예제 #1
0
        public void ShouldSendNoReferenceEmail()
        {
            const int    templateId         = 5;
            const int    applicantContactId = 9987654;
            const int    groupsContactId    = 1123456;
            const string groupsEmail        = "*****@*****.**";
            const int    messageId          = 7;
            var          applicantContact   = ContactMock(applicantContactId);
            var          groupsContact      = new MpMyContact
            {
                Contact_ID    = groupsContactId,
                Email_Address = groupsEmail
            };
            var mergeData = new Dictionary <string, object>
            {
                { "First_Name", applicantContact.Nickname },
                { "Last_Name", applicantContact.Last_Name },
                { "Email_Address", applicantContact.Email_Address }
            };
            var communication = NoReferenceCommunication(templateId, mergeData, groupsContact);
            var referenceData = new Dictionary <string, object>
            {
                { "contact", applicantContact },
                { "participant", ParticipantMock() },
                { "referenceContactId", "0" }
            };

            _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderNoReferenceEmailTemplate")).Returns(templateId);
            _configWrapper.Setup(m => m.GetConfigIntValue("DefaultGroupContactEmailId")).Returns(groupsContactId);
            _contactMock.Setup(m => m.GetContactEmail(groupsContactId)).Returns(groupsEmail);
            _communicationRepository.Setup(m => m.GetTemplateAsCommunication(templateId, groupsContactId, groupsEmail, mergeData)).Returns(communication);
            _communicationRepository.Setup(m => m.SendMessage(communication, false)).Returns(messageId);

            var response = _fixture.SendNoReferenceEmail(referenceData);

            response.Subscribe((n) =>
            {
                Assert.AreEqual(messageId, response);
            },
                               (err) =>
            {
                Assert.Fail(err.ToString());
            });
        }
예제 #2
0
        public async Task <IHttpActionResult> SaveSpiritualGrowth([FromBody] SpiritualGrowthDTO spiritualGrowth)
        {
            if (ModelState.IsValid)
            {
                return(await Authorized(token =>
                {
                    try
                    {
                        _groupLeaderService.SaveSpiritualGrowth(spiritualGrowth)
                        .Concat(_groupLeaderService.SetApplied(token)).Wait();

                        _groupLeaderService.GetApplicationData(spiritualGrowth.ContactId).Subscribe((res) =>
                        {
                            if ((string)res["referenceContactId"] != "0")
                            {
                                _groupLeaderService.SendReferenceEmail(res).Subscribe(CancellationToken.None);
                            }
                            else
                            {
                                _groupLeaderService.SendNoReferenceEmail(res).Subscribe(CancellationToken.None);
                            }

                            if (((string)res["studentLeaderRequest"]).ToUpper() == "TRUE")
                            {
                                _groupLeaderService.SendStudentMinistryRequestEmail(res).Subscribe(CancellationToken.None);
                            }
                        });
                        return Ok();
                    }
                    catch (Exception e)
                    {
                        var apiError = new ApiErrorDto("Saving SpiritualGrowth failed:", e);
                        throw new HttpResponseException(apiError.HttpResponseMessage);
                    }
                }));
            }
            var errors    = ModelState.Values.SelectMany(val => val.Errors).Aggregate("", (current, err) => current + err.ErrorMessage);
            var dataError = new ApiErrorDto("Spiritual Growth Data Invalid", new InvalidOperationException("Invalid Spiritual Growth Data" + errors));

            throw new HttpResponseException(dataError.HttpResponseMessage);
        }