public void PersonWithPrimaryEmailShouldHandleAccountProtectionProfileCorrectly(string personGuid, string emailSearch, int accountProtectionProfile) { if (!Bus.RockMessageBus.IsRockStarted) { Bus.RockMessageBus.IsRockStarted = true; Bus.RockMessageBus.StartAsync().Wait(); } var securitySettingService = new SecuritySettingsService(); securitySettingService.SecuritySettings.AccountProtectionProfilesForDuplicateDetectionToIgnore = new List <AccountProtectionProfile>(); securitySettingService.Save(); // Give time for cache to update. Thread.Sleep(50); using (var rockContext = new RockContext()) { var personService = new PersonService(rockContext); var person = personService.Get(personGuid.AsGuid()); var personMatchQuery = new PersonService.PersonMatchQuery(person.FirstName, person.LastName, emailSearch, null) { MobilePhone = null, Gender = person.Gender, BirthDate = person.BirthDate, SuffixValueId = person.SuffixValueId }; var foundPerson = personService.FindPerson(personMatchQuery, false); Assert.That.IsNotNull(foundPerson); } securitySettingService.SecuritySettings.AccountProtectionProfilesForDuplicateDetectionToIgnore = new List <AccountProtectionProfile> { ( AccountProtectionProfile )accountProtectionProfile }; securitySettingService.Save(); // Give time for cache to update. Thread.Sleep(50); using (var rockContext = new RockContext()) { var personService = new PersonService(rockContext); var person = personService.Get(personGuid.AsGuid()); var personMatchQuery = new PersonService.PersonMatchQuery(person.FirstName, person.LastName, emailSearch, null) { MobilePhone = null, Gender = person.Gender, BirthDate = person.BirthDate, SuffixValueId = person.SuffixValueId }; var foundPerson = personService.FindPerson(personMatchQuery, false); Assert.That.IsNull(foundPerson); } }