public async Task And_Exception_Then_Returns_Bad_Request( long cohortId, [Frozen] Mock <IMediator> mockMediator, [Greedy] DraftApprenticeshipController controller) { mockMediator .Setup(mediator => mediator.Send( It.Is <GetDraftApprenticeshipsQuery>(x => x.CohortId == cohortId), It.IsAny <CancellationToken>())) .Throws <InvalidOperationException>(); var controllerResult = await controller.GetAll(cohortId) as BadRequestResult; controllerResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest); }
public async Task Then_Gets_DraftApprenticeships_From_Mediator( long cohortId, GetDraftApprenticeshipsResult mediatorResult, [Frozen] Mock <IMediator> mockMediator, [Greedy] DraftApprenticeshipController controller) { mockMediator .Setup(mediator => mediator.Send( It.Is <GetDraftApprenticeshipsQuery>(x => x.CohortId == cohortId), It.IsAny <CancellationToken>())) .ReturnsAsync(mediatorResult); var controllerResult = await controller.GetAll(cohortId) as ObjectResult; Assert.IsNotNull(controllerResult); controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK); var model = controllerResult.Value as GetDraftApprenticeshipsResult; Assert.IsNotNull(model); model.DraftApprenticeships.Should().BeEquivalentTo(mediatorResult.DraftApprenticeships); }