public async Task When_adding_a_product_succeeds_expect_ok_object_result() { var notFoundApiResult = new ApiResult(); var mockedService = Mock.Of <IProductService>(); Mock.Get(mockedService).Setup(i => i.AddProduct(It.IsAny <string>())).ReturnsAsync(notFoundApiResult); var controller = new ProductController(mockedService); var result = await controller.AddItem("NotFoundProduct"); result.Result.Should().BeEquivalentTo(new OkObjectResult(notFoundApiResult)); }
public async Task When_adding_a_product_an_error_occurs_expect_bad_request() { var duplicateProduct = new ApiResult(new Error(ErrorCode.ProductNotFound, "Message")); var mockedService = Mock.Of <IProductService>(); Mock.Get(mockedService).Setup(i => i.AddProduct(It.IsAny <string>())).ReturnsAsync(duplicateProduct); var controller = new ProductController(mockedService); var result = await controller.AddItem("DuplicateProduct"); result.Result.Should().BeEquivalentTo(new BadRequestObjectResult(duplicateProduct)); }