public void GivenValidCode_DefaultViewModelIsReturned() { //Arrange var candidateId = Guid.NewGuid(); var candidateMock = new CandidateBuilder(candidateId) .EnableApplicationStatusChangeAlertsViaText(true) .PhoneNumber(PhoneNumber) .VerifiedMobile(false) .Build(); var candidateServiceMock = new Mock <ICandidateService>(); candidateServiceMock.Setup(cs => cs.GetCandidate(candidateId)).Returns(candidateMock); candidateServiceMock.Setup(cs => cs.SendMobileVerificationCode(candidateMock)); var viewModel = new VerifyMobileViewModelBuilder().PhoneNumber(PhoneNumber).Build(); var provider = new AccountProviderBuilder().With(candidateServiceMock).Build(); //Act var result = provider.SendMobileVerificationCode(candidateId, viewModel); //Assert result.Status.Should().Be(VerifyMobileState.Ok); result.HasError().Should().BeFalse(); result.ViewModelMessage.Should().BeNullOrEmpty(); }
public void ShouldMapDisabilityStatus(int?disabilityStatus, DisabilityStatus?expectedDisabilityStatus) { // Arrange. var candidateId = Guid.NewGuid(); var candidateService = new Mock <ICandidateService>(); candidateService .Setup(cs => cs.GetCandidate(candidateId)) .Returns(new CandidateBuilder(candidateId).Build); var viewModel = new SettingsViewModelBuilder() .PhoneNumber("0123456789") .DisabilityStatus(disabilityStatus) .Build(); var provider = new AccountProviderBuilder().With(candidateService).Build(); Candidate candidate; // Act. var result = provider.TrySaveSettings(candidateId, viewModel, out candidate); // Assert. result.Should().BeTrue(); candidate.MonitoringInformation.Should().NotBeNull(); candidate.MonitoringInformation.DisabilityStatus.Should().Be(expectedDisabilityStatus); }
public void ShouldMapSupport(bool isJavascript, bool requiresSupport, string support, string expectedSuport) { // Arrange. var candidateId = Guid.NewGuid(); var candidateService = new Mock <ICandidateService>(); candidateService .Setup(cs => cs.GetCandidate(candidateId)) .Returns(new CandidateBuilder(candidateId).Build); var viewModel = new SettingsViewModelBuilder() .IsJavascript(isJavascript) .Support(requiresSupport, support) .Build(); var provider = new AccountProviderBuilder().With(candidateService).Build(); Candidate candidate; // Act. var result = provider.TrySaveSettings(candidateId, viewModel, out candidate); // Assert. result.Should().BeTrue(); candidate.MonitoringInformation.Should().NotBeNull(); candidate.ApplicationTemplate.AboutYou.Support.Should().Be(expectedSuport); }
public void GivenEntityStateError_ThenValidViewModelIsReturned(string errorCode, VerifyMobileState verifyMobileState) { //Arrange var candidateId = Guid.NewGuid(); var candidateMock = new CandidateBuilder(candidateId) .EnableApplicationStatusChangeAlertsViaText(true) .PhoneNumber(PhoneNumber) .VerifiedMobile(false) .Build(); var candidateServiceMock = new Mock <ICandidateService>(); candidateServiceMock.Setup(cs => cs.GetCandidate(candidateId)).Returns(candidateMock); candidateServiceMock.Setup(cs => cs.SendMobileVerificationCode(candidateMock)).Throws(new CustomException(errorCode)); var viewModel = new VerifyMobileViewModelBuilder().PhoneNumber(PhoneNumber).Build(); var provider = new AccountProviderBuilder().With(candidateServiceMock).Build(); //Act var result = provider.SendMobileVerificationCode(candidateId, viewModel); //Assert result.Status.Should().Be(verifyMobileState); result.HasError().Should().BeTrue(); result.ViewModelMessage.Should().NotBeNull(); }
public void UpdateEmailAddressOk() { var provider = new AccountProviderBuilder().Build(); var returnedModel = provider.UpdateEmailAddress(Guid.NewGuid(), viewModel); returnedModel.Should().NotBeNull(); returnedModel.UpdateStatus.Should().Be(UpdateEmailStatus.Ok); }
public void ShouldRequireMobileVerification(string newPhoneNumber, bool verifiedMobile, bool enableCommunicationViaText, bool mobileVerificationRequired) { // Arrange. const string mobileVerificationCode = "1234"; var candidateId = Guid.NewGuid(); var candidateService = new Mock <ICandidateService>(); const string currentPhoneNumber = "0123456789"; candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(new CandidateBuilder(candidateId).PhoneNumber(currentPhoneNumber).VerifiedMobile(verifiedMobile).Build); candidateService.Setup(cs => cs.SaveCandidate(It.IsAny <Candidate>())).Returns <Candidate>(c => { if (c.MobileVerificationRequired()) { c.CommunicationPreferences.MobileVerificationCode = mobileVerificationCode; } return(c); }); var viewModel = new SettingsViewModelBuilder().PhoneNumber(newPhoneNumber).EnableMarketingViaText(enableCommunicationViaText).Build(); var provider = new AccountProviderBuilder().With(candidateService).Build(); Candidate candidate; // Act. var result = provider.TrySaveSettings(candidateId, viewModel, out candidate); // Assert. result.Should().BeTrue(); candidate.RegistrationDetails.Should().NotBeNull(); candidate.RegistrationDetails.PhoneNumber.Should().Be(newPhoneNumber); candidate.CommunicationPreferences.Should().NotBeNull(); candidate.CommunicationPreferences.MarketingPreferences.Should().NotBeNull(); candidate.CommunicationPreferences.MarketingPreferences.EnableText.Should().Be(enableCommunicationViaText); if (newPhoneNumber != currentPhoneNumber) { candidate.CommunicationPreferences.VerifiedMobile.Should().BeFalse(); } else { candidate.CommunicationPreferences.VerifiedMobile.Should().Be(verifiedMobile); } if (mobileVerificationRequired) { candidate.MobileVerificationRequired().Should().BeTrue(); candidate.CommunicationPreferences.MobileVerificationCode.Should().Be(mobileVerificationCode); } else { candidate.MobileVerificationRequired().Should().BeFalse(); candidate.CommunicationPreferences.MobileVerificationCode.Should().BeNullOrEmpty(); } }
public void UpdateEmailAddressAccountAlreadyExixtsCustomError() { var userAccountService = new Mock <IUserAccountService>(); userAccountService.Setup(x => x.UpdateUsername(It.IsAny <Guid>(), It.IsAny <string>())).Throws(new CustomException(ErrorCodes.UserDirectoryAccountExistsError)); var provider = new AccountProviderBuilder().With(userAccountService).Build(); var returnedModel = provider.UpdateEmailAddress(Guid.NewGuid(), viewModel); returnedModel.Should().NotBeNull(); returnedModel.UpdateStatus.Should().Be(UpdateEmailStatus.AccountAlreadyExists); }
public void UpdateEmailAddressUnknownError() { var userAccountService = new Mock <IUserAccountService>(); userAccountService.Setup(x => x.UpdateUsername(It.IsAny <Guid>(), It.IsAny <string>())).Throws(new Exception()); var provider = new AccountProviderBuilder().With(userAccountService).Build(); var returnedModel = provider.UpdateEmailAddress(Guid.NewGuid(), viewModel); returnedModel.Should().NotBeNull(); returnedModel.UpdateStatus.Should().Be(UpdateEmailStatus.Error); }
public void VerifyUpdatedEmailAddressTestsException() { var candidateService = new Mock <ICandidateService>(); candidateService.Setup(x => x.UpdateUsername(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>())).Throws(new Exception()); var provider = new AccountProviderBuilder().With(candidateService).Build(); var returnedModel = provider.VerifyUpdatedEmailAddress(Guid.NewGuid(), new VerifyUpdatedEmailViewModel()); returnedModel.Should().NotBeNull(); returnedModel.UpdateStatus.Should().Be(UpdateEmailStatus.Error); returnedModel.ViewModelMessage.Should().Be(UpdateEmailStatus.Error.ToString()); }
public void MobileVerificationRequired(string newPhoneNumber, bool verifiedMobile, bool allowSmsComms, bool mobileVerificationRequired) { const string mobileVerificationCode = "1234"; var candidateId = Guid.NewGuid(); var candidateService = new Mock <ICandidateService>(); const string phoneNumber = "0123456789"; candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(new CandidateBuilder(candidateId).PhoneNumber(phoneNumber).VerifiedMobile(verifiedMobile).Build); candidateService.Setup(cs => cs.SaveCandidate(It.IsAny <Candidate>())).Returns <Candidate>(c => { if (c.MobileVerificationRequired()) { c.CommunicationPreferences.MobileVerificationCode = mobileVerificationCode; } return(c); }); var viewModel = new SettingsViewModelBuilder().PhoneNumber(newPhoneNumber).AllowSmsComms(allowSmsComms).Build(); var provider = new AccountProviderBuilder().With(candidateService).Build(); Candidate candidate; var result = provider.TrySaveSettings(candidateId, viewModel, out candidate); result.Should().BeTrue(); candidate.RegistrationDetails.Should().NotBeNull(); candidate.RegistrationDetails.PhoneNumber.Should().Be(newPhoneNumber); candidate.CommunicationPreferences.Should().NotBeNull(); candidate.CommunicationPreferences.AllowMobile.Should().Be(allowSmsComms); if (newPhoneNumber != phoneNumber) { candidate.CommunicationPreferences.VerifiedMobile.Should().BeFalse(); } else { candidate.CommunicationPreferences.VerifiedMobile.Should().Be(verifiedMobile); } if (mobileVerificationRequired) { candidate.MobileVerificationRequired().Should().BeTrue(); candidate.CommunicationPreferences.MobileVerificationCode.Should().Be(mobileVerificationCode); } else { candidate.MobileVerificationRequired().Should().BeFalse(); candidate.CommunicationPreferences.MobileVerificationCode.Should().BeNullOrEmpty(); } }
public void TestMarketingMappings(bool allowEmailMarketing, bool allowSmsMarketing) { var candidateId = Guid.NewGuid(); var candidate = new CandidateBuilder(candidateId) .AllowEmailMarketing(allowEmailMarketing) .AllowMobileMarketing(allowSmsMarketing) .Build(); var candidateService = new Mock <ICandidateService>(); candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(candidate); var provider = new AccountProviderBuilder().With(candidateService).Build(); var viewModel = provider.GetSettingsViewModel(candidateId); viewModel.Should().NotBeNull(); viewModel.AllowEmailMarketing.Should().Be(allowEmailMarketing); viewModel.AllowSmsMarketing.Should().Be(allowSmsMarketing); }
public void GivenValidCode_DefaultViewModelIsReturned() { //Arrange var candidateId = Guid.NewGuid(); var candidateServiceMock = new Mock <ICandidateService>(); candidateServiceMock.Setup(cs => cs.VerifyMobileCode(candidateId, VerificationCode));; var viewModel = new VerifyMobileViewModelBuilder().PhoneNumber(PhoneNumber).MobileVerificationCode(VerificationCode).Build(); var provider = new AccountProviderBuilder().With(candidateServiceMock).Build(); //Act var result = provider.VerifyMobile(candidateId, viewModel); //Assert result.Status.Should().Be(VerifyMobileState.Ok); result.HasError().Should().BeFalse(); result.ViewModelMessage.Should().BeNullOrEmpty(); }
public void MarketingMappingTest(bool allowEmailMarketing, bool allowSmsMarketing) { var candidateId = Guid.NewGuid(); var candidateService = new Mock <ICandidateService>(); candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(new CandidateBuilder(candidateId).Build); var viewModel = new SettingsViewModelBuilder().AllowEmailMarketing(allowEmailMarketing).AllowSmsMarketing(allowSmsMarketing).Build(); var provider = new AccountProviderBuilder().With(candidateService).Build(); Candidate candidate; var result = provider.TrySaveSettings(candidateId, viewModel, out candidate); result.Should().BeTrue(); candidate.RegistrationDetails.Should().NotBeNull(); candidate.CommunicationPreferences.Should().NotBeNull(); candidate.CommunicationPreferences.AllowEmailMarketing.Should().Be(allowEmailMarketing); candidate.CommunicationPreferences.AllowMobileMarketing.Should().Be(allowSmsMarketing); }
public void CommunicationMappingTest(string phoneNumber, bool verifiedMobile, bool allowEmailComms, bool allowSmsComms) { var candidateId = Guid.NewGuid(); var candidateService = new Mock <ICandidateService>(); candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(new CandidateBuilder(candidateId).PhoneNumber(phoneNumber).VerifiedMobile(verifiedMobile).Build); var viewModel = new SettingsViewModelBuilder().PhoneNumber(phoneNumber).AllowEmailComms(allowEmailComms).AllowSmsComms(allowSmsComms).Build(); var provider = new AccountProviderBuilder().With(candidateService).Build(); Candidate candidate; var result = provider.TrySaveSettings(candidateId, viewModel, out candidate); result.Should().BeTrue(); candidate.RegistrationDetails.Should().NotBeNull(); candidate.RegistrationDetails.PhoneNumber.Should().Be(phoneNumber); candidate.CommunicationPreferences.Should().NotBeNull(); candidate.CommunicationPreferences.AllowEmail.Should().Be(allowEmailComms); candidate.CommunicationPreferences.AllowMobile.Should().Be(allowSmsComms); candidate.CommunicationPreferences.VerifiedMobile.Should().Be(verifiedMobile); }
public void TestSavedSearchMappings(bool alertsEnabled) { var candidateId = Guid.NewGuid(); var candidate = new CandidateBuilder(candidateId).Build(); var candidateService = new Mock <ICandidateService>(); candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(candidate); var savedSearches = new Fixture().Build <SavedSearch>() .With(s => s.AlertsEnabled, alertsEnabled) .With(s => s.Keywords, string.Empty) .With(s => s.ApprenticeshipLevel, "All") .With(s => s.Location, "CV1 2WT") .With(s => s.Latitude, 1.1) .With(s => s.Longitude, 2.1) .With(s => s.WithinDistance, 5) .With(s => s.SubCategoriesFullName, "Surveying, Construction Civil Engineering") .With(s => s.DateProcessed, new DateTime(2015, 01, 01)) .CreateMany(1).ToList(); candidateService.Setup(cs => cs.GetSavedSearches(candidateId)).Returns(savedSearches); var provider = new AccountProviderBuilder().With(candidateService).Build(); var viewModel = provider.GetSettingsViewModel(candidateId); candidateService.Verify(cs => cs.GetSavedSearches(candidateId), Times.Once); viewModel.Should().NotBeNull(); viewModel.SavedSearches.Count.Should().Be(1); var savedSearch = viewModel.SavedSearches[0]; savedSearch.Id.Should().Be(savedSearches[0].EntityId); savedSearch.Name.Should().Be("Within 5 miles of CV1 2WT"); savedSearch.SearchUrl.Should().NotBeNull(); savedSearch.SearchUrl.Value.Should().NotBeNullOrEmpty(); savedSearch.AlertsEnabled.Should().Be(alertsEnabled); savedSearch.ApprenticeshipLevel.Should().Be("All"); savedSearch.SubCategoriesFullNames.Should().Be("Surveying, Construction Civil Engineering"); savedSearch.DateProcessed.HasValue.Should().BeTrue(); savedSearch.DateProcessed.Should().Be(new DateTime(2015, 01, 01)); }
public void TestMarketingMappings( bool enableApplicationStatusChangeAlerts, bool enableExpiringApplicationAlerts, bool sendMarketingCommunications, bool sendSavedSearchAlerts, CommunicationChannels channel) { var candidateId = Guid.NewGuid(); var candidate = new CandidateBuilder(candidateId) .EnableApplicationStatusChangeAlertsViaEmail(enableApplicationStatusChangeAlerts && channel == CommunicationChannels.Email) .EnableApplicationStatusChangeAlertsViaText(enableApplicationStatusChangeAlerts && channel == CommunicationChannels.Sms) .EnableExpiringApplicationAlertsViaEmail(enableExpiringApplicationAlerts && channel == CommunicationChannels.Email) .EnableExpiringApplicationAlertsViaText(enableExpiringApplicationAlerts && channel == CommunicationChannels.Sms) .EnableMarketingViaEmail(sendMarketingCommunications && channel == CommunicationChannels.Email) .EnableMarketingViaText(sendMarketingCommunications && channel == CommunicationChannels.Sms) .EnableSavedSearchAlertsViaEmail(sendSavedSearchAlerts && channel == CommunicationChannels.Email) .EnableSavedSearchAlertsViaText(sendSavedSearchAlerts && channel == CommunicationChannels.Sms) .Build(); var candidateService = new Mock <ICandidateService>(); candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(candidate); var provider = new AccountProviderBuilder().With(candidateService).Build(); var viewModel = provider.GetSettingsViewModel(candidateId); viewModel.Should().NotBeNull(); viewModel.EnableApplicationStatusChangeAlertsViaEmail.Should().Be(enableApplicationStatusChangeAlerts && channel == CommunicationChannels.Email); viewModel.EnableApplicationStatusChangeAlertsViaText.Should().Be(enableApplicationStatusChangeAlerts && channel == CommunicationChannels.Sms); viewModel.EnableExpiringApplicationAlertsViaEmail.Should().Be(enableExpiringApplicationAlerts && channel == CommunicationChannels.Email); viewModel.EnableExpiringApplicationAlertsViaText.Should().Be(enableExpiringApplicationAlerts && channel == CommunicationChannels.Sms); viewModel.EnableMarketingViaEmail.Should().Be(sendMarketingCommunications && channel == CommunicationChannels.Email); viewModel.EnableMarketingViaText.Should().Be(sendMarketingCommunications && channel == CommunicationChannels.Sms); viewModel.EnableSavedSearchAlertsViaEmail.Should().Be(sendSavedSearchAlerts && channel == CommunicationChannels.Email); viewModel.EnableSavedSearchAlertsViaText.Should().Be(sendSavedSearchAlerts && channel == CommunicationChannels.Sms); }
public void TestUserMappings() { var candidateId = Guid.NewGuid(); var candidate = new CandidateBuilder(candidateId).Build(); var candidateService = new Mock <ICandidateService>(); candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(candidate); var userAccountService = new Mock <IUserAccountService>(); userAccountService.Setup(ac => ac.GetUser(It.IsAny <Guid>())) .Returns(new User { Username = "******", PendingUsername = "******" }); var provider = new AccountProviderBuilder().With(candidateService).With(userAccountService).Build(); var viewModel = provider.GetSettingsViewModel(candidateId); viewModel.Username.Should().Be("username"); viewModel.PendingUsername.Should().Be("pendingun"); }
public void TestCommunicationMappings(bool verifiedMobile, bool enableEmail, bool enableText) { var candidateId = Guid.NewGuid(); const string phoneNumber = "0123456789"; var candidate = new CandidateBuilder(candidateId) .PhoneNumber(phoneNumber) .VerifiedMobile(verifiedMobile) .Build(); var candidateService = new Mock <ICandidateService>(); candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(candidate); var provider = new AccountProviderBuilder().With(candidateService).Build(); var viewModel = provider.GetSettingsViewModel(candidateId); viewModel.Should().NotBeNull(); viewModel.PhoneNumber.Should().Be(phoneNumber); viewModel.VerifiedMobile.Should().Be(verifiedMobile); }
public void TestMonitoringInformationMappings( Gender?gender, DisabilityStatus disabilityStatus, int?ethnicity, string support) { // Arrange. var candidateId = Guid.NewGuid(); var candidate = new CandidateBuilder(candidateId) .With(gender) .With(disabilityStatus) .With(ethnicity) .With(new ApplicationTemplate { AboutYou = new AboutYou { Support = support } }) .Build(); var candidateService = new Mock <ICandidateService>(); candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(candidate); var provider = new AccountProviderBuilder().With(candidateService).Build(); // Act. var viewModel = provider.GetSettingsViewModel(candidateId); // Assert. viewModel.Should().NotBeNull(); viewModel.MonitoringInformation.Gender.Should().Be((int?)gender); viewModel.MonitoringInformation.DisabilityStatus.Should().Be((int?)disabilityStatus); viewModel.MonitoringInformation.Ethnicity.Should().Be(ethnicity); viewModel.MonitoringInformation.RequiresSupportForInterview.Should().Be(!string.IsNullOrWhiteSpace(support)); viewModel.MonitoringInformation.AnythingWeCanDoToSupportYourInterview.Should().Be(support); }
public void ShouldMapCommunicationPreferences(string phoneNumber, CommunicationChannels communicationChannel, bool verifiedMobile) { // Arrange. var candidateId = Guid.NewGuid(); var candidateService = new Mock <ICandidateService>(); candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(new CandidateBuilder(candidateId).PhoneNumber(phoneNumber).VerifiedMobile(verifiedMobile).Build); var viewModel = new SettingsViewModelBuilder() .PhoneNumber(phoneNumber) .EnableApplicationStatusChangeAlertsViaEmail(communicationChannel == CommunicationChannels.Email) .EnableApplicationStatusChangeAlertsViaText(communicationChannel == CommunicationChannels.Sms) .EnableExpiringApplicationAlertsViaEmail(communicationChannel == CommunicationChannels.Email) .EnableExpiringApplicationAlertsViaText(communicationChannel == CommunicationChannels.Sms) .EnableMarketingViaEmail(communicationChannel == CommunicationChannels.Email) .EnableMarketingViaText(communicationChannel == CommunicationChannels.Sms) .EnableSavedSearchAlertsViaEmail(communicationChannel == CommunicationChannels.Email) .EnableSavedSearchAlertsViaText(communicationChannel == CommunicationChannels.Sms) .Build(); var provider = new AccountProviderBuilder().With(candidateService).Build(); Candidate candidate; // Act. var result = provider.TrySaveSettings(candidateId, viewModel, out candidate); // Assert. result.Should().BeTrue(); candidate.RegistrationDetails.Should().NotBeNull(); candidate.RegistrationDetails.PhoneNumber.Should().Be(phoneNumber); candidate.CommunicationPreferences.Should().NotBeNull(); { var preferences = candidate.CommunicationPreferences.ApplicationStatusChangePreferences; preferences.Should().NotBeNull(); preferences.EnableEmail.Should().Be(communicationChannel == CommunicationChannels.Email); preferences.EnableText.Should().Be(communicationChannel == CommunicationChannels.Sms); } { var preferences = candidate.CommunicationPreferences.ExpiringApplicationPreferences; preferences.Should().NotBeNull(); preferences.EnableEmail.Should().Be(communicationChannel == CommunicationChannels.Email); preferences.EnableText.Should().Be(communicationChannel == CommunicationChannels.Sms); } { var preferences = candidate.CommunicationPreferences.MarketingPreferences; preferences.Should().NotBeNull(); preferences.EnableEmail.Should().Be(communicationChannel == CommunicationChannels.Email); preferences.EnableText.Should().Be(communicationChannel == CommunicationChannels.Sms); } { var preferences = candidate.CommunicationPreferences.SavedSearchPreferences; preferences.Should().NotBeNull(); preferences.EnableEmail.Should().Be(communicationChannel == CommunicationChannels.Email); preferences.EnableText.Should().Be(communicationChannel == CommunicationChannels.Sms); } candidate.CommunicationPreferences.VerifiedMobile.Should().Be(verifiedMobile); }