public async Task GetOption_OptionExists() { //Arrange var productOptionsRepository = new Mock <IAsyncRepository <ProductAggregate.ProductOption> >(); productOptionsRepository.Setup(repo => repo.GetByIdAsync(It.IsAny <Guid>())) .ReturnsAsync(MockObjects.ProductOption.GetProductOption()) .Verifiable(); var productRepository = new Mock <IAsyncRepository <ProductAggregate.Product> >(); var controlller = new ProductOptionsController(productRepository.Object, productOptionsRepository.Object); //Act var result = await controlller.GetOptionAsync(new Guid()); //Assert var okObjectResult = result as OkObjectResult; var product = okObjectResult.Value as object; productRepository.Verify(); Assert.NotNull(okObjectResult); Assert.NotNull(product); }
public async Task GetOption_OptionDoesNotExist() { //Arrange var productOptionsRepository = new Mock <IAsyncRepository <ProductAggregate.ProductOption> >(); productOptionsRepository.Setup(repo => repo.GetByIdAsync(It.IsAny <Guid>())) .ReturnsAsync(MockObjects.ProductOption.GetProductOption_Empty()) .Verifiable(); var productRepository = new Mock <IAsyncRepository <ProductAggregate.Product> >(); var controlller = new ProductOptionsController(productRepository.Object, productOptionsRepository.Object); //Act var result = await controlller.GetOptionAsync(new Guid()); //Assert var notFoundResult = result as NotFoundResult; //Assert productRepository.Verify(); Assert.NotNull(notFoundResult); Assert.Equal(StatusCodes.Status404NotFound, notFoundResult.StatusCode); }