public async Task And_NoApprenticeIsReturnedFromMediator_Then_ReturnNotFound( Guid apprenticeId, [Frozen] Mock <IMediator> mockMediator, [Greedy] ApprenticeController controller) { mockMediator.Setup(m => m.Send(It.IsAny <GetApprenticeQuery>(), CancellationToken.None)) .ReturnsAsync((GetApprenticeResult)null); var controllerResult = await controller.Get(apprenticeId) as NotFoundResult; controllerResult.StatusCode.Should().Be((int)HttpStatusCode.NotFound); }
public async Task And_MediatorThrowsException_Then_ReturnBadRequest( Guid apprenticeId, [Frozen] Mock <IMediator> mockMediator, [Greedy] ApprenticeController controller) { mockMediator .Setup(mediator => mediator.Send( It.IsAny <GetApprenticeQuery>(), It.IsAny <CancellationToken>())) .Throws <InvalidOperationException>(); var controllerResult = await controller.Get(apprenticeId) as BadRequestResult; controllerResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest); }
public async Task Then_GetsApprenticeFromMediator( Guid apprenticeId, GetApprenticeResult mediatorResult, [Frozen] Mock <IMediator> mockMediator, [Greedy] ApprenticeController controller) { mockMediator .Setup(mediator => mediator.Send( It.Is <GetApprenticeQuery>(x => x.ApprenticeId == apprenticeId), It.IsAny <CancellationToken>())) .ReturnsAsync(mediatorResult); var controllerResult = await controller.Get(apprenticeId) as ObjectResult; Assert.IsNotNull(controllerResult); controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK); var model = controllerResult.Value as GetApprenticeResult; Assert.IsNotNull(model); model.Should().BeEquivalentTo(mediatorResult); }