public async Task Then_The_Api_Is_Called_And_Email_Sent_If_ResponseCode_Is_Created( RegisterDemandCommand command, PostCreateCourseDemand responseBody, [Frozen] Mock <IEmployerDemandApiClient <EmployerDemandApiConfiguration> > apiClient, [Frozen] Mock <INotificationService> mockNotificationService, RegisterDemandCommandHandler handler) { //Arrange var apiResponse = new ApiResponse <PostCreateCourseDemand>(responseBody, HttpStatusCode.Created); apiClient.Setup(x => x.PostWithResponseCode <PostCreateCourseDemand>(It.Is <PostCreateCourseDemandRequest>(c => ((CreateCourseDemandData)c.Data).Id.Equals(command.Id) && ((CreateCourseDemandData)c.Data).ContactEmailAddress.Equals(command.ContactEmailAddress) && ((CreateCourseDemandData)c.Data).OrganisationName.Equals(command.OrganisationName) && ((CreateCourseDemandData)c.Data).NumberOfApprentices.Equals(command.NumberOfApprentices) && ((CreateCourseDemandData)c.Data).Location.LocationPoint.GeoPoint.First() == command.Lat && ((CreateCourseDemandData)c.Data).Location.LocationPoint.GeoPoint.Last() == command.Lon && ((CreateCourseDemandData)c.Data).Location.Name.Equals(command.LocationName) && ((CreateCourseDemandData)c.Data).Course.Title.Equals(command.CourseTitle) && ((CreateCourseDemandData)c.Data).Course.Level.Equals(command.CourseLevel) && ((CreateCourseDemandData)c.Data).Course.Id.Equals(command.CourseId) && ((CreateCourseDemandData)c.Data).Course.Route.Equals(command.CourseSector) ))) .ReturnsAsync(apiResponse); SendEmailCommand actualEmail = null; mockNotificationService .Setup(service => service.Send(It.IsAny <SendEmailCommand>())) .Callback((SendEmailCommand args) => actualEmail = args) .Returns(Task.CompletedTask); var expectedEmail = new CreateDemandConfirmationEmail( command.ContactEmailAddress, command.OrganisationName, command.CourseTitle, command.CourseLevel, command.LocationName, command.NumberOfApprentices); //Act var actual = await handler.Handle(command, CancellationToken.None); //Assert actual.Should().Be(apiResponse.Body.Id); actualEmail.Tokens.Should().BeEquivalentTo(expectedEmail.Tokens); actualEmail.RecipientsAddress.Should().BeEquivalentTo(expectedEmail.RecipientAddress); actualEmail.TemplateId.Should().BeEquivalentTo(expectedEmail.TemplateId); }
public async Task Then_The_Api_Is_Called_And_Email_Not_Sent_If_ResponseCode_Is_Not_Created( RegisterDemandCommand command, PostCreateCourseDemand responseBody, [Frozen] Mock <IEmployerDemandApiClient <EmployerDemandApiConfiguration> > apiClient, [Frozen] Mock <INotificationService> mockNotificationService, RegisterDemandCommandHandler handler) { //Arrange var apiResponse = new ApiResponse <PostCreateCourseDemand>(responseBody, HttpStatusCode.Accepted); apiClient.Setup(x => x.PostWithResponseCode <PostCreateCourseDemand>(It.IsAny <PostCreateCourseDemandRequest>( ))) .ReturnsAsync(apiResponse); //Act var actual = await handler.Handle(command, CancellationToken.None); //Assert actual.Should().Be(apiResponse.Body.Id); mockNotificationService.Verify(x => x.Send(It.IsAny <SendEmailCommand>()), Times.Never); }