Example #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.");
        }
Example #2
0
        public void UpdateUserThrows()
        {
            MockUser           original = MockUser.CreateDefaultUser();
            MockUser           user     = MockUser.CreateInitializedUser();
            MockAuthentication provider =
                ServerTestHelper.CreateInitializedDomainService <MockAuthentication>(DomainOperationType.Submit);

            ExceptionHelper.ExpectException <UnauthorizedAccessException>(
                () => provider.UpdateUser(user));
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
0
        public void ConvertSqlExceptions()
        {
            MockUser           mockUser = MockUser.CreateInitializedUser();
            MockAuthentication provider = new MockAuthentication();

            SqlException sqlEx = null;

            try
            {
                using (SqlConnection badConnection = new SqlConnection("Data Source=Nosource"))
                {
                    badConnection.Open();
                }
            }
            catch (SqlException sqlEx2)
            {
                sqlEx = sqlEx2;
            }

            // Membership
            string message = string.Format(
                CultureInfo.InvariantCulture,
                Resources.ApplicationServices_ProviderError,
                "Membership", sqlEx.Message);

            ((MockMembershipProvider)Membership.Provider).Error = sqlEx;
            ExceptionHelper.ExpectException <DomainException>(() =>
                                                              provider.Login(mockUser.Name, mockUser.Name, false, null), message);
            ((MockMembershipProvider)Membership.Provider).Error = null;

            // Roles
            message = string.Format(
                CultureInfo.InvariantCulture,
                Resources.ApplicationServices_ProviderError,
                "Role", sqlEx.Message);
            ((MockRoleProvider)Roles.Provider).Error = sqlEx;
            ExceptionHelper.ExpectException <DomainException>(() =>
                                                              provider.GetAuthenticatedUserMock(mockUser), message);
            ((MockRoleProvider)Roles.Provider).Error = null;

            // Profile
            message = string.Format(
                CultureInfo.InvariantCulture,
                Resources.ApplicationServices_ProviderError,
                "Profile", sqlEx.Message);
            ((MockProfileProvider)ProfileManager.Provider).Error = sqlEx;
            ExceptionHelper.ExpectException <DomainException>(() =>
                                                              provider.GetAuthenticatedUserMock(mockUser), message);
            ((MockProfileProvider)ProfileManager.Provider).Error = null;
        }
Example #6
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);
        }
Example #7
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.");
        }
Example #8
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);
        }