public void TestDeleteInactiveProfiles() { var membershipConfig = new NameValueCollection(_membershipConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var profileConfig = new NameValueCollection(_profileConfig); var profileProvider = new MongoProfileProvider(); profileProvider.Initialize(DefaultProfileName, profileConfig); SetUpTestProfiles(membershipProvider, profileProvider); int numberOfUsersBefore, numberOfUsersAfter; membershipProvider.GetAllUsers(0, int.MaxValue, out numberOfUsersBefore); var numberOfInactiveProfilesDeleted = profileProvider.DeleteInactiveProfiles(ProfileAuthenticationOption.All, DateTime.Now.AddDays(-1)); var numberOfInactiveProfiles = profileProvider.GetNumberOfInactiveProfiles(ProfileAuthenticationOption.All, DateTime.Now.AddDays(-1)); membershipProvider.GetAllUsers(0, int.MaxValue, out numberOfUsersAfter); Assert.AreEqual(40, numberOfInactiveProfilesDeleted); Assert.AreEqual(0, numberOfInactiveProfiles); // No users should be removed by this process. Assert.AreEqual(numberOfUsersBefore, numberOfUsersAfter); }
public void TestAddUsersToRoles() { var membershipConfig = new NameValueCollection(_membershipConfig); var roleConfig = new NameValueCollection(_roleConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var roleProvider = new MongoRoleProvider(); roleProvider.Initialize(DefaultRoleName, roleConfig); MembershipCreateStatus status; membershipProvider.CreateUser("user1", "123456", "*****@*****.**", null, null, true, null, out status); membershipProvider.CreateUser("user2", "123456", "*****@*****.**", null, null, true, null, out status); roleProvider.CreateRole("role1"); roleProvider.CreateRole("role2"); roleProvider.AddUsersToRoles(new[] { "user1", "user2" }, new[] { "role1", "role2" }); Assert.IsTrue(roleProvider.IsUserInRole("user1", "role1")); Assert.IsTrue(roleProvider.IsUserInRole("user1", "role2")); Assert.IsTrue(roleProvider.IsUserInRole("user2", "role1")); Assert.IsTrue(roleProvider.IsUserInRole("user2", "role2")); }
public void TestGetAllProfilesThatAreAuthenticated() { var membershipConfig = new NameValueCollection(_membershipConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var profileConfig = new NameValueCollection(_profileConfig); var profileProvider = new MongoProfileProvider(); profileProvider.Initialize(DefaultProfileName, profileConfig); SetUpTestProfiles(membershipProvider, profileProvider); int totalRecords = 0; var profiles = profileProvider.GetAllProfiles(ProfileAuthenticationOption.Authenticated, 0, 30, out totalRecords); Assert.AreEqual(40, totalRecords); Assert.AreEqual(30, profiles.Count); foreach (ProfileInfo p in profiles) { Assert.AreEqual("user", p.UserName.Substring(0, 4)); // All even records are authenticated in this test. Assert.IsTrue(Convert.ToInt32(p.UserName.Substring(4)) % 2 == 0); Assert.IsFalse(p.IsAnonymous); Assert.Greater(p.Size, 0); } }
public void TestInitializeWhenCalledTwice() { var config = new NameValueCollection(_config); var provider = new MongoMembershipProvider(); Assert.Throws<InvalidOperationException>(() => { provider.Initialize(DefaultName, config); provider.Initialize(DefaultName, config); }); }
public void TestGetAllProfiles() { var membershipConfig = new NameValueCollection(_membershipConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var profileConfig = new NameValueCollection(_profileConfig); var profileProvider = new MongoProfileProvider(); profileProvider.Initialize(DefaultProfileName, profileConfig); SetUpTestProfiles(membershipProvider, profileProvider); int totalRecords = 0; var profiles = profileProvider.GetAllProfiles(ProfileAuthenticationOption.All, 0, 30, out totalRecords); Assert.AreEqual(80, totalRecords); Assert.AreEqual(30, profiles.Count); foreach (ProfileInfo p in profiles) { Assert.AreEqual("user", p.UserName.Substring(0, 4)); Assert.Greater(p.Size, 0); } }
public void TestIsUserInRoleWhenRoleDoesNotExist() { var membershipConfig = new NameValueCollection(_membershipConfig); var roleConfig = new NameValueCollection(_roleConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var roleProvider = new MongoRoleProvider(); roleProvider.Initialize(DefaultRoleName, roleConfig); MembershipCreateStatus status; membershipProvider.CreateUser("user1", "123456", "*****@*****.**", null, null, true, null, out status); Assert.Throws<ArgumentException>(() => roleProvider.IsUserInRole("user1", "role1")); }
public void TestRemoveUsersFromRolesWithNonExistantRoles() { var membershipConfig = new NameValueCollection(_membershipConfig); var roleConfig = new NameValueCollection(_roleConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var roleProvider = new MongoRoleProvider(); roleProvider.Initialize(DefaultRoleName, roleConfig); MembershipCreateStatus status; membershipProvider.CreateUser("user1", "123456", "*****@*****.**", null, null, true, null, out status); membershipProvider.CreateUser("user2", "123456", "*****@*****.**", null, null, true, null, out status); Assert.Throws<ProviderException>( () => roleProvider.RemoveUsersFromRoles(new[] { "user1", "user2" }, new[] { "role1", "role2" })); }
public void TestUnlockUser() { var config = new NameValueCollection(_config); config["enablePasswordRetrieval"] = "true"; config["requiresQuestionAndAnswer"] = "true"; config["maxInvalidPasswordAttempts"] = "1"; config["passwordFormat"] = "clear"; var provider = new MongoMembershipProvider(); provider.Initialize(DefaultName, config); MembershipCreateStatus status; provider.CreateUser("test", "123456", "*****@*****.**", "Question", "Answer", true, null, out status); try { provider.GetPassword("test", "Wrong!"); } catch (MembershipPasswordException) { } // User will now be locked. var lockedOutUser = provider.GetUser("test", false); Assert.IsTrue(lockedOutUser.IsLockedOut); var unlocked = provider.UnlockUser("test"); Assert.IsTrue(unlocked); // User will now be unlocked. var user = provider.GetUser("test", false); Assert.IsFalse(user.IsLockedOut); }
public void TestGetRolesForUserWhenHasUserDoesNotExist() { var membershipConfig = new NameValueCollection(_membershipConfig); var roleConfig = new NameValueCollection(_roleConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var roleProvider = new MongoRoleProvider(); roleProvider.Initialize(DefaultRoleName, roleConfig); MembershipCreateStatus status; membershipProvider.CreateUser("user1", "123456", "*****@*****.**", null, null, true, null, out status); membershipProvider.CreateUser("user2", "123456", "*****@*****.**", null, null, true, null, out status); roleProvider.CreateRole("role1"); roleProvider.CreateRole("role2"); roleProvider.CreateRole("role3"); roleProvider.AddUsersToRoles(new[] { "user1", }, new[] { "role1", "role2" }); var roles = roleProvider.GetRolesForUser("user3"); Assert.AreEqual(0, roles.Length); }
public void TestUpdateUserWithoutRequiresUniqueEmailWithDuplicateEmail() { var provider = new MongoMembershipProvider(); provider.Initialize(DefaultName, _config); MembershipCreateStatus status1; provider.CreateUser("test1", "123456", "*****@*****.**", null, null, true, null, out status1); MembershipCreateStatus status2; var user = provider.CreateUser("test2", "123456", "*****@*****.**", null, null, true, null, out status2); // Change the email to match the first user's email. user.Email = "*****@*****.**"; // No exception as duplicate emails are allowed. provider.UpdateUser(user); }
public void TestGetPropertyValuesUsingXmlProperties() { var membershipConfig = new NameValueCollection(_membershipConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); MembershipCreateStatus status; membershipProvider.CreateUser("user", "123456", "*****@*****.**", null, null, true, null, out status); var profileConfig = new NameValueCollection(_profileConfig); var profileProvider = new MongoProfileProvider(); profileProvider.Initialize(DefaultProfileName, profileConfig); var values = new SettingsPropertyValueCollection(); AddXmlPropertyValuesTo(values, allowAnonymous: false); profileProvider.SetPropertyValues(TestHelper.GenerateSettingsContext("user", true), values); var properties = new SettingsPropertyCollection(); AddXmlPropertiesTo(properties, allowAnonymous: false); var retrievedValues = profileProvider .GetPropertyValues(TestHelper.GenerateSettingsContext("user", true), properties); var rawRetrievedValues = retrievedValues .Cast<SettingsPropertyValue>() .Select(value => value.PropertyValue) .ToList(); Assert.AreEqual(1, retrievedValues.Count); Assert.Contains("Value of stringValue", rawRetrievedValues); }
public void TestUpdateUserWithNonExistantProviderUserKey() { var provider = new MongoMembershipProvider(); provider.Initialize(DefaultName, _config); var user = new MembershipUser( providerName: provider.Name, name: "test", // This will cause the exception as it's not an ObjectId // or a parseable string version of an ObjectId. providerUserKey: ObjectId.GenerateNewId(), email: "*****@*****.**", passwordQuestion: null, comment: null, isApproved: true, isLockedOut: false, creationDate: DateTime.Now, lastLoginDate: new DateTime(), lastActivityDate: new DateTime(), lastPasswordChangedDate: new DateTime(), lastLockoutDate: new DateTime()); Assert.Throws<ProviderException>(() => provider.UpdateUser(user)); }
public void TestUpdateUserWithNullUser() { var provider = new MongoMembershipProvider(); provider.Initialize(DefaultName, _config); Assert.Throws<ArgumentNullException>(() => provider.UpdateUser(null)); }
public void TestUpdateUserWithDuplicateUserName() { var provider = new MongoMembershipProvider(); provider.Initialize(DefaultName, _config); MembershipCreateStatus status1; provider.CreateUser("test1", "123456", "*****@*****.**", null, null, true, null, out status1); MembershipCreateStatus status2; var createdUser = provider.CreateUser("test2", "123456", "*****@*****.**", null, null, true, null, out status2); // Since we can't change the UserName property directly, we create a MembershipUser with the same values Assert.IsNotNull(createdUser); Assert.IsNotNull(createdUser.ProviderUserKey); var duplicateUser = new MembershipUser( providerName: createdUser.ProviderName, // Change the name to match the first user. name: "test1", providerUserKey: createdUser.ProviderUserKey, email: createdUser.Email, passwordQuestion: createdUser.PasswordQuestion, comment: createdUser.Comment, isApproved: createdUser.IsApproved, isLockedOut: createdUser.IsLockedOut, creationDate: createdUser.CreationDate, lastLoginDate: createdUser.LastLoginDate, lastActivityDate: createdUser.LastActivityDate, lastPasswordChangedDate: createdUser.LastPasswordChangedDate, lastLockoutDate: createdUser.LastLockoutDate); // Exception as duplicate usernames are NOT allowed. Assert.Throws<ProviderException>(() => provider.UpdateUser(duplicateUser)); }
public void TestUpdateUser() { var provider = new MongoMembershipProvider(); provider.Initialize(DefaultName, _config); MembershipCreateStatus status; var createdUser = provider.CreateUser("test", "123456", "*****@*****.**", null, null, true, null, out status); createdUser.Email = "*****@*****.**"; createdUser.Comment = "comment"; createdUser.IsApproved = false; createdUser.LastLoginDate = new DateTime(1982, 04, 28); createdUser.LastActivityDate = new DateTime(1982, 04, 30); provider.UpdateUser(createdUser); var updatedUser = provider.GetUser(createdUser.ProviderUserKey, false); Assert.NotNull(updatedUser); Assert.AreEqual("*****@*****.**", updatedUser.Email); Assert.AreEqual("comment", updatedUser.Comment); Assert.AreEqual(false, updatedUser.IsApproved); Assert.AreEqual(new DateTime(1982, 04, 28), updatedUser.LastLoginDate); Assert.AreEqual(new DateTime(1982, 04, 30), updatedUser.LastActivityDate); }
public void TestUnlockUserWithNonExistentUser() { var config = new NameValueCollection(_config); config["enablePasswordRetrieval"] = "true"; config["requiresQuestionAndAnswer"] = "true"; config["maxInvalidPasswordAttempts"] = "1"; config["passwordFormat"] = "clear"; var provider = new MongoMembershipProvider(); provider.Initialize(DefaultName, config); MembershipCreateStatus status; provider.CreateUser("test", "123456", "*****@*****.**", "Question", "Answer", true, null, out status); var unlocked = provider.UnlockUser("Wrong!"); Assert.IsFalse(unlocked); }
public void TestGetNumberOfInactiveProfilesThatAreAuthenticated() { var membershipConfig = new NameValueCollection(_membershipConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var profileConfig = new NameValueCollection(_profileConfig); var profileProvider = new MongoProfileProvider(); profileProvider.Initialize(DefaultProfileName, profileConfig); SetUpTestProfiles(membershipProvider, profileProvider); var numberOfInactiveProfiles = profileProvider.GetNumberOfInactiveProfiles(ProfileAuthenticationOption.Authenticated, DateTime.Now.AddDays(-1)); Assert.AreEqual(20, numberOfInactiveProfiles); }
public void TestDeleteRoleWhenPopulatedWithThrowOnPopulated() { var membershipConfig = new NameValueCollection(_membershipConfig); var roleConfig = new NameValueCollection(_roleConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var roleProvider = new MongoRoleProvider(); roleProvider.Initialize(DefaultRoleName, roleConfig); MembershipCreateStatus status; membershipProvider.CreateUser("user1", "123456", "*****@*****.**", null, null, true, null, out status); membershipProvider.CreateUser("user2", "123456", "*****@*****.**", null, null, true, null, out status); roleProvider.CreateRole("role1"); roleProvider.CreateRole("role2"); roleProvider.AddUsersToRoles(new[] { "user1", "user2" }, new[] { "role1", "role2" }); Assert.Throws<ProviderException>(() => roleProvider.DeleteRole("role1", true)); }
public void TestUpdateUserWithRequiresUniqueEmailWithDuplicateEmail() { var config = new NameValueCollection(_config); config["requiresUniqueEmail"] = "true"; var provider = new MongoMembershipProvider(); provider.Initialize(DefaultName, config); MembershipCreateStatus status1; provider.CreateUser("test1", "123456", "*****@*****.**", null, null, true, null, out status1); MembershipCreateStatus status2; var user = provider.CreateUser("test2", "123456", "*****@*****.**", null, null, true, null, out status2); // Change the email to match the first user's email. user.Email = "*****@*****.**"; // Exception as duplicate emails are NOT allowed. Assert.Throws<ProviderException>(() => provider.UpdateUser(user)); }
public void TestInitializeWithEnablePasswordRetrievalWithIrretrievablePassword() { var config = new NameValueCollection(_config); config["enablePasswordRetrieval"] = "true"; config["passwordFormat"] = "hashed"; var provider = new MongoMembershipProvider(); Assert.Throws<ProviderException>(() => provider.Initialize(DefaultName, config)); }
public void TestSetPropertyValues() { var membershipConfig = new NameValueCollection(_membershipConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); MembershipCreateStatus status; membershipProvider.CreateUser("user", "123456", "*****@*****.**", null, null, true, null, out status); var profileConfig = new NameValueCollection(_profileConfig); var profileProvider = new MongoProfileProvider(); profileProvider.Initialize(DefaultProfileName, profileConfig); var collection = new SettingsPropertyValueCollection(); AddProviderSpecificPropertyValuesTo(collection, allowAnonymous: false); profileProvider.SetPropertyValues(TestHelper.GenerateSettingsContext("user", true), collection); }
public void TestDeleteProfilesUsingProfileInfoCollection() { var membershipConfig = new NameValueCollection(_membershipConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var profileConfig = new NameValueCollection(_profileConfig); var profileProvider = new MongoProfileProvider(); profileProvider.Initialize(DefaultProfileName, profileConfig); SetUpTestProfiles(membershipProvider, profileProvider); int numberOfUsersBefore, numberOfUsersAfter; membershipProvider.GetAllUsers(0, int.MaxValue, out numberOfUsersBefore); int totalRecords; var profiles = profileProvider.FindProfilesByUserName(ProfileAuthenticationOption.All, @"user3\d", 0, int.MaxValue, out totalRecords); var numberOfProfilesDeleted = profileProvider.DeleteProfiles(profiles); int numberOfProfilesRemaining; profileProvider.GetAllProfiles(ProfileAuthenticationOption.All, 0, int.MaxValue, out numberOfProfilesRemaining); membershipProvider.GetAllUsers(0, int.MaxValue, out numberOfUsersAfter); Assert.AreEqual(10, numberOfProfilesDeleted); Assert.AreEqual(70, numberOfProfilesRemaining); // No users should be removed by this process. Assert.AreEqual(numberOfUsersBefore, numberOfUsersAfter); }
public void TestFindUsersInRoleWithNonRegex() { var membershipConfig = new NameValueCollection(_membershipConfig); var roleConfig = new NameValueCollection(_roleConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var roleProvider = new MongoRoleProvider(); roleProvider.Initialize(DefaultRoleName, roleConfig); MembershipCreateStatus status; membershipProvider.CreateUser("aaaa", "123456", "*****@*****.**", null, null, true, null, out status); membershipProvider.CreateUser("aabb", "123456", "*****@*****.**", null, null, true, null, out status); membershipProvider.CreateUser("bbaa", "123456", "*****@*****.**", null, null, true, null, out status); membershipProvider.CreateUser("aacc", "123456", "*****@*****.**", null, null, true, null, out status); roleProvider.CreateRole("role1"); roleProvider.CreateRole("role2"); roleProvider.AddUsersToRoles(new[] { "aaaa", "aabb", "bbaa" }, new[] { "role1" }); roleProvider.AddUsersToRoles(new[] { "aacc" }, new[] { "role2" }); var userNames = roleProvider.FindUsersInRole("role1", "aa"); Assert.AreEqual(3, userNames.Length); Assert.Contains("aaaa", userNames); Assert.Contains("aabb", userNames); Assert.Contains("bbaa", userNames); }
public void TestDeleteProfilesUsingStringArray() { var membershipConfig = new NameValueCollection(_membershipConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var profileConfig = new NameValueCollection(_profileConfig); var profileProvider = new MongoProfileProvider(); profileProvider.Initialize(DefaultProfileName, profileConfig); SetUpTestProfiles(membershipProvider, profileProvider); int numberOfUsersBefore, numberOfUsersAfter; membershipProvider.GetAllUsers(0, int.MaxValue, out numberOfUsersBefore); // Note that user0 does not have a profile. var numberOfProfilesDeleted = profileProvider.DeleteProfiles(new [] { "user0", "user44", "user56" }); int numberOfProfilesRemaining; profileProvider.GetAllProfiles(ProfileAuthenticationOption.All, 0, int.MaxValue, out numberOfProfilesRemaining); membershipProvider.GetAllUsers(0, int.MaxValue, out numberOfUsersAfter); Assert.AreEqual(2, numberOfProfilesDeleted); Assert.AreEqual(78, numberOfProfilesRemaining); // No users should be removed by this process. Assert.AreEqual(numberOfUsersBefore, numberOfUsersAfter); }
public void TestGetUsersInRoleWhenNoUsersInRole() { var membershipConfig = new NameValueCollection(_membershipConfig); var roleConfig = new NameValueCollection(_roleConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var roleProvider = new MongoRoleProvider(); roleProvider.Initialize(DefaultRoleName, roleConfig); MembershipCreateStatus status; membershipProvider.CreateUser("user1", "123456", "*****@*****.**", null, null, true, null, out status); membershipProvider.CreateUser("user2", "123456", "*****@*****.**", null, null, true, null, out status); membershipProvider.CreateUser("user3", "123456", "*****@*****.**", null, null, true, null, out status); roleProvider.CreateRole("role1"); var userNames = roleProvider.GetUsersInRole("role1"); Assert.AreEqual(0, userNames.Length); }
public void TestFindInactiveProfilesByUserName() { var membershipConfig = new NameValueCollection(_membershipConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var profileConfig = new NameValueCollection(_profileConfig); var profileProvider = new MongoProfileProvider(); profileProvider.Initialize(DefaultProfileName, profileConfig); SetUpTestProfiles(membershipProvider, profileProvider); int totalRecords = 0; var profiles = profileProvider.FindInactiveProfilesByUserName( ProfileAuthenticationOption.All, @"user\d*(0|1)", DateTime.Now.AddDays(-1), 0, 2, out totalRecords); Assert.AreEqual(8, totalRecords); Assert.AreEqual(2, profiles.Count); foreach (ProfileInfo p in profiles) { Assert.IsTrue(p.UserName.StartsWith("user") && (p.UserName.EndsWith("0") || p.UserName.EndsWith("1"))); Assert.Greater(p.Size, 0); } }
public void TestFindProfilesByUserName() { var membershipConfig = new NameValueCollection(_membershipConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var profileConfig = new NameValueCollection(_profileConfig); var profileProvider = new MongoProfileProvider(); profileProvider.Initialize(DefaultProfileName, profileConfig); SetUpTestProfiles(membershipProvider, profileProvider); int totalRecords = 0; var profiles = profileProvider.FindProfilesByUserName(ProfileAuthenticationOption.All, @"user2\d*", 0, 2, out totalRecords); Assert.AreEqual(10, totalRecords); Assert.AreEqual(2, profiles.Count); foreach (ProfileInfo p in profiles) { Assert.IsTrue(p.UserName.StartsWith("user2")); Assert.Greater(p.Size, 0); } }
public void TestFindProfilesByUserNameThatAreAnonymous() { var membershipConfig = new NameValueCollection(_membershipConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var profileConfig = new NameValueCollection(_profileConfig); var profileProvider = new MongoProfileProvider(); profileProvider.Initialize(DefaultProfileName, profileConfig); SetUpTestProfiles(membershipProvider, profileProvider); int totalRecords = 0; var profiles = profileProvider.FindProfilesByUserName(ProfileAuthenticationOption.Anonymous, @"user2\d*", 0, 2, out totalRecords); Assert.AreEqual(5, totalRecords); Assert.AreEqual(2, profiles.Count); foreach (ProfileInfo p in profiles) { Assert.IsTrue(p.UserName.StartsWith("user2")); // All even records are authenticated in this test. Assert.IsFalse(Convert.ToInt32(p.UserName.Substring(4)) % 2 == 0); Assert.IsTrue(p.IsAnonymous); Assert.Greater(p.Size, 0); } }
public void TestRemoveUsersFromRolesWithNonExistantUserNames() { var membershipConfig = new NameValueCollection(_membershipConfig); var roleConfig = new NameValueCollection(_roleConfig); var membershipProvider = new MongoMembershipProvider(); membershipProvider.Initialize(DefaultMembershipName, membershipConfig); var roleProvider = new MongoRoleProvider(); roleProvider.Initialize(DefaultRoleName, roleConfig); roleProvider.CreateRole("role1"); roleProvider.CreateRole("role2"); Assert.Throws<ProviderException>( () => roleProvider.RemoveUsersFromRoles(new[] { "user1", "user2" }, new[] { "role1", "role2" })); }
public void TestGetUserNameByEmailWhenNonUnique() { var provider = new MongoMembershipProvider(); provider.Initialize(DefaultName, _config); MembershipCreateStatus status; provider.CreateUser("bbb", "123456", "*****@*****.**", null, null, true, null, out status); provider.CreateUser("aaa", "123456", "*****@*****.**", null, null, true, null, out status); var retrievedUserName = provider.GetUserNameByEmail("*****@*****.**"); Assert.AreEqual("aaa", retrievedUserName); }