static void Main(string[] args)
        {
            var productFinder = new ProductFinder(ConnectionString);
            var product       = productFinder.FindById(1);

            Console.WriteLine($"Product price: {product.Price}, after discount: {product.PriceWithDiscount(10.0)}, USD: {product.PriceConvertToUsd()}");
        }
        public IHttpActionResult Search(string keyword)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var finder = new ProductFinder();

            finder.AddProductStore(new JumboProductStore());
            finder.AddProductStore(new PlusProductStore());
            finder.AddProductStore(new AHProductStore());

            var model = new SearchResults();

            model.SearchTerm   = keyword;
            model.Supermarkets =
                finder
                .Find(keyword)
                .GroupBy(p => p.Supermarket)
                .Select(s => new Supermarket
            {
                Name     = s.Key,
                Products = s.ToList()
            });

            stopwatch.Stop();

            model.Duration = $"{stopwatch.Elapsed.Seconds} seconds and {stopwatch.Elapsed.Milliseconds} milliseconds";

            return(Ok(model));
        }
        public ActionResult Search(string product)
        {
            try
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                var finder = new ProductFinder();
                finder.AddProductStore(new JumboProductStore());
                finder.AddProductStore(new PlusProductStore());
                finder.AddProductStore(new AHProductStore());
                var model = new SearchViewModel();
                model.SearchTerm = product;
                model.Products   = finder.Find(product).OrderBy(p => p.Price);

                stopwatch.Stop();

                model.SearchDuration = $"{stopwatch.Elapsed.Seconds} seconds and {stopwatch.Elapsed.Milliseconds} milliseconds";

                return(View(model));
            }
            catch (System.Exception ex)
            {
                var model = new ErrorModel
                {
                    Exception  = ex.ToString(),
                    Message    = ex.Message,
                    Stacktrace = ex.StackTrace
                };

                return(RedirectToAction("Index", "Error", model));
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var productFinder = new ProductFinder(ConnectionString);
            var product       = productFinder.FindById(1);

            product.Name = "New name";
            product.Update();

            var product2 = productFinder.FindById(1);

            Console.WriteLine($"Product name: {product2.Name}");
        }
Beispiel #5
0
        public void TestIdentityMapOfProductFinder()
        {
            int productId        = 9;
            int anotherProductId = 54;

            ProductFinder  productFinder   = new ProductFinder();
            ProductGateway productGateway1 = productFinder.FindProductGatewayById(productId);
            ProductGateway productGateway2 = productFinder.FindProductGatewayById(productId);

            Assert.AreEqual(productGateway1, productGateway2);

            ProductGateway productGateway3 = productFinder.FindProductGatewayById(anotherProductId);

            Assert.AreNotEqual(productGateway1, productGateway3);
            Assert.AreNotEqual(productGateway2, productGateway3);
        }
Beispiel #6
0
        public void TestProductFinder()
        {
            int productId = 9;

            ProductFinder  productFinder  = new ProductFinder();
            ProductGateway productGateway = productFinder.FindProductGatewayById(productId);

            Assert.AreEqual(productId, productGateway.ProductID);
            Assert.AreEqual("Mishi Kobe Niku", productGateway.ProductName);
            Assert.AreEqual(4, productGateway.SupplierID);
            Assert.AreEqual(6, productGateway.CategoryID);
            Assert.AreEqual("18 - 500 g pkgs.", productGateway.QuantityPerUnit);
            Assert.AreEqual(97.0000m, productGateway.UnitPrice);
            Assert.AreEqual((short)29, productGateway.UnitsInStock);
            Assert.AreEqual((short)0, productGateway.UnitsOnOrder);
            Assert.AreEqual((short)0, productGateway.ReorderLevel);
            Assert.AreEqual(true, productGateway.Discontinued);
        }
        public ActionResult Index()
        {
            var cartItems = Enumerable.Empty <CartItemDto>();

            if (Cart.HasItems)
            {
                // LINQ
                var productsIdsWithCount = Cart.ProductsIdsWithCount;
                var products             = ProductFinder.FindProducts(new ProductSearchCriteria
                {
                    SpecificProductIds = productsIdsWithCount.Keys.ToList()
                });

                cartItems = from p in products.Items
                            select new CartItemDto {
                    Name = p.DisplayedName, ProductId = p.ProductId, Count = productsIdsWithCount[p.ProductId]
                };
            }


            return(View(cartItems));
        }
 protected void Init()
 {
     this._finder = new ProductFinder(this.CreateProductRepository());
 }
 public ProductFinderShould()
 {
     productRepository = new Mock <ProductRepository>();
     productFinder     = new ProductFinder(productRepository.Object);
 }