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."); }
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); }
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."); }
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."); }
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; }
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); }