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