using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using Renci.SshNet.Tests.Common; namespace Renci.SshNet.Tests.Classes { [TestClass] public abstract class ClientAuthenticationTestBase : TestBase { internal Mock ConnectionInfoMock { get; private set; } internal Mock SessionMock { get; private set; } internal Mock NoneAuthenticationMethodMock { get; private set; } internal Mock PasswordAuthenticationMethodMock { get; private set; } internal Mock PublicKeyAuthenticationMethodMock { get; private set; } internal Mock KeyboardInteractiveAuthenticationMethodMock { get; private set; } internal ClientAuthentication ClientAuthentication { get; private set; } protected void CreateMocks() { ConnectionInfoMock = new Mock(MockBehavior.Strict); SessionMock = new Mock(MockBehavior.Strict); NoneAuthenticationMethodMock = new Mock(MockBehavior.Strict); PasswordAuthenticationMethodMock = new Mock(MockBehavior.Strict); PublicKeyAuthenticationMethodMock = new Mock(MockBehavior.Strict); KeyboardInteractiveAuthenticationMethodMock = new Mock(MockBehavior.Strict); } protected abstract void SetupMocks(); protected abstract void Act(); protected override void OnInit() { base.OnInit(); // Arrange CreateMocks(); SetupMocks(); ClientAuthentication = new ClientAuthentication(); // Act Act(); } [TestMethod] public void RegisterMessageWithUserAuthFailureShouldBeInvokedOnce() { SessionMock.Verify(p => p.RegisterMessage("SSH_MSG_USERAUTH_FAILURE"), Times.Once); } [TestMethod] public void RegisterMessageWithUserAuthSuccessShouldBeInvokedOnce() { SessionMock.Verify(p => p.RegisterMessage("SSH_MSG_USERAUTH_SUCCESS"), Times.Once); } [TestMethod] public void RegisterMessageWithUserAuthBannerShouldBeInvokedOnce() { SessionMock.Verify(p => p.RegisterMessage("SSH_MSG_USERAUTH_BANNER"), Times.Once); } [TestMethod] public void UnRegisterMessageWithUserAuthFailureShouldBeInvokedOnce() { SessionMock.Verify(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_FAILURE"), Times.Once); } [TestMethod] public void UnRegisterMessageWithUserAuthSuccessShouldBeInvokedOnce() { SessionMock.Verify(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_SUCCESS"), Times.Once); } [TestMethod] public void UnRegisterMessageWithUserAuthBannerShouldBeInvokedOnce() { SessionMock.Verify(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_BANNER"), Times.Once); } } }