示例#1
0
        public void ValidateUser()
        {
            MockUser           mockUser = MockUser.CreateInitializedUser();
            MockAuthentication provider = new MockAuthentication();

            // Failure
            AuthenticationBaseTest.SetUserInProviders(null);
            MockUser user = provider.Login(string.Empty, string.Empty, false, null);

            Assert.IsTrue(provider.WasValidateUserInvoked,
                          "ValidateUser should have been invoked from Login.");

            Assert.IsFalse(provider.ValidateUserMock(string.Empty, string.Empty),
                           "ValidateUser should return false.");
            Assert.IsNull(user,
                          "Users should be null when ValidateUser returns false.");

            provider.WasValidateUserInvoked = false;

            // Success
            AuthenticationBaseTest.SetUserInProviders(mockUser);
            user = provider.Login(mockUser.Name, mockUser.Name, false, null);

            Assert.IsTrue(provider.WasValidateUserInvoked,
                          "ValidateUser should have been invoked from Login.");

            Assert.IsTrue(provider.ValidateUserMock(mockUser.Name, mockUser.Name),
                          "ValidateUser should return true.");
            Assert.IsNotNull(user,
                             "Users should not be null when ValidateUser returns true.");
        }