private async Task <Tuple <RequestResult <UserProfileModel>, UserProfileModel> > ExecuteInsertUserProfile(Database.Constants.DBStatusCode dbResultStatus, string registrationStatus, MessagingVerification messagingVerification = null) { UserProfile userProfile = new UserProfile { HdId = hdid, AcceptedTermsOfService = true, Email = "*****@*****.**" }; UserProfileModel expected = UserProfileModel.CreateFromDbModel(userProfile); Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>(); profileDelegateMock.Setup(s => s.InsertUserProfile(It.Is <UserProfile>(x => x.HdId == userProfile.HdId))).Returns(new DBResult <UserProfile> { Payload = userProfile, Status = DBStatusCode.Created }); Mock <IConfigurationService> configServiceMock = new Mock <IConfigurationService>(); configServiceMock.Setup(s => s.GetConfiguration()).Returns(new ExternalConfiguration() { WebClient = new WebClientConfiguration() { RegistrationStatus = registrationStatus } }); Mock <ICryptoDelegate> cryptoDelegateMock = new Mock <ICryptoDelegate>(); cryptoDelegateMock.Setup(s => s.GenerateKey()).Returns("abc"); Mock <INotificationSettingsService> notificationServiceMock = new Mock <INotificationSettingsService>(); notificationServiceMock.Setup(s => s.QueueNotificationSettings(It.IsAny <NotificationSettingsRequest>())); 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, new Mock <IUserPreferenceDelegate>().Object, new Mock <ILegalAgreementDelegate>().Object, new Mock <IMessagingVerificationDelegate>().Object, cryptoDelegateMock.Object, new Mock <IHttpContextAccessor>().Object); RequestResult <UserProfileModel> actualResult = await service.CreateUserProfile(new CreateUserRequest() { Profile = userProfile }, DateTime.Today); return(new Tuple <RequestResult <UserProfileModel>, UserProfileModel>(actualResult, expected)); }
private async Task LoginFacebookAsync(SocialNetwork socialNetwork) { try { if (_facebookClient.IsLoggedIn) { _facebookClient.Logout(); } EventHandler <FBEventArgs <string> > userDataDelegate = null; userDataDelegate = async(object sender, FBEventArgs <string> e) => { switch (e.Status) { case FacebookActionStatus.Completed: var facebookProfile = await Task.Run(() => JsonConvert.DeserializeObject <FacebookProfile>(e.Data)); var userProfile = new UserProfile(facebookProfile.Id, $"{facebookProfile.FirstName} {facebookProfile.LastName}", facebookProfile.Email, facebookProfile.Picture.Data.Url); await _userProfileService.CreateUserProfile(userProfile); var userProfileFromDb = await _userProfileService.GetUserProfileByProfileId(userProfile.ProfileId); await App.Current.MainPage.Navigation.PushModalAsync(new HomePage(userProfileFromDb)); break; case FacebookActionStatus.Canceled: await App.Current.MainPage.DisplayAlert("Facebook Auth", "Cancelled", "Ok"); break; case FacebookActionStatus.Error: await App.Current.MainPage.DisplayAlert("Facebook Auth", "Error", "Ok"); break; case FacebookActionStatus.Unauthorized: await App.Current.MainPage.DisplayAlert("Facebook Auth", "Unauthorized", "Ok"); break; } _facebookClient.OnUserData -= userDataDelegate; }; _facebookClient.OnUserData += userDataDelegate; string[] fbRequestFields = { "email", "first_name", "picture", "gender", "last_name" }; string[] fbPermisions = { "email" }; await _facebookClient.RequestUserDataAsync(fbRequestFields, fbPermisions); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }
public async void ShouldQueueNotificationUpdate() { UserProfile userProfile = new UserProfile { HdId = "1234567890123456789012345678901234567890123456789012", AcceptedTermsOfService = true, Email = string.Empty }; DBResult <UserProfile> insertResult = new DBResult <UserProfile> { Payload = userProfile, Status = DBStatusCode.Created }; UserProfileModel expected = UserProfileModel.CreateFromDbModel(userProfile); Mock <IEmailQueueService> emailer = new Mock <IEmailQueueService>(); Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>(); profileDelegateMock.Setup(s => s.InsertUserProfile(It.Is <UserProfile>(x => x.HdId == userProfile.HdId))).Returns(insertResult); Mock <IUserPreferenceDelegate> preferenceDelegateMock = new Mock <IUserPreferenceDelegate>(); 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() { WebClient = new WebClientConfiguration() { RegistrationStatus = RegistrationStatus.Open } }); Mock <ICryptoDelegate> cryptoDelegateMock = new Mock <ICryptoDelegate>(); cryptoDelegateMock.Setup(s => s.GenerateKey()).Returns("abc"); Mock <INotificationSettingsService> notificationServiceMock = new Mock <INotificationSettingsService>(); notificationServiceMock.Setup(s => s.QueueNotificationSettings(It.IsAny <NotificationSettingsRequest>())); 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, new Mock <IMessagingVerificationDelegate>().Object, cryptoDelegateMock.Object, new Mock <IHttpContextAccessor>().Object); // Execute RequestResult <UserProfileModel> actualResult = await service.CreateUserProfile(new CreateUserRequest() { Profile = userProfile }, DateTime.Today); // Verify notificationServiceMock.Verify(s => s.QueueNotificationSettings(It.IsAny <NotificationSettingsRequest>()), Times.Once()); Assert.Equal(ResultType.Success, actualResult.ResultStatus); Assert.Equal(expected.HdId, actualResult.ResourcePayload.HdId); Assert.Equal(expected.AcceptedTermsOfService, actualResult.ResourcePayload.AcceptedTermsOfService); Assert.Equal(expected.Email, actualResult.ResourcePayload.Email); }
public void ShouldQueueNotificationUpdate() { UserProfile userProfile = new UserProfile { HdId = "1234567890123456789012345678901234567890123456789012", AcceptedTermsOfService = true, Email = string.Empty }; DBResult <UserProfile> insertResult = new DBResult <UserProfile> { Payload = userProfile, Status = DBStatusCode.Created }; UserProfileModel expected = UserProfileModel.CreateFromDbModel(userProfile); Mock <IEmailQueueService> emailer = new Mock <IEmailQueueService>(); Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>(); profileDelegateMock.Setup(s => s.InsertUserProfile(userProfile)).Returns(insertResult); Mock <IUserPreferenceDelegate> preferenceDelegateMock = new Mock <IUserPreferenceDelegate>(); Mock <IEmailDelegate> emailDelegateMock = new Mock <IEmailDelegate>(); Mock <IMessagingVerificationDelegate> emailInviteDelegateMock = new Mock <IMessagingVerificationDelegate>(); emailInviteDelegateMock.Setup(s => s.GetByInviteKey(It.IsAny <Guid>())).Returns(new MessagingVerification()); Mock <IConfigurationService> configServiceMock = new Mock <IConfigurationService>(); configServiceMock.Setup(s => s.GetConfiguration()).Returns(new ExternalConfiguration() { WebClient = new WebClientConfiguration() { RegistrationStatus = RegistrationStatus.Open } }); Mock <ICryptoDelegate> cryptoDelegateMock = new Mock <ICryptoDelegate>(); cryptoDelegateMock.Setup(s => s.GenerateKey()).Returns("abc"); Mock <INotificationSettingsService> notificationServiceMock = new Mock <INotificationSettingsService>(); notificationServiceMock.Setup(s => s.QueueNotificationSettings(It.IsAny <NotificationSettingsRequest>())); Mock <IMessagingVerificationDelegate> messageVerificationDelegateMock = new Mock <IMessagingVerificationDelegate>(); IUserProfileService service = new UserProfileService( new Mock <ILogger <UserProfileService> >().Object, profileDelegateMock.Object, preferenceDelegateMock.Object, emailDelegateMock.Object, emailInviteDelegateMock.Object, configServiceMock.Object, emailer.Object, new Mock <ILegalAgreementDelegate>().Object, cryptoDelegateMock.Object, notificationServiceMock.Object, messageVerificationDelegateMock.Object); RequestResult <UserProfileModel> actualResult = service.CreateUserProfile(new CreateUserRequest() { Profile = userProfile }, new Uri("http://localhost/"), "bearer_token"); notificationServiceMock.Verify(s => s.QueueNotificationSettings(It.IsAny <NotificationSettingsRequest>()), Times.Once()); Assert.Equal(ResultType.Success, actualResult.ResultStatus); Assert.True(actualResult.ResourcePayload.IsDeepEqual(expected)); }