Example #1
0
        public void ShouldSaveSpiritualGrowthAnswers()
        {
            const int fakeFormId        = 5;
            const int fakeStoryFieldId  = 1;
            const int fakeTaughtFieldId = 2;
            const int fakeResponseId    = 10;
            const int fakeTemplateId    = 12;

            var growthDto = SpiritualGrowthMock();

            _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderFormId")).Returns(fakeFormId);
            _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderFormStoryFieldId")).Returns(fakeStoryFieldId);
            _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderFormTaughtFieldId")).Returns(fakeTaughtFieldId);
            _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderConfirmationTemplate")).Returns(fakeTemplateId);

            _formService.Setup(m => m.SubmitFormResponse(It.IsAny <MpFormResponse>())).Returns((MpFormResponse form) =>
            {
                Assert.AreEqual(fakeFormId, form.FormId);
                return(fakeResponseId);
            });

            _communicationRepository.Setup(m => m.GetTemplate(fakeTemplateId)).Returns(ConfirmationEmailMock());

            var responseId = _fixture.SaveSpiritualGrowth(growthDto).Wait();

            Assert.AreEqual(fakeResponseId, responseId);
        }
Example #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);
        }