Exemplo n.º 1
0
        public static ProductB CreateProductB(double price)
        {
            ProductB productB = new ProductB();

            productB.Price = price;
            return(productB);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please, input the annual electric consumption.");
            string strConsumptionPerYear = Console.ReadLine();

            int.TryParse(strConsumptionPerYear, out var consuptionPerYear);

            ITariffCalculator productA = new ProductA();
            ITariffCalculator productB = new ProductB();

            TariffCalculateService service = new TariffCalculateService(productA, productB);
            var list = service.GetList(consuptionPerYear);

            Console.WriteLine("------------------------------------------------------------");
            Console.WriteLine("See the two products sorted by annual tariff.");
            int count = 0;

            list.ForEach(x =>
            {
                count += 1;
                Console.WriteLine($"{count} - {x.Title}: {x.AnnualTariff} euros");
            });

            Console.ReadKey();
        }
Exemplo n.º 3
0
        public static Product GetInstance(eProduct productType)
        {
            Product p = null;

            switch (productType)
            {
            case eProduct.A:
            {
                p = new ProductA();
            }
            break;

            case eProduct.B:
            {
                p = new ProductB();
            }
            break;

            case eProduct.C:
            {
                p = new ProductC();
            }
            break;

            default:
            {
                p = new Product();
            }
            break;
            }

            return(p);
        }
Exemplo n.º 4
0
 public static void Main()
 {
     var      factoryA = new Factory <ProductA>(ProductA.InitializeProduct);
     var      factoryB = new Factory <ProductB>(ProductB.InitializeProduct);
     ProductA prodA    = factoryA.CreateProduct();
     ProductB prodB    = factoryB.CreateProduct();
 }
Exemplo n.º 5
0
        public void GetTotalAnnualCosts_ProductB_Consumption3500()
        {
            ProductB productB    = new ProductB();
            decimal  consumption = 3500;

            Assert.AreEqual(800M, productB.GetTotalAnnualCosts(consumption));
        }
Exemplo n.º 6
0
    public IProduct MakeProduct(Condition condition)
    {
        IProduct product;

        switch (condition)
        {
        case Condition.CaseA:
            product = new ProductA();
            // Other product setup code
            break;

        case Condition.CaseA2:
            product = new ProductA();
            // Yet other product setup code
            break;

        case Condition.CaseB:
            product = new ProductB();
            // Other product setup code
            break;

        default:
            throw new Exception(string.Format("Condition {0} ...", condition));
        }
        return(product);
    }
Exemplo n.º 7
0
        public void GetVariableAnnualCost_ProductB_Consumption4500()
        {
            ProductB productB    = new ProductB();
            decimal  consumption = 4500;

            Assert.AreEqual(150, productB.GetVariableAnnualCost(consumption));
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            #region Static Factory Method Pattern
            // use static method
            ILogger_static_factory logger_static_factory = LoggerFactory_static_factory.Create(LoggerType.DB);

            #endregion

            #region Simple Factory Pattern
            // no using static method
            var factory_simple  = new LoggerFactory_simple_factory();
            var dbLogger_simple = factory_simple.CreateDbLogger();

            #endregion

            #region Factory Method Pattern

            LogFactory logger = new XmlLogFactory();
            logger.Log("Log something");

            LogFactory logger_s = LogFactory.GetLogger();
            logger_s.Log("Log somethinf");

            #endregion


            #region Abstract Factory Patthern

            AbstractFactory factory = new ConcreteFactory1();
            ProductA        prodA   = factory.CreateProductA();
            ProductB        prodB   = factory.CreateProductB();

            #endregion
        }
        public void Test_CalculationModelB(int consumption, int result)
        {
            ProductB pr = new ProductB();
            var      resultingConsumption = pr.CalculationModel(consumption);

            Assert.AreEqual(result, resultingConsumption);
        }
Exemplo n.º 10
0
    public override Product Create()
    {
        var a = new ProductB();

        Console.WriteLine("Created Product A");
        return(a);
    }
Exemplo n.º 11
0
        public bool UpdateProduct(ProductB product)
        {
            var updated = true;

            using (var NWEntities = new SaveWorldEntities())
            {
                var productId       = product.ProductId;
                var productDatabase =
                    (from p
                     in NWEntities.Products
                     where p.id == productId
                     select p).FirstOrDefault();

                if (productDatabase == null)
                {
                    throw new Exception("No product with ID " + product.ProductId);
                }
                productDatabase.productName = product.ProductName;
                productDatabase.price       = product.Price;
                productDatabase.description = product.ProductDescription;
                productDatabase.minStock    = product.Stock;


                NWEntities.Products.Attach(productDatabase);

                NWEntities.Entry(productDatabase).State = System.Data.Entity.EntityState.Modified;

                var num = NWEntities.SaveChanges();
            }
            return(updated);
        }
Exemplo n.º 12
0
        public void ChildrenAndInheritance()
        {
            var datacontext = new Configuration(Constants.Connectionstring).WithDocuments(typeof(Order), typeof(ProductA), typeof(ProductB)).Create();

            datacontext.EnsureNewDatabase();

            var order = new Order()
            {
                Id = Guid.NewGuid()
            };

            datacontext.Insert(order);

            var p1 = new ProductA {
                Id = Guid.NewGuid(), Text = "abc", ValueA = "va"
            };

            datacontext.Insert(p1);
            var p2 = new ProductB {
                Id = Guid.NewGuid(), Text = "abc", ValueB = "vb"
            };

            datacontext.Insert(p2);

            datacontext.AppendChild(order, p1);
            datacontext.AppendChild(order, p2);

            var children = datacontext.GetChildren <Order, IProduct>(order);

            Assert.AreEqual(2, children.Count);
            var children2 = datacontext.GetChildren <Order, Product>(order);

            Assert.AreEqual(2, children2.Count);
        }
Exemplo n.º 13
0
    public ProductBase Create()
    {
        ProductB p = new ProductB();

        populate(p);
        p.a = some_a;
        return(p);
    }
Exemplo n.º 14
0
    public override IProduct FactoryMethod()
    {
        Debug.Log("生产产品B");
        ProductB productB = new ProductB();

        //TODO...
        return(productB);
    }
Exemplo n.º 15
0
        public void ProductBBuilderTest()
        {
            ProductBBuilder builder = new ProductBBuilder();

            new Director(builder).Action();
            ProductB product = builder.GetProduct();

            AssertProduct(product, typeof(ProductB));
        }
Exemplo n.º 16
0
        private static int GetTotalPrice(List <Product> products)
        {
            var finalPrice = 0;

            finalPrice += new ProductA <List <Product> >(products.Where(x => x.Id == "A").ToList()).CalculateProductPrice();
            finalPrice += new ProductB <List <Product> >(products.Where(x => x.Id == "B").ToList()).CalculateProductPrice();
            finalPrice += new ProductCnD <List <Product> >(products.Where(x => x.Id == "C" || x.Id == "D").ToList()).CalculateProductPrice();
            return(finalPrice);
        }
Exemplo n.º 17
0
        private TariffModel InitializeTariffModel()
        {
            TariffModel model    = new TariffModel();
            ProductA    productA = new ProductA(productA_Name);
            ProductB    productB = new ProductB(productB_Name);

            model.AddProduct(productA);
            model.AddProduct(productB);
            return(model);
        }
Exemplo n.º 18
0
        public void CacheGetByNameTest_IfNothingFound()
        {
            var productA = new ProductA("test productA", 22, 5);
            var productB = new ProductB("test productB", 30, 4000, 800);

            _sut.InsertProduct(productA);
            _sut.InsertProduct(productB);
            var item = _sut.GetProductByName("test productC");

            Assert.Null(item);
        }
Exemplo n.º 19
0
        public void CacheInsertTest()
        {
            var productA = new ProductA("test productA", 22, 5);
            var productB = new ProductB("test productB", 30, 4000, 800);

            _sut.InsertProduct(productA);
            _sut.InsertProduct(productB);
            var items = _sut.GetAllProducts();

            Assert.Equal(2, items.Length);
        }
Exemplo n.º 20
0
        public void CreatingAProduct()
        {
            ProductCtrB productCtr = new ProductCtrB();
            ProductB    prod       = new ProductB();

            prod.ProductName        = "umbrella";
            prod.ProductDescription = "a very nice umbrella";
            prod.Stock = 10;
            prod.Price = 10.35M;
            Assert.IsNotNull(productCtr.CreateProduct(prod));
        }
Exemplo n.º 21
0
        public void ProductBTestTotalPrice_Returns_Zero_OnNoProduct()
        {
            //Arrange
            List <Product> products = new List <Product>();

            //Assert
            var value = new ProductB <List <Product> >(products).CalculateProductPrice();

            //Act
            value.Equals(0);
        }
Exemplo n.º 22
0
        public void ProductBTestTotalPrice_Returns_Promotion_Price()
        {
            //Arrange
            List <Product> products = new List <Product>();

            products.Add(new Product("B", 2));
            //Assert
            var value = new ProductB <List <Product> >(products).CalculateProductPrice();

            //Act
            value.Equals(45);
        }
Exemplo n.º 23
0
        public void Setup()
        {
            _pointOfSale = new POS();
            _terminal    = new Terminal(_pointOfSale);

            var productA = new ProductA();
            var productB = new ProductB();
            var productC = new ProductC();
            var productD = new ProductD();

            List <Product> products = new List <Product> {
                productA, productB, productC, productD
            };

            foreach (var product in products)
            {
                Utils.DoSafe(() =>
                {
                    _pointOfSale.AddProduct(product);
                });
            }

            Utils.DoSafe(() =>
            {
                _terminal.SetPricing(productA.Code, (decimal)1.25d);
            });

            Utils.DoSafe(() =>
            {
                _terminal.SetPricing(productA.Code, (decimal)3.00d, 3);
            });

            Utils.DoSafe(() =>
            {
                _terminal.SetPricing(productB.Code, (decimal)4.25d);
            });

            Utils.DoSafe(() =>
            {
                _terminal.SetPricing(productC.Code, (decimal)1.00d);
            });

            Utils.DoSafe(() =>
            {
                _terminal.SetPricing(productC.Code, (decimal)5.00d, 6);
            });

            Utils.DoSafe(() =>
            {
                _terminal.SetPricing(productD.Code, (decimal)0.75d);
            });
        }
Exemplo n.º 24
0
        static List <TariffProduct> Comparison(int consumption)
        {
            List <TariffProduct> comparisonList = new List <TariffProduct>();

            Product productA = new ProductA();
            Product productB = new ProductB();

            TariffProduct tariffProductA = new TariffProduct(productA, consumption);
            TariffProduct tariffProductB = new TariffProduct(productB, consumption);

            comparisonList.Add(tariffProductA);
            comparisonList.Add(tariffProductB);

            return(comparisonList.OrderBy(item => item.AnnualCost).ToList());
        }
Exemplo n.º 25
0
        public void TestPointOfSale_InitialiseWithProductList()
        {
            var productA = new ProductA();
            var productB = new ProductB();
            var productC = new ProductC();
            var productD = new ProductD();

            List <Product> products = new List <Product> {
                productA, productB, productC, productD
            };

            Assert.DoesNotThrow(() => {
                var pointOfSale = new POS(products);

                Assert.IsNotEmpty(products);
                Assert.AreEqual(products, pointOfSale.Products);
            });
        }
Exemplo n.º 26
0
        private static void Init()
        {
            var productA = new ProductA();
            var productB = new ProductB();
            var productC = new ProductC();
            var productD = new ProductD();

            List <Product> products = new List <Product> {
                productA, productB, productC, productD
            };

            PointOfSale = new POS(products);
            Terminal    = new Terminal(PointOfSale);

            Utils.DoSafe(() =>
            {
                Terminal.SetPricing(productA.Code, (decimal)1.25d);
            });

            Utils.DoSafe(() =>
            {
                Terminal.SetPricing(productA.Code, (decimal)3.00d, 3);
            });

            Utils.DoSafe(() =>
            {
                Terminal.SetPricing(productB.Code, (decimal)4.25d);
            });

            Utils.DoSafe(() =>
            {
                Terminal.SetPricing(productC.Code, (decimal)1.00d);
            });

            Utils.DoSafe(() =>
            {
                Terminal.SetPricing(productC.Code, (decimal)5.00d, 6);
            });

            Utils.DoSafe(() =>
            {
                Terminal.SetPricing(productD.Code, (decimal)0.75d);
            });
        }
Exemplo n.º 27
0
        public ProductB GetProductByName(string name)
        {
            ProductB prod = null;

            try
            {
                prod = prodCtr.GetProductByName(name);
            }
            catch
            {
                var reason = "GetUser Exception";
                throw new FaultException(reason);
            }

            if (prod == null)
            {
                var reason = "GetUser empty user";
                throw new FaultException(reason);
            }

            return(prod);
        }
Exemplo n.º 28
0
        public List <ProductB> GetAllProduct()
        {
            // var db = new SaveWorldEntities();
            //return db.Products.ToList();
            List <ProductB> list = new List <ProductB>();

            using (SaveWorldEntities NWEntities = new SaveWorldEntities())
            {
                var ptx     = (from r in NWEntities.Products select r);
                var allRows = NWEntities.Products.ToList();

                for (int i = 0; i < allRows.Count; i++)
                {
                    ProductB pro = new ProductB();
                    pro.ProductName        = allRows[i].productName;
                    pro.ProductId          = allRows[i].id;
                    pro.ProductDescription = allRows[i].description;
                    pro.Price = allRows[i].price;
                    list.Add(pro);
                }
            }
            return(list);
        }
Exemplo n.º 29
0
        public void TestPointOfSale_AddProducts()
        {
            var productA = new ProductA();
            var productB = new ProductB();
            var productC = new ProductC();
            var productD = new ProductD();

            List <Product> products = new List <Product> {
                productA, productB, productC, productD
            };

            var pointOfSale = new POS();

            Assert.DoesNotThrow(() => {
                foreach (var product in products)
                {
                    pointOfSale.AddProduct(product);
                }

                Assert.IsNotEmpty(products);
                Assert.AreEqual(products, pointOfSale.Products);
            });
        }
Exemplo n.º 30
0
        public void Setup()
        {
            _pointOfSale = new POS();
            _terminal    = new Terminal(_pointOfSale);

            var productA = new ProductA();
            var productB = new ProductB();
            var productC = new ProductC();
            var productD = new ProductD();

            List <Product> products = new List <Product> {
                productA, productB, productC, productD
            };


            foreach (var product in products)
            {
                Utils.DoSafe(() =>
                {
                    _pointOfSale.AddProduct(product);
                });
            }
        }