private RequestResult <UserPreferenceModel> ExecuteUpdateUserPreference(Database.Constants.DBStatusCode dbResultStatus = Database.Constants.DBStatusCode.Updated) { UserPreferenceModel userPreferenceModel = new UserPreferenceModel { HdId = hdid, Preference = "TutorialPopover", Value = "mocked value", }; DBResult <UserPreference> readResult = new DBResult <UserPreference> { Payload = userPreferenceModel.ToDbModel(), Status = dbResultStatus }; Mock <IUserPreferenceDelegate> preferenceDelegateMock = new Mock <IUserPreferenceDelegate>(); preferenceDelegateMock.Setup(s => s.UpdateUserPreference(It.IsAny <UserPreference>(), It.IsAny <bool>())).Returns(readResult); Mock <IEmailQueueService> emailer = new Mock <IEmailQueueService>(); Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>(); Mock <IEmailDelegate> emailDelegateMock = new Mock <IEmailDelegate>(); Mock <IMessagingVerificationDelegate> emailInviteDelegateMock = new Mock <IMessagingVerificationDelegate>(); Mock <IConfigurationService> configServiceMock = new Mock <IConfigurationService>(); Mock <ILegalAgreementDelegate> legalAgreementDelegateMock = new Mock <ILegalAgreementDelegate>(); Mock <ICryptoDelegate> cryptoDelegateMock = new Mock <ICryptoDelegate>(); Mock <INotificationSettingsService> notificationServiceMock = new Mock <INotificationSettingsService>(); Mock <IMessagingVerificationDelegate> messageVerificationDelegateMock = new Mock <IMessagingVerificationDelegate>(); IUserProfileService service = new UserProfileService( new Mock <ILogger <UserProfileService> >().Object, new Mock <IPatientService>().Object, new Mock <IUserEmailService>().Object, new Mock <IUserSMSService>().Object, configServiceMock.Object, new Mock <IEmailQueueService>().Object, notificationServiceMock.Object, profileDelegateMock.Object, preferenceDelegateMock.Object, new Mock <ILegalAgreementDelegate>().Object, messageVerificationDelegateMock.Object, cryptoDelegateMock.Object, new Mock <IHttpContextAccessor>().Object); return(service.UpdateUserPreference(userPreferenceModel)); }
/// <inheritdoc /> public RequestResult <UserPreferenceModel> CreateUserPreference(UserPreferenceModel userPreferenceModel) { this.logger.LogTrace($"Creating user preference... {userPreferenceModel.Preference}"); UserPreference userPreference = userPreferenceModel.ToDbModel(); DBResult <UserPreference> dbResult = this.userPreferenceDelegate.CreateUserPreference(userPreference); this.logger.LogDebug($"Finished creating user preference. {JsonSerializer.Serialize(dbResult)}"); RequestResult <UserPreferenceModel> requestResult = new RequestResult <UserPreferenceModel>() { ResourcePayload = UserPreferenceModel.CreateFromDbModel(dbResult.Payload), ResultStatus = dbResult.Status == DBStatusCode.Created ? ResultType.Success : ResultType.Error, ResultError = dbResult.Status == DBStatusCode.Created ? null : new RequestResultError() { ResultMessage = dbResult.Message, ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationInternal, ServiceType.Database), }, }; return(requestResult); }
private Tuple <RequestResult <Dictionary <string, UserPreferenceModel> >, List <UserPreferenceModel> > ExecuteGetUserPreference(Database.Constants.DBStatusCode dbResultStatus = Database.Constants.DBStatusCode.Read) { UserProfile userProfile = new UserProfile { HdId = hdid, AcceptedTermsOfService = true, }; DBResult <UserProfile> userProfileDBResult = new DBResult <UserProfile> { Payload = userProfile, Status = dbResultStatus }; UserProfileModel expected = UserProfileModel.CreateFromDbModel(userProfile); LegalAgreement termsOfService = new LegalAgreement() { Id = Guid.NewGuid(), LegalText = "", EffectiveDate = DateTime.Now }; Mock <IEmailQueueService> emailer = new Mock <IEmailQueueService>(); Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>(); profileDelegateMock.Setup(s => s.GetUserProfile(hdid)).Returns(userProfileDBResult); profileDelegateMock.Setup(s => s.Update(userProfile, true)).Returns(userProfileDBResult); UserPreferenceModel userPreferenceModel = new UserPreferenceModel { HdId = hdid, Preference = "TutorialPopover", Value = true.ToString(), }; List <UserPreferenceModel> userPreferences = new List <UserPreferenceModel>(); userPreferences.Add(userPreferenceModel); List <UserPreference> dbUserPreferences = new List <UserPreference>(); dbUserPreferences.Add(userPreferenceModel.ToDbModel()); DBResult <IEnumerable <UserPreference> > readResult = new DBResult <IEnumerable <UserPreference> > { Payload = dbUserPreferences, Status = dbResultStatus }; Mock <IUserPreferenceDelegate> preferenceDelegateMock = new Mock <IUserPreferenceDelegate>(); preferenceDelegateMock.Setup(s => s.GetUserPreferences(hdid)).Returns(readResult); Mock <IEmailDelegate> emailDelegateMock = new Mock <IEmailDelegate>(); Mock <IMessagingVerificationDelegate> emailInviteDelegateMock = new Mock <IMessagingVerificationDelegate>(); emailInviteDelegateMock.Setup(s => s.GetLastByInviteKey(It.IsAny <Guid>())).Returns(new MessagingVerification()); Mock <IConfigurationService> configServiceMock = new Mock <IConfigurationService>(); configServiceMock.Setup(s => s.GetConfiguration()).Returns(new ExternalConfiguration()); Mock <ILegalAgreementDelegate> legalAgreementDelegateMock = new Mock <ILegalAgreementDelegate>(); legalAgreementDelegateMock .Setup(s => s.GetActiveByAgreementType(LegalAgreementType.TermsofService)) .Returns(new DBResult <LegalAgreement>() { Payload = termsOfService }); Mock <ICryptoDelegate> cryptoDelegateMock = new Mock <ICryptoDelegate>(); Mock <INotificationSettingsService> notificationServiceMock = new Mock <INotificationSettingsService>(); Mock <IMessagingVerificationDelegate> messageVerificationDelegateMock = new Mock <IMessagingVerificationDelegate>(); IUserProfileService service = new UserProfileService( new Mock <ILogger <UserProfileService> >().Object, new Mock <IPatientService>().Object, new Mock <IUserEmailService>().Object, new Mock <IUserSMSService>().Object, configServiceMock.Object, new Mock <IEmailQueueService>().Object, notificationServiceMock.Object, profileDelegateMock.Object, preferenceDelegateMock.Object, new Mock <ILegalAgreementDelegate>().Object, messageVerificationDelegateMock.Object, cryptoDelegateMock.Object, new Mock <IHttpContextAccessor>().Object); RequestResult <Dictionary <string, UserPreferenceModel> > actualResult = service.GetUserPreferences(hdid); return(new Tuple <RequestResult <Dictionary <string, UserPreferenceModel> >, List <UserPreferenceModel> >(actualResult, userPreferences)); }