Exemplo n.º 1
0
        public void CreateUser()
        {
            MockUser           mockUser = MockUser.CreateDefaultUser();
            MockAuthentication provider = new MockAuthentication();

            AuthenticationBaseTest.SetUserInProviders(mockUser);

            // GetUser(IIdentity)
            MockUser userGUM = provider.GetAuthenticatedUserMock(mockUser);

            Assert.IsTrue(provider.WasCreateUserInvoked,
                          "CreateUser should have been invoked from GetUser(IIdentity).");

            provider.WasCreateUserInvoked = false;

            // GetAnonymousUser
            MockUser userGAU = provider.GetAnonymousUserMock();

            Assert.IsTrue(provider.WasCreateUserInvoked,
                          "GetAnonymousUser should have been invoked from GetUser.");

            provider.WasGetAnonymousUserInvoked = false;

            Assert.IsNotNull(provider.CreateUserMock(),
                             "User should not be null.");
        }
Exemplo n.º 2
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.");
        }
Exemplo n.º 3
0
        public void GetAnonymousUser()
        {
            MockUser           mockUser = MockUser.CreateDefaultUser();
            MockAuthentication provider = new MockAuthentication();

            AuthenticationBaseTest.SetUserInProviders(mockUser);

            // Logout
            MockUser userL = provider.Logout();

            Assert.IsTrue(provider.WasGetAnonymousUserInvoked,
                          "GetAnonymousUser should have been invoked from Logout.");

            provider.WasGetAnonymousUserInvoked = false;

            // GetUser
            MockUser userGU = provider.GetUser();

            Assert.IsTrue(provider.WasGetAnonymousUserInvoked,
                          "GetAnonymousUser should have been invoked from GetUser.");

            provider.WasGetAnonymousUserInvoked = false;

            // Logout should return the same value as GetAnonymousUser
            AuthenticationBaseTest.CompareUsers(mockUser, provider.GetAnonymousUserMock(), true);
            AuthenticationBaseTest.CompareUsers(mockUser, userL, true);
            AuthenticationBaseTest.CompareUsers(mockUser, userGU, true);
        }
Exemplo n.º 4
0
        public void Logout()
        {
            MockUser           mockUser = MockUser.CreateDefaultUser();
            MockAuthentication provider = new MockAuthentication();

            AuthenticationBaseTest.SetUserInProviders(mockUser);
            MockUser user = provider.Logout();

            AuthenticationBaseTest.CompareUsers(mockUser, user, true);
        }
Exemplo n.º 5
0
        public void LoginAndGetUser()
        {
            MockUser           mockUser = MockUser.CreateInitializedUser();
            MockAuthentication provider = new MockAuthentication();

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

            AuthenticationBaseTest.CompareUsers(mockUser, user, true);
        }
Exemplo n.º 6
0
        public void LoginFailure()
        {
            MockAuthentication provider = new MockAuthentication();

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

            Assert.IsNull(user,
                          "The user should be null to indicate the Login was unsuccessful.");
        }
Exemplo n.º 7
0
        public void UpdateUser()
        {
            MockUser           original = MockUser.CreateDefaultUser();
            MockUser           user     = MockUser.CreateInitializedUser();
            MockAuthentication provider = new MockAuthentication();

            AuthenticationBaseTest.SetUserInProviders(original);
            provider.UpdateUser(user);

            AuthenticationBaseTest.CompareUsers(user, original, false);
        }
Exemplo n.º 8
0
        public void ClearAuthenticationToken()
        {
            MockUser           mockUser = MockUser.CreateDefaultUser();
            MockAuthentication provider = new MockAuthentication();

            // Failure
            AuthenticationBaseTest.SetUserInProviders(null);
            MockUser user = provider.Logout();

            Assert.IsTrue(provider.WasClearAuthenticationTokenInvoked,
                          "ClearAuthenticationToken should have been invoked from Logout.");
        }
Exemplo n.º 9
0
        public void GetAuthenticatedUser()
        {
            MockUser           mockUser = MockUser.CreateInitializedUser();
            MockAuthentication provider = new MockAuthentication();

            AuthenticationBaseTest.SetUserInProviders(mockUser);

            // Login
            MockUser user = provider.Login(mockUser.Name, mockUser.Name, false, null);

            Assert.IsTrue(provider.WasGetAuthenticatedUserInvoked,
                          "GetAuthenticatedUser should have been invoked from Login.");

            provider.WasGetAuthenticatedUserInvoked = false;

            // GetUser will always invoke GetAnonymousUser when testing

            // Login (and GetUser. See explanation on LoginAndGetUser) should return the same value as GetUser(IIdentity)
            AuthenticationBaseTest.CompareUsers(mockUser, provider.GetAuthenticatedUserMock(mockUser), true);
            AuthenticationBaseTest.CompareUsers(mockUser, user, true);
        }
Exemplo n.º 10
0
        public void IssueAuthenticationToken()
        {
            MockUser           mockUser = MockUser.CreateInitializedUser();
            MockAuthentication provider = new MockAuthentication();

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

            Assert.IsFalse(provider.WasIssueAuthenticationTokenInvoked,
                           "IssueAuthenticationToken should not have been invoked from a failed Login.");

            provider.WasIssueAuthenticationTokenInvoked = false;

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

            Assert.IsTrue(provider.WasIssueAuthenticationTokenInvoked,
                          "ValidateUser should have been invoked from Login.");
        }
Exemplo n.º 11
0
        public void UpdateUserCore()
        {
            MockUser           original = MockUser.CreateDefaultUser();
            MockUser           user     = MockUser.CreateInitializedUser();
            MockAuthentication provider = new MockAuthentication();

            AuthenticationBaseTest.SetUserInProviders(original);
            provider.UpdateUserCoreMock(user);

            AuthenticationBaseTest.CompareUsers(user, original, false);

            // These tests are only valid when we can call SetUser directly
            //MockUser originalUU = MockUser.CreateDefaultUser();

            //AspNetUserDomainServiceTest.SetUserInProviders(originalUU);
            //provider.UpdateUser(user, originalUU);

            //Assert.IsTrue(provider.WasUpdateUserCoreInvoked,
            //    "UpdateUserCore should have been invoked from UpdateUser.");

            //AspNetUserDomainServiceTest.CompareUsers(original, originalUU, false);
        }