public async Task GetAll_ReturnsOkObjectResult_With_ProductCategoryResult() { var testList = new List <ProductCategory>() { new ProductCategory() { Id = "abc", Name = "Test" } }; var repoMock = new Mock <IProductCategories>(); repoMock.Setup(p => p.GetAllAsync()) .Returns(Task.FromResult(testList)); var categoryController = new ProductCategoryController(repoMock.Object, null); var response = await categoryController.GetProductCategories(); Assert.IsType <OkObjectResult>(response.Result); var result = response.Result as OkObjectResult; Assert.IsType <ProductCategoryResult>(result.Value); var resultData = (result.Value as ProductCategoryResult).ResultData; Assert.Single(resultData); }
public async Task GetProductCategories_ShouldReturnProductCategories_WhenProductCategoriesExist( [Frozen] List <ProductCategory> categories, [Frozen] Mock <IMediator> mockMediator, [Greedy] ProductCategoryController sut ) { //Arrange mockMediator.Setup(x => x.Send( It.IsAny <GetProductCategoriesQuery>(), It.IsAny <CancellationToken>() )) .ReturnsAsync(categories); //Act var actionResult = await sut.GetProductCategories(); //Assert var okObjectResult = actionResult as OkObjectResult; okObjectResult.Should().NotBeNull(); var response = okObjectResult.Value as List <ProductCategory>; response.Count.Should().Be(categories.Count); for (int i = 0; i < response.Count; i++) { response[i].Name.Should().Be(categories[i].Name); } }