public void Read_IdExisting_ReturnsProductModelWithSpecifiedId() { //Arrange int existingId = 12; ProductModel expected = new ProductModel { Id = existingId, Name = "Rust In Peace Hoodie", ProductCategory = new ProductCategory { Id = 2 }, Price = 120, Products = null }; Mock <IProductModelRepository> productModelRepository = new Mock <IProductModelRepository>(); productModelRepository.Setup(repo => repo.Read(existingId)). Returns(expected); Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>(); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); IProductModelService productModelService = new ProductModelService(productModelRepository.Object, productCategoryRepository.Object, productMetricRepository.Object); //Act ProductModel actual = productModelService.Read(existingId); //Assert Assert.Equal(expected, actual); }
public void Read_IdNonExisting_ReturnsNull() { //Arrange int existingId = 12; ProductModel expected = null; Mock <IProductModelRepository> productModelRepository = new Mock <IProductModelRepository>(); productModelRepository.Setup(repo => repo.Read(existingId)). Returns(expected); Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>(); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); IProductModelService productModelService = new ProductModelService(productModelRepository.Object, productCategoryRepository.Object, productMetricRepository.Object); //Act ProductModel actual = productModelService.Read(existingId); //Assert Assert.Equal(expected, actual); }