public async Task SessionStateDeleteWithValidSessionIdHeaderReturnsSuccessForCallback() { // Arrange const bool expectedSendEmailResult = true; string expectedRedirectUrl = $"/{RegistrationPath}/{HomeController.ThankyouForContactingUsCanonicalName}"; var viewModel = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel(); var controller = BuildEnterYourDetailsController(MediaTypeNames.Text.Html); controller.Request.Headers.Add(ConstantStrings.CompositeSessionIdHeaderName, Guid.NewGuid().ToString()); A.CallTo(() => fakeRoutingService.GetEmailToSendTo(A <string> .Ignored, A <Category> .Ignored)).Returns(A.Dummy <string>()); A.CallTo(() => fakeMapper.Map <ContactUsEmailRequestModel>(A <EnterYourDetailsBodyViewModel> .Ignored)).Returns(A.Fake <ContactUsEmailRequestModel>()); A.CallTo(() => fakeNotifyEmailService.SendEmailAsync(A <ContactUsEmailRequestModel> .Ignored)).Returns(expectedSendEmailResult); A.CallTo(() => fakeSessionStateService.DeleteAsync(A <Guid> .Ignored)).Returns(true); // Act var result = await controller.EnterYourDetailsBody(viewModel).ConfigureAwait(false); // Assert A.CallTo(() => fakeRoutingService.GetEmailToSendTo(A <string> .Ignored, A <Category> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeMapper.Map <ContactUsEmailRequestModel>(A <EnterYourDetailsBodyViewModel> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeNotifyEmailService.SendEmailAsync(A <ContactUsEmailRequestModel> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeSessionStateService.DeleteAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); var redirectResult = Assert.IsType <RedirectResult>(result); Assert.Equal(expectedRedirectUrl, redirectResult.Url); Assert.False(redirectResult.Permanent); controller.Dispose(); }
private async Task <bool> SendEmailAsync(EnterYourDetailsBodyViewModel model) { Logger.LogInformation($"{nameof(SendEmailAsync)} preparing email"); var contactUsRequestModel = mapper.Map <ContactUsEmailRequestModel>(model); contactUsRequestModel.ToEmailAddress = await routingService.GetEmailToSendTo(model.Postcode !, model.SelectedCategory).ConfigureAwait(false); return(await notifyEmailService.SendEmailAsync(contactUsRequestModel).ConfigureAwait(false)); }