| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 | using Microsoft.Extensions.Logging.Abstractions;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<IConnectionInfoInternal> ConnectionInfoMock { get; private set; }        internal Mock<ISession> SessionMock { get; private set; }        internal Mock<IAuthenticationMethod> NoneAuthenticationMethodMock { get; private set; }        internal Mock<IAuthenticationMethod> PasswordAuthenticationMethodMock { get; private set; }        internal Mock<IAuthenticationMethod> PublicKeyAuthenticationMethodMock { get; private set; }        internal Mock<IAuthenticationMethod> KeyboardInteractiveAuthenticationMethodMock { get; private set; }        protected abstract void SetupData();        protected void CreateMocks()        {            ConnectionInfoMock = new Mock<IConnectionInfoInternal>(MockBehavior.Strict);            SessionMock = new Mock<ISession>(MockBehavior.Strict);            SessionMock.Setup(p => p.SessionLoggerFactory).Returns(NullLoggerFactory.Instance);            NoneAuthenticationMethodMock = new Mock<IAuthenticationMethod>(MockBehavior.Strict);            PasswordAuthenticationMethodMock = new Mock<IAuthenticationMethod>(MockBehavior.Strict);            PublicKeyAuthenticationMethodMock = new Mock<IAuthenticationMethod>(MockBehavior.Strict);            KeyboardInteractiveAuthenticationMethodMock = new Mock<IAuthenticationMethod>(MockBehavior.Strict);        }        protected abstract void SetupMocks();        protected virtual void Arrange()        {            SetupData();            CreateMocks();            SetupMocks();        }        protected abstract void Act();        protected sealed override void OnInit()        {            base.OnInit();            Arrange();            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);        }    }}
 |