Example #1
0
        public void ShouldSetApplicantAsApplied()
        {
            const int    groupLeaderAppliedId = 3;
            const string fakeToken            = "letmein";
            var          fakeParticipant      = ParticipantMock();

            _participantRepository.Setup(m => m.GetParticipantRecord(fakeToken)).Returns(fakeParticipant);
            _participantRepository.Setup(m => m.UpdateParticipant(It.IsAny <MpParticipant>())).Callback((MpParticipant p) =>
            {
                Assert.AreEqual(groupLeaderAppliedId, p.GroupLeaderStatus);
            });
            _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderApplied")).Returns(groupLeaderAppliedId);

            var res = _fixture.SetApplied(fakeToken);

            res.Subscribe((n) =>
            {
                Assert.AreEqual(n, 1);
            },
                          (err) =>
            {
                Assert.Fail();
            });
        }
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);
        }