public void ShouldCreateSMSCode()
        {
            var mockLogger     = new Mock <ILogger <NotificationSettingsService> >();
            var mockJobClient  = new Mock <IBackgroundJobClient>();
            var mockNSDelegate = new Mock <INotificationSettingsDelegate>();

            INotificationSettingsService service = new NotificationSettingsService(
                mockLogger.Object,
                mockJobClient.Object,
                mockNSDelegate.Object);

            NotificationSettingsRequest nsr = new NotificationSettingsRequest()
            {
                EmailEnabled = true,
                EmailAddress = "*****@*****.**",
                SMSEnabled   = true,
                SMSNumber    = "2505555555",
                SubjectHdid  = "hdid",
                SMSVerified  = false,
            };

            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);
        }
        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);
        }