public async Task CreateReturnsCreatedAtActionWhenSuccessAnswerAsync() { // Arrange var query = new ApiGeoCreateCommand() { ProjectId = "0000000000000001", Title = "Test Geo" }; var newId = "0000000000000000"; var mediator = new Mock <IMediator>(); mediator.Setup(x => x.Send(It.IsAny <GeoCreateCommand>(), It.IsAny <CancellationToken>())) .ReturnsAsync( new CreateResult(newId)) .Verifiable("Query was not sent."); var controller = BuildController(mediator); // Act var answer = await controller.Create(query); // Assert Assert.IsType <CreatedAtActionResult>(answer); Assert.Equal(newId, ((CreatedAtActionResult)answer).Value); mediator.Verify(x => x.Send(It.IsAny <GeoCreateCommand>(), It.IsAny <CancellationToken>())); }
public async Task CreateReturnsBadResultWhenNotSuccessAnswerAsync() { // Arrange var query = new ApiGeoCreateCommand() { ProjectId = "0000000000000001", Title = "Test Geo" }; var mediator = new Mock <IMediator>(); mediator.Setup(x => x.Send(It.IsAny <GeoCreateCommand>(), It.IsAny <CancellationToken>())) .ReturnsAsync( new CreateResult(new string[] { "Error" })) .Verifiable("Query was not sent."); var controller = BuildController(mediator); // Act var answer = await controller.Create(query); // Assert Assert.IsType <BadRequestResult>(answer); mediator.Verify(x => x.Send(It.IsAny <GeoCreateCommand>(), It.IsAny <CancellationToken>())); }