public void ShouldSendAnEmailToThePersonsReference() { const int contactId = 123456; const int referenceContactId = 9876545; const int messageId = 456; const int templateId = 2018; var participant = ParticipantMock(); var contact = ContactMock(contactId); var referenceContact = ContactMock(referenceContactId); var referenceData = new Dictionary <string, object> { { "participant", participant }, { "contact", contact }, { "referenceContactId", referenceContactId.ToString() } }; _contactMock.Setup(m => m.GetContactById(referenceContactId)).Returns(referenceContact); _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderReferenceEmailTemplate")).Returns(templateId); _configWrapper.Setup(m => m.GetConfigValue("BaseMPUrl")).Returns("adminint"); var mergeData = new Dictionary <string, object>(); var communication = ReferenceCommunication(2018, mergeData, referenceContact); _communicationRepository.Setup(m => m.GetTemplateAsCommunication(2018, referenceContact.Contact_ID, It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(communication); _communicationRepository.Setup(m => m.SendMessage(communication, false)).Returns(messageId); var result = _fixture.SendReferenceEmail(referenceData); result.Subscribe((n) => { Assert.AreEqual(messageId, result); }, (err) => { Assert.Fail(err.ToString()); }); }
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); }