ClientAuthenticationTest.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Moq;
  4. namespace Renci.SshNet.Tests.Classes
  5. {
  6. [TestClass]
  7. public class ClientAuthenticationTest
  8. {
  9. private ClientAuthentication _clientAuthentication;
  10. [TestInitialize]
  11. public void Init()
  12. {
  13. _clientAuthentication = new ClientAuthentication(1);
  14. }
  15. [TestMethod]
  16. public void Ctor_PartialSuccessLimit_Zero()
  17. {
  18. const int partialSuccessLimit = 0;
  19. try
  20. {
  21. new ClientAuthentication(partialSuccessLimit);
  22. Assert.Fail();
  23. }
  24. catch (ArgumentOutOfRangeException ex)
  25. {
  26. Assert.IsNull(ex.InnerException);
  27. Assert.AreEqual(string.Format("Cannot be less than one.{0}Parameter name: {1}", Environment.NewLine, ex.ParamName), ex.Message);
  28. Assert.AreEqual("partialSuccessLimit", ex.ParamName);
  29. }
  30. }
  31. [TestMethod]
  32. public void Ctor_PartialSuccessLimit_Negative()
  33. {
  34. var partialSuccessLimit = new Random().Next(int.MinValue, -1);
  35. try
  36. {
  37. new ClientAuthentication(partialSuccessLimit);
  38. Assert.Fail();
  39. }
  40. catch (ArgumentOutOfRangeException ex)
  41. {
  42. Assert.IsNull(ex.InnerException);
  43. Assert.AreEqual(string.Format("Cannot be less than one.{0}Parameter name: {1}", Environment.NewLine, ex.ParamName), ex.Message);
  44. Assert.AreEqual("partialSuccessLimit", ex.ParamName);
  45. }
  46. }
  47. [TestMethod]
  48. public void Ctor_PartialSuccessLimit_One()
  49. {
  50. const int partialSuccessLimit = 1;
  51. var clientAuthentication = new ClientAuthentication(partialSuccessLimit);
  52. Assert.AreEqual(partialSuccessLimit, clientAuthentication.PartialSuccessLimit);
  53. }
  54. [TestMethod]
  55. public void Ctor_PartialSuccessLimit_MaxValue()
  56. {
  57. const int partialSuccessLimit = int.MaxValue;
  58. var clientAuthentication = new ClientAuthentication(partialSuccessLimit);
  59. Assert.AreEqual(partialSuccessLimit, clientAuthentication.PartialSuccessLimit);
  60. }
  61. [TestMethod]
  62. public void AuthenticateShouldThrowArgumentNullExceptionWhenConnectionInfoIsNull()
  63. {
  64. const IConnectionInfoInternal connectionInfo = null;
  65. var session = new Mock<ISession>(MockBehavior.Strict).Object;
  66. try
  67. {
  68. _clientAuthentication.Authenticate(connectionInfo, session);
  69. Assert.Fail();
  70. }
  71. catch (ArgumentNullException ex)
  72. {
  73. Assert.IsNull(ex.InnerException);
  74. Assert.AreEqual("connectionInfo", ex.ParamName);
  75. }
  76. }
  77. [TestMethod]
  78. public void AuthenticateShouldThrowArgumentNullExceptionWhenSessionIsNull()
  79. {
  80. var connectionInfo = new Mock<IConnectionInfoInternal>(MockBehavior.Strict).Object;
  81. const ISession session = null;
  82. try
  83. {
  84. _clientAuthentication.Authenticate(connectionInfo, session);
  85. Assert.Fail();
  86. }
  87. catch (ArgumentNullException ex)
  88. {
  89. Assert.IsNull(ex.InnerException);
  90. Assert.AreEqual("session", ex.ParamName);
  91. }
  92. }
  93. }
  94. }