예제 #1
0
 public Scraper(IProductProcessor productProcessor, IShopCreator shopCreator, IServiceProvider services, ILogger <Scraper> logger)
 {
     _productProcessor = productProcessor;
     _shopCreator      = shopCreator;
     _services         = services;
     _logger           = logger;
 }
        public void ErrorTests()
        {
            var products = new List <IProduct>
            {
                new Product("A", 68.91, 69.80, 69.05),
                new Product("B", 71.92, 71.92, 71.88)
            };

            var pricePoints = new List <IDigit>
            {
                new Digit(3)
            };

            IProductProcessor productProcessor = ProductProcessorFactory
                                                 .GetProductProcessor(products, pricePoints);

            productProcessor.Optimiser = new Optimiser();
            productProcessor.Process();

            Assert.AreEqual(68.91, products[0].NewPrice, 0.002, "Product A New Price incorrect");
            Assert.AreEqual("An error occured :: Price Range Incorrect", products[0].Message, "Product A Message incorrect");

            Assert.AreEqual(71.92, products[1].NewPrice, 0.002, "Product B New Price incorrect");
            Assert.AreEqual("An error occured :: Price Range Incorrect", products[1].Message, "Product B Message incorrect");
        }
        private static void PricePointListEdgeCase(List <IProduct> products)
        {
            Console.WriteLine("Edge Case Tests");

            var pricePoints = new List <IDigit>
            {
                new Digit(3),
                new Digit(9)
            };

            IProductProcessor productProcessor = ProductProcessorFactory.GetProductProcessor(products, pricePoints);

            productProcessor.Optimiser = new Optimiser();
            productProcessor.Process();

            foreach (var product in products)
            {
                Console.WriteLine($"Name: {product.ToString()}");
                Console.WriteLine($"Original Price: {product.OriginalPrice}");
                Console.WriteLine($"New Price: {product.NewPrice}");
                Console.WriteLine($"Min Price: {product.MinPrice}");
                Console.WriteLine($"Max Price: {product.MaxPrice}");
                Console.WriteLine($"Message: {product.Message}");
            }

            Console.WriteLine("Edge Case Tests");
            Console.WriteLine();
        }
예제 #4
0
        static void Main(string[] args)
        {
            ConfigureContainer();
            IConfiguration configuration = Configuration.LoadConfigFromFile();

            var factory = new ProductProcessorFactory();
            IProductProcessor productProcessor = factory.GetProductProcessor(configuration.ProductType);
            Product           product          = productProcessor.GetProduct(Guid.NewGuid());

            Console.WriteLine($"Product: {product.Description}");
        }
예제 #5
0
 public ProductController(IProductProcessor productProcessor)
 {
     _productProcessor = productProcessor;
 }
예제 #6
0
 public ProductsService(IContextFactory contextFactory, IProductProcessor productProcessor)
 {
     _factory = contextFactory;
     this.productProcessor = productProcessor;
 }
예제 #7
0
 public ProductsController(ILogger <ProductsController> logger, IProductProcessor productProcessor)
 {
     _logger           = logger;
     _productProcessor = productProcessor;
 }
 public CalculationController(IProductProcessor processor)
 {
     _processor = processor;
 }
        public void BasicTests()
        {
            var products = new List <IProduct>
            {
                new Product("A", 68.91, 68.85, 69.05),
                new Product("B", 71.92, 71.92, 71.98),
                new Product("C", 69.93, 69.96, 69.98),
                new Product("D", 68.54, 68.96, 69.98),
                new Product("E", 68.95, 68.85, 69.05),
                new Product("F", 68.96, 68.85, 69.05),
                new Product("G", 68.97, 68.85, 69.05),
                new Product("H", 68.98, 68.85, 69.05),
                new Product("I", 68.99, 68.85, 69.05),
                new Product("J", 69.00, 68.85, 69.95),
                new Product("K", 69.10, 68.85, 69.05),
                new Product("L", 68.50, 68.85, 69.95)
            };

            var pricePoints = new List <IDigit>
            {
                new Digit(3),
                new Digit(5),
                new Digit(9)
            };

            IProductProcessor productProcessor = ProductProcessorFactory
                                                 .GetProductProcessor(products, pricePoints);

            productProcessor.Optimiser = new OptimiserCounter();
            productProcessor.Process();

            Assert.AreEqual(68.93, products[0].NewPrice, 0.002, "Product A New Price incorrect");
            Assert.AreEqual("Price increased", products[0].Message, "Product A Message incorrect");

            Assert.AreEqual(71.93, products[1].NewPrice, 0.002, "Product B New Price incorrect");
            Assert.AreEqual("Price increased", products[1].Message, "Product B Message incorrect");

            Assert.AreEqual(69.93, products[2].NewPrice, 0.002, "Product C New Price incorrect");
            Assert.AreEqual("Unable to set price", products[2].Message, "Product C Message incorrect");

            Assert.AreEqual(68.99, products[3].NewPrice, 0.002, "Product D New Price incorrect");
            Assert.AreEqual("Price increased", products[3].Message, "Product D Message incorrect");

            Assert.AreEqual(68.95, products[4].NewPrice, 0.002, "Product E New Price incorrect");
            Assert.AreEqual("Current price is optimal", products[4].Message, "Product E Message incorrect");

            Assert.AreEqual(68.95, products[5].NewPrice, 0.002, "Product F New Price incorrect");
            Assert.AreEqual("Price reduced", products[5].Message, "Product F Message incorrect");

            Assert.AreEqual(68.99, products[6].NewPrice, 0.002, "Product G New Price incorrect");
            Assert.AreEqual("Price increased", products[6].Message, "Product G Message incorrect");

            Assert.AreEqual(68.99, products[7].NewPrice, 0.002, "Product H New Price incorrect");
            Assert.AreEqual("Price increased", products[7].Message, "Product H Message incorrect");

            Assert.AreEqual(68.99, products[8].NewPrice, 0.002, "Product I New Price incorrect");
            Assert.AreEqual("Current price is optimal", products[8].Message, "Product I Message incorrect");

            Assert.AreEqual(68.99, products[9].NewPrice, 0.002, "Product J New Price incorrect");
            Assert.AreEqual("Price reduced", products[9].Message, "Product J Message incorrect");

            Assert.AreEqual(69.05, products[10].NewPrice, 0.002, "Product K New Price incorrect");
            Assert.AreEqual("Price reduced", products[10].Message, "Product K Message incorrect");

            Assert.AreEqual(68.85, products[11].NewPrice, 0.002, "Product L New Price incorrect");
            Assert.AreEqual("Price increased", products[11].Message, "Product L Message incorrect");
        }
예제 #10
0
 public ProductService(IProductProcessor productProccesor)
 {
     this.productProccesor = productProccesor;
 }
 public ProductImporterMiddleware(RequestDelegate next, IProductProcessor productprocessor)
 {
     _next             = next;
     _productProcessor = productprocessor;
 }