public void ShouldReturnProductWithoutSubcategory() { // Arrange var product = new Product() { Class = "TestClass", Color = "TestColor", ListPrice = 9.99m, Name = "TestProduct", Id = 1, ProductNumber = "TestProductNumber", Size = "TestSize", SizeUnitMeasureCode = "FT", Style = "TestStyle", Weight = 2, WeightUnitMeasureCode = "LBS", }; var repository = new StubIProductRepository() { GetProductInt32 = productId => product }; var recommendationRepository = new StubIProductRecommendationRepository(); var controller = new ProductsController(repository, recommendationRepository); SetupControllerForTests(controller); // Act var result = controller.Get(1); var returnedProduct = new JavaScriptSerializer().Deserialize <ProductDetail>(result.Content.ReadAsStringAsync().Result); // Assert Assert.AreEqual(result.StatusCode, HttpStatusCode.OK); Assert.AreEqual(returnedProduct.Id, product.Id); }
public void ShouldReturnNotFoundForProducts() { // Arrange var productRepository = new StubIProductRepository() { GetProductsInt32 = subcategoryId => null }; var recommendationRepository = new StubIProductRecommendationRepository(); var controller = new ProductsController(productRepository, recommendationRepository); SetupControllerForTests(controller); // Act var result = controller.GetProducts(1); // Assert Assert.AreEqual(result.StatusCode, HttpStatusCode.NotFound); }