public void ShouldValidateSMSWithInvalidInvite() { var smsValidationCode = "SMSValidationCodeMock"; MessagingVerification expectedResult = new MessagingVerification { HdId = "invalid" + HdIdMock, VerificationAttempts = 0, SMSValidationCode = smsValidationCode, ExpireDate = DateTime.Now.AddDays(1), }; Mock <IMessagingVerificationDelegate> messagingVerificationDelegate = new Mock <IMessagingVerificationDelegate>(); messagingVerificationDelegate.Setup(s => s.GetLastForUser(It.IsAny <string>(), It.IsAny <string>())).Returns(expectedResult); Mock <IUserProfileDelegate> userProfileDelegate = new Mock <IUserProfileDelegate>(); var userProfileMock = new Database.Wrapper.DBResult <UserProfile>() { Payload = new UserProfile(), Status = Database.Constants.DBStatusCode.Read, }; userProfileDelegate.Setup(s => s.GetUserProfile(It.IsAny <string>())).Returns(userProfileMock); userProfileDelegate.Setup(s => s.Update(It.IsAny <UserProfile>(), It.IsAny <bool>())).Returns(new Database.Wrapper.DBResult <UserProfile>()); IUserSMSService service = new UserSMSService( new Mock <ILogger <UserSMSService> >().Object, messagingVerificationDelegate.Object, userProfileDelegate.Object, new Mock <INotificationSettingsService>().Object); bool actualResult = service.ValidateSMS(HdIdMock, smsValidationCode); Assert.True(!actualResult); }
public void ShouldQueue() { NotificationSettingsRequest nsr = new NotificationSettingsRequest() { EmailEnabled = true, EmailAddress = "*****@*****.**", SMSEnabled = true, SMSNumber = "2505555555", SubjectHdid = "hdid", SMSVerificationCode = "123456", SMSVerified = false, }; var mockLogger = new Mock <ILogger <NotificationSettingsService> >(); var mockJobClient = new Mock <IBackgroundJobClient>(); var mockNSDelegate = new Mock <INotificationSettingsDelegate>(); var mockResourceDelegateDelegate = new Mock <IResourceDelegateDelegate>(); var dbResult = new Database.Wrapper.DBResult <IEnumerable <ResourceDelegate> >(); dbResult.Payload = new List <ResourceDelegate>(); mockResourceDelegateDelegate.Setup(s => s.Get(nsr.SubjectHdid, 0, 500)).Returns(dbResult); INotificationSettingsService service = new NotificationSettingsService( mockLogger.Object, mockJobClient.Object, mockNSDelegate.Object, mockResourceDelegateDelegate.Object); var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, IgnoreNullValues = true, WriteIndented = true, }; string expectedJobParm = JsonSerializer.Serialize(nsr, options); service.QueueNotificationSettings(nsr); mockJobClient.Verify(x => x.Create( It.Is <Job>(job => job.Method.Name == "PushNotificationSettings" && (string)job.Args[0] == expectedJobParm), It.IsAny <EnqueuedState>())); }
public void ShouldCreateSMSCode() { NotificationSettingsRequest nsr = new NotificationSettingsRequest() { EmailEnabled = true, EmailAddress = "*****@*****.**", SMSEnabled = true, SMSNumber = "2505555555", SubjectHdid = "hdid", SMSVerified = true, }; var mockLogger = new Mock <ILogger <NotificationSettingsService> >(); var mockJobClient = new Mock <IBackgroundJobClient>(); var mockNSDelegate = new Mock <INotificationSettingsDelegate>(); var mockResourceDelegateDelegate = new Mock <IResourceDelegateDelegate>(); var dbResult = new Database.Wrapper.DBResult <IEnumerable <ResourceDelegate> >(); dbResult.Payload = new List <ResourceDelegate>() { new ResourceDelegate() { ProfileHdid = hdid }, }; mockResourceDelegateDelegate.Setup(s => s.Get(nsr.SubjectHdid, 0, 500)).Returns(dbResult); INotificationSettingsService service = new NotificationSettingsService( mockLogger.Object, mockJobClient.Object, mockNSDelegate.Object, mockResourceDelegateDelegate.Object); Assert.True(nsr.SMSVerificationCode == null); service.QueueNotificationSettings(nsr); mockJobClient.Verify(x => x.Create( It.Is <Job>(job => job.Method.Name == "PushNotificationSettings" && job.Args[0] is string), It.IsAny <EnqueuedState>())); Assert.True(nsr.SMSVerificationCode != null); }