public async Task Then_The_Command_Is_Sent_To_Mediator_And_Response_Returned( CreateCourseDemandCommandResponse response, CourseDemandRequest request, [Frozen] Mock <IMediator> mediator, [Greedy] DemandController controller) { //Arrange response.IsCreated = true; mediator.Setup(x => x.Send(It.Is <CreateCourseDemandCommand>(c => c.CourseDemand.Id.Equals(request.Id) && c.CourseDemand.OrganisationName.Equals(request.OrganisationName) && c.CourseDemand.ContactEmailAddress.Equals(request.ContactEmailAddress) && c.CourseDemand.NumberOfApprentices.Equals(request.NumberOfApprentices) && c.CourseDemand.Course.Id.Equals(request.Course.Id) && c.CourseDemand.Course.Title.Equals(request.Course.Title) && c.CourseDemand.Course.Level.Equals(request.Course.Level) && c.CourseDemand.Course.Route.Equals(request.Course.Route) && c.CourseDemand.Location.Name.Equals(request.Location.Name) && c.CourseDemand.Location.Lat == request.Location.LocationPoint.GeoPoint.First() && c.CourseDemand.Location.Lon == request.Location.LocationPoint.GeoPoint.Last() ), It.IsAny <CancellationToken>())) .ReturnsAsync(response); //Act var actual = await controller.CreateDemand(request) as CreatedResult; //Assert Assert.IsNotNull(actual); actual.StatusCode.Should().Be((int)HttpStatusCode.Created); actual.Value.Should().BeEquivalentTo(new { response.Id }); }
public async Task Then_The_Command_Is_Sent_To_Mediator_And_Response_Returned_And_If_Not_Created_Accepted_Returned( CreateCourseDemandCommandResponse response, CourseDemandRequest request, [Frozen] Mock <IMediator> mediator, [Greedy] DemandController controller) { //Arrange response.IsCreated = false; mediator.Setup(x => x.Send(It.Is <CreateCourseDemandCommand>(c => c.CourseDemand.Id.Equals(request.Id) ), It.IsAny <CancellationToken>())) .ReturnsAsync(response); //Act var actual = await controller.CreateDemand(request) as AcceptedResult; //Assert Assert.IsNotNull(actual); actual.StatusCode.Should().Be((int)HttpStatusCode.Accepted); actual.Value.Should().BeEquivalentTo(new { response.Id }); }