ConnectionInfoTest_Authenticate_Success.cs 2.1 KB

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