Пример #1
0
        public void ValidLoginReturnsSessionToken()
        {
            LoginRequest credentials = new LoginRequest("johndoe");

            Mock.Get(authenticationMock).Setup(_authenticationMock => _authenticationMock.Authenticate(credentials)).Returns(true).Verifiable();
            Mock.Get(authenticationMock).Setup(_authenticationMock => _authenticationMock.GetUserName(credentials)).Returns("johndoe").Verifiable();
            Mock.Get(authenticationMock).Setup(_authenticationMock => _authenticationMock.GetDisplayName(credentials)).Returns("johndoe").Verifiable();
            Mock.Get(sessionMock).Setup(_sessionMock => _sessionMock.AddToCache("johndoe")).Returns(testSessionToken).Verifiable();
            Mock.Get(sessionMock).Setup(_sessionMock => _sessionMock.StoreSessionValue(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Verifiable();

            manager.Initialise();

            string sessionToken = manager.Login(credentials);

            Assert.AreEqual(testSessionToken, sessionToken);
        }
        public void ValidLoginReturnsSessionToken()
        {
            LoginRequest credentials = new LoginRequest("johndoe");

            Expect.Call(authenticationMock.Authenticate(credentials)).Return(true);
            Expect.Call(authenticationMock.GetUserName(credentials)).Return("johndoe");
            Expect.Call(authenticationMock.GetDisplayName(credentials)).Return("johndoe");
            Expect.Call(sessionMock.AddToCache("johndoe")).Return(testSessionToken);
            Expect.Call(delegate { sessionMock.StoreSessionValue(string.Empty, string.Empty, string.Empty); })
            .IgnoreArguments();

            mocks.ReplayAll();
            manager.Initialise();

            string sessionToken = manager.Login(credentials);

            Assert.AreEqual(testSessionToken, sessionToken);
        }