コード例 #1
0
        public void TestExecute()
        {
            IJobDetail jobDetail = new JobDetailImpl("jobsettings", typeof(SendTextMessageJob));

            _mockJobExecutionContext.Setup(mock => mock.JobDetail).Returns(jobDetail);

            MpMessageTemplate mockMessageTemplate = new MpMessageTemplate()
            {
                Body = "<div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\">Hi there!<br /></div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\"><br /></div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\">Welcome to the [Event_Date] [EVent_Start_Time] Crossroads service. </div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\"><br /></div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\">Click here to join us:  https://[BaseUrl]/live/stream</div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\"><br /></div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\">We\'re glad you\'re here,</div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\">-Crossroads</div></div>"
            };

            string mockParsedTemplate =
                "<div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\">Hi there!<br /></div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\"><br /></div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\">Welcome to the word up Crossroads service. </div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\"><br /></div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\">Click here to join us:  https://localhost/live/stream</div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\"><br /></div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\">We\'re glad you\'re here,</div><div style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, 255);\">-Crossroads</div></div>";

            TextCommunicationDto dto = new TextCommunicationDto()
            {
                MergeData     = new Dictionary <string, object>(),
                StartDate     = DateTime.Now,
                TemplateId    = 10,
                ToPhoneNumber = "+12345678910"
            };

            dto.MergeData.Add("Event_Date", "datey mcdateface");
            dto.MergeData.Add("Event_Start_Time", "starty mctimeface");

            IDictionary <string, object> keyValuePairs = new Dictionary <string, object>()
            {
                { "TemplateId", dto.TemplateId },
                { "MergeData", dto.MergeData },
                { "StartDate", dto.StartDate },
                { "ToPhoneNumber", dto.ToPhoneNumber }
            };

            JobDataMap jobDataMap = new JobDataMap(keyValuePairs);

            _mockJobExecutionContext.SetupGet(p => p.JobDetail.JobDataMap).Returns(jobDataMap);

            _communicationRepository.Setup(mock => mock.GetTemplate(dto.TemplateId)).Returns(mockMessageTemplate);
            _communicationRepository.Setup(mock => mock.ParseTemplateBody(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >()))
            .Returns(mockParsedTemplate);

            var expectedBody = HtmlHelper.StripHTML(mockParsedTemplate);

            var spiedBody  = "";
            var spiedPhone = "";

            _textCommunicationService.Setup(mock => mock.SendTextMessage(It.IsAny <string>(), It.IsAny <string>()))
            .Callback <string, string>((phone, body) =>
            {
                spiedBody  = body;
                spiedPhone = phone;
            });
            _fixture.Execute(_mockJobExecutionContext.Object);
            Assert.AreEqual(dto.ToPhoneNumber, spiedPhone);
            Assert.AreEqual(expectedBody, spiedBody);
        }
コード例 #2
0
        public IHttpActionResult PostReminder(TextCommunicationDto textCommunicationData)
        {
            if (textCommunicationData == null || !ModelState.IsValid)
            {
                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("Received invalid schedule text event " + textCommunicationData);
                }
                return(BadRequest(ModelState));
            }

            _logger.Debug("Received schedule text request " + textCommunicationData);

            try
            {
                // Hardcode template ID for now to mitigate misuse risk
                textCommunicationData.TemplateId = _streamReminderTemplateId;

                ScheduledJob scheduledJob = new ScheduledJob();
                scheduledJob.StartDateTime = textCommunicationData.StartDate.Value;
                scheduledJob.JobType       = typeof(SendTextMessageJob);
                scheduledJob.Dto           = new Dictionary <string, object>()
                {
                    { "TemplateId", textCommunicationData.TemplateId },
                    { "MergeData", textCommunicationData.MergeData },
                    { "ToPhoneNumber", textCommunicationData.ToPhoneNumber },
                    { "StartDate", textCommunicationData.StartDate }
                };

                var message = _messageFactory.CreateMessage(scheduledJob);

                if (!_messageQueue.Exists(_eventQueueName))
                {
                    _messageQueue.CreateQueue(_eventQueueName, QueueAccessMode.Send);
                }

                _messageQueue.Send(message, MessageQueueTransactionType.None);
            }
            catch (Exception e)
            {
                var msg = "Unexpected error processing schedule text request " + textCommunicationData;
                _logger.Error(msg, e);
                var apiError = new ApiErrorDto("Schedule Text failed", e);
                throw new HttpResponseException(apiError.HttpResponseMessage);
            }

            return(this.Ok());
        }
コード例 #3
0
        public void TestPostReminderIsSuccessful()
        {
            TextCommunicationDto textData = new TextCommunicationDto
            {
                TemplateId    = 264567,
                MergeData     = new Dictionary <string, object>(),
                ToPhoneNumber = "1234567890",
                StartDate     = DateTime.Now
            };

            ScheduledJob scheduledJob = new ScheduledJob();

            scheduledJob.StartDateTime = textData.StartDate.Value;
            scheduledJob.JobType       = typeof(SendTextMessageJob);
            scheduledJob.Dto           = new Dictionary <string, object>()
            {
                { "TemplateId", textData.TemplateId },
                { "MergeData", textData.MergeData },
                { "ToPhoneNumber", textData.ToPhoneNumber },
                { "StartDate", textData.StartDate }
            };

            var          msg = new Mock <Message>();
            ScheduledJob spiedScheduledJob = new ScheduledJob();

            _messageFactory.Setup(mock => mock.CreateMessage(It.IsAny <ScheduledJob>(), null))
            .Callback <object, IMessageFormatter>((obj, imf) => spiedScheduledJob = (ScheduledJob)obj)
            .Returns(msg.Object);

            var spiedMsg = new Object();

            _messageQueue.Setup(mock => mock.Send(It.IsAny <Object>(), It.IsAny <MessageQueueTransactionType>()))
            .Callback <Object, MessageQueueTransactionType>((obj, type) => spiedMsg = obj)
            .Verifiable();

            _fixture.PostReminder(textData);
            _messageFactory.Verify(mock => mock.CreateMessage(It.IsAny <ScheduledJob>(), null), Times.Once());
            Assert.AreEqual(JsonConvert.SerializeObject(scheduledJob), JsonConvert.SerializeObject(spiedScheduledJob));
            _messageQueue.Verify();
        }