ConnectionInfoTest_Authenticate_Success.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Microsoft.Extensions.Logging.Abstractions;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Moq;
  4. using Renci.SshNet.Tests.Properties;
  5. namespace Renci.SshNet.Tests.Classes
  6. {
  7. [TestClass]
  8. public class ConnectionInfoTest_Authenticate_Success
  9. {
  10. private Mock<IServiceFactory> _serviceFactoryMock;
  11. private Mock<IClientAuthentication> _clientAuthenticationMock;
  12. private Mock<ISession> _sessionMock;
  13. private ConnectionInfo _connectionInfo;
  14. [TestInitialize]
  15. public void Init()
  16. {
  17. Arrange();
  18. Act();
  19. }
  20. protected void Arrange()
  21. {
  22. _serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
  23. _clientAuthenticationMock = new Mock<IClientAuthentication>(MockBehavior.Strict);
  24. _sessionMock = new Mock<ISession>(MockBehavior.Strict);
  25. _sessionMock.Setup(p => p.SessionLoggerFactory).Returns(NullLoggerFactory.Instance);
  26. _connectionInfo = new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None,
  27. Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD,
  28. new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
  29. _serviceFactoryMock.Setup(p => p.CreateClientAuthentication()).Returns(_clientAuthenticationMock.Object);
  30. _clientAuthenticationMock.Setup(p => p.Authenticate(_connectionInfo, _sessionMock.Object));
  31. }
  32. protected void Act()
  33. {
  34. _connectionInfo.Authenticate(_sessionMock.Object, _serviceFactoryMock.Object);
  35. }
  36. [TestMethod]
  37. public void IsAuthenticatedShouldReturnTrue()
  38. {
  39. Assert.IsTrue(_connectionInfo.IsAuthenticated);
  40. }
  41. [TestMethod]
  42. public void CreateClientAuthenticationOnServiceFactoryShouldBeInvokedOnce()
  43. {
  44. _serviceFactoryMock.Verify(p => p.CreateClientAuthentication(), Times.Once);
  45. }
  46. [TestMethod]
  47. public void AuthenticateOnClientAuthenticationShouldBeInvokedOnce()
  48. {
  49. _clientAuthenticationMock.Verify(p => p.Authenticate(_connectionInfo, _sessionMock.Object), Times.Once);
  50. }
  51. }
  52. }