ClientAuthenticationTestBase.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Moq;
  3. using Renci.SshNet.Tests.Common;
  4. namespace Renci.SshNet.Tests.Classes
  5. {
  6. [TestClass]
  7. public abstract class ClientAuthenticationTestBase : TestBase
  8. {
  9. internal Mock<IConnectionInfoInternal> ConnectionInfoMock { get; private set; }
  10. internal Mock<ISession> SessionMock { get; private set; }
  11. internal Mock<IAuthenticationMethod> NoneAuthenticationMethodMock { get; private set; }
  12. internal Mock<IAuthenticationMethod> PasswordAuthenticationMethodMock { get; private set; }
  13. internal Mock<IAuthenticationMethod> PublicKeyAuthenticationMethodMock { get; private set; }
  14. internal Mock<IAuthenticationMethod> KeyboardInteractiveAuthenticationMethodMock { get; private set; }
  15. protected abstract void SetupData();
  16. protected void CreateMocks()
  17. {
  18. ConnectionInfoMock = new Mock<IConnectionInfoInternal>(MockBehavior.Strict);
  19. SessionMock = new Mock<ISession>(MockBehavior.Strict);
  20. NoneAuthenticationMethodMock = new Mock<IAuthenticationMethod>(MockBehavior.Strict);
  21. PasswordAuthenticationMethodMock = new Mock<IAuthenticationMethod>(MockBehavior.Strict);
  22. PublicKeyAuthenticationMethodMock = new Mock<IAuthenticationMethod>(MockBehavior.Strict);
  23. KeyboardInteractiveAuthenticationMethodMock = new Mock<IAuthenticationMethod>(MockBehavior.Strict);
  24. }
  25. protected abstract void SetupMocks();
  26. protected virtual void Arrange()
  27. {
  28. SetupData();
  29. CreateMocks();
  30. SetupMocks();
  31. }
  32. protected abstract void Act();
  33. protected sealed override void OnInit()
  34. {
  35. base.OnInit();
  36. Arrange();
  37. Act();
  38. }
  39. [TestMethod]
  40. public void RegisterMessageWithUserAuthFailureShouldBeInvokedOnce()
  41. {
  42. SessionMock.Verify(p => p.RegisterMessage("SSH_MSG_USERAUTH_FAILURE"), Times.Once);
  43. }
  44. [TestMethod]
  45. public void RegisterMessageWithUserAuthSuccessShouldBeInvokedOnce()
  46. {
  47. SessionMock.Verify(p => p.RegisterMessage("SSH_MSG_USERAUTH_SUCCESS"), Times.Once);
  48. }
  49. [TestMethod]
  50. public void RegisterMessageWithUserAuthBannerShouldBeInvokedOnce()
  51. {
  52. SessionMock.Verify(p => p.RegisterMessage("SSH_MSG_USERAUTH_BANNER"), Times.Once);
  53. }
  54. [TestMethod]
  55. public void UnRegisterMessageWithUserAuthFailureShouldBeInvokedOnce()
  56. {
  57. SessionMock.Verify(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_FAILURE"), Times.Once);
  58. }
  59. [TestMethod]
  60. public void UnRegisterMessageWithUserAuthSuccessShouldBeInvokedOnce()
  61. {
  62. SessionMock.Verify(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_SUCCESS"), Times.Once);
  63. }
  64. [TestMethod]
  65. public void UnRegisterMessageWithUserAuthBannerShouldBeInvokedOnce()
  66. {
  67. SessionMock.Verify(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_BANNER"), Times.Once);
  68. }
  69. }
  70. }