public void GetFeaturedProductsWillReturnCorrectProduct() { // Fixture setup var product = new Product(); product.Name = "Olives"; product.UnitPrice = 24.5m; var repositoryStub = new Mock<ProductRepository>(); repositoryStub .Setup(s => s.GetFeaturedProducts()) .Returns(new[] { product }); var sut = new ProductService(repositoryStub.Object); var userStub = new Mock<IPrincipal>(); // Exercise system var products = sut.GetFeaturedProducts(userStub.Object); var result = products.Single(); // Verify outcome Assert.Equal(product.Name, result.Name); Assert.Equal(product.UnitPrice, result.UnitPrice); // Teardown }
public ViewResult Index() { var productService = new ProductService(this.repository); var vm = new FeaturedProductsViewModel(); var products = productService.GetFeaturedProducts(this.User); foreach (var product in products) { var productVM = new ProductViewModel(product); vm.Products.Add(productVM); } return View(vm); }
public ViewResult Index() { var currencyCode = this.CurrencyProfileService.GetCurrencyCode(); var currency = this.currencyProvider.GetCurrency(currencyCode); var productService = new ProductService(this.repository); var vm = new FeaturedProductsViewModel(); var products = productService.GetFeaturedProducts(this.User); foreach (var product in products) { var productVM = new ProductViewModel(product.ConvertTo(currency)); vm.Products.Add(productVM); } return this.View(vm); }