| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 | using System.Collections.Generic;using Microsoft.VisualStudio.TestTools.UnitTesting;using Moq;using Renci.SshNet.Common;namespace Renci.SshNet.Tests.Classes{    [TestClass]    public class ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodNotSupported : ClientAuthenticationTestBase    {        private SshAuthenticationException _actualException;        protected override void SetupMocks()        {            var seq = new MockSequence();            SessionMock.InSequence(seq).Setup(p => p.RegisterMessage("SSH_MSG_USERAUTH_FAILURE"));            SessionMock.InSequence(seq).Setup(p => p.RegisterMessage("SSH_MSG_USERAUTH_SUCCESS"));            SessionMock.InSequence(seq).Setup(p => p.RegisterMessage("SSH_MSG_USERAUTH_BANNER"));            ConnectionInfoMock.InSequence(seq).Setup(p => p.CreateNoneAuthenticationMethod())                .Returns(NoneAuthenticationMethodMock.Object);            NoneAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object))                .Returns(AuthenticationResult.Failure);            ConnectionInfoMock.InSequence(seq).Setup(p => p.AuthenticationMethods)                            .Returns(new List<IAuthenticationMethod>                {                    PublicKeyAuthenticationMethodMock.Object                });            NoneAuthenticationMethodMock.InSequence(seq)                .Setup(p => p.AllowedAuthentications)                .Returns(new[] { "password" });            PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey");            SessionMock.InSequence(seq).Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_FAILURE"));            SessionMock.InSequence(seq).Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_SUCCESS"));            SessionMock.InSequence(seq).Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_BANNER"));        }        protected override void Act()        {            try            {                ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object);                Assert.Fail();            }            catch (SshAuthenticationException ex)            {                _actualException = ex;            }        }        [TestMethod]        public void AuthenticateShouldThrowSshAuthenticationException()        {            Assert.IsNotNull(_actualException);            Assert.IsNull(_actualException.InnerException);            Assert.AreEqual("No suitable authentication method found to complete authentication (password).", _actualException.Message);        }    }}
 |