示例#1
0
        public void ApplyDiscountForSilverCustomer_ReturnDiscountedPrice(int customerId, double amount, double expectedDiscount)
        {
            double          silverDiscountPercent = 10;
            ICustomer       customer        = new SilverCustomer(customerId, silverDiscountPercent);
            DiscountService discountService = new DiscountService(customer);
            var             result          = discountService.ApplyDiscount(amount);

            Assert.AreEqual(result, expectedDiscount);
        }
示例#2
0
            public void Demo()
            {
                double   d = 0;
                Customer c = new SilverCustomer();

                d = c.GetDiscount(1000);
                c = new GoldCustomer();
                d = c.GetDiscount(1000);
            }
        public void Method()
        {
            // 1. 选中 Customer 执行 Go To Base Symbols
            //    导航到 ICustomer
            Customer customer = GetCustomer();

            // 2. 选中 SilverCustomer 执行 Go To Base Symbols
            //    显示 Customer 和 ICustomer
            //    Customer被加粗是因为他是SilverCustomer的父类.
            var customer2 = new SilverCustomer("id", "Tim");

            // 3. 选中 PercentageDiscount 执行 Go To Base Symbols
            //    显示 Customer.PercentageDiscount 和 ICustomer.PercentageDiscount
            Console.WriteLine(customer2.PercentageDiscount);
        }
        public void Method()
        {
            // 1. Put the caret on Customer and Go To Base Symbols
            //    Navigated to ICustomer
            Customer customer = GetCustomer();

            // 2. Put the caret on SilverCustomer and Go To Base Symbols
            //    Navigated to Customer.
            //    Always navigates one level up the hierarchy, rather than
            //    Go To Derived Symbols, which can navigate many levels down
            var customer2 = new SilverCustomer("id", "Tim");

            // 3. Put the caret on PercentageDiscount and Go To Base Symbols
            //    Navigated to virtual property Customer.PercentageDiscount
            Console.WriteLine(customer2.PercentageDiscount);
        }
示例#5
0
        public void Method()
        {
            // 1. Customer を選択してキャレットを置き、この機能を試してみましょう。
            //    ICustomer に移動できましたか?
            Customer customer = GetCustomer();

            // 2. SilverCustomer を選択してキャレットを置き、この機能を試してみましょう。
            //    Customer に移動できましたか?
            //    ”Go to derived symbols” と異なり、常に1つ上の継承レベルに移動しますが、
            //    何段階も先の階層に移動することもできます。
            //
            var customer2 = new SilverCustomer("id", "Tim");

            // 3. PercentageDiscount を選択してキャレットを置き、この機能を試してみましょう。
            //    基底クラスの仮想プロパティが候補に表示されます。
            //
            Console.WriteLine(customer2.PercentageDiscount);
        }
示例#6
0
        static void Main(string[] args)
        {
            ICustomer         c  = new GoldCustomer();
            IReadableCustomer rc = new GoldCustomer();

            //Interface Seggregation

            /* *
             * ICustomer, IReadableCustomer are different and they are used as and when Required
             * when new demand is there, without modifying instance "c", we can create new instance of "IReadableCustomer" and use it
             * */
            c.Add();

            rc.Add();
            rc.read();


            //DIP
            ICustomer silverCutomer = new SilverCustomer(new ErrorHandler());
        }
        static void Main(string[] args)
        {
            var listRepository =
                new CustomerRepositoryList();
            var newCustomer      = new SilverCustomer();
            var adressRepository = new AdressRepository();


            newCustomer.Id       = 5;
            newCustomer.Name     = "Gilberto";
            newCustomer.Email    = "*****@*****.**";
            newCustomer.Adresses = adressRepository.GetByAdressesById(5);

            listRepository.Save(newCustomer);
            var customers = listRepository.GetAll();


            //foreach(var customer in customers)
            //{
            //    System.Console.WriteLine(customer.Name);
            //}
        }
示例#8
0
        static void Main(string[] args)
        {
            //System.Console.WriteLine("Hello World!");

            ICustomerRepository repository = null;
            var menu = 1;

            System.Console.WriteLine("Introduce 1 si quiere trabajar con RepositoryList\no 2 si quiere trabajar con RepositorySQL");
            menu = int.Parse(System.Console.ReadLine());
            //Con esto podemos trabajar con diferentes respositorios en tiempo de ejecución. Fijemonos cómo utilizamos la
            //interfaz ICustomerRepository para que podamos invocar los métodos y, utilizando el concepto de polimorfismo,
            //se ejecutarán los métodos de un repositorio u otro según el tipo de repositorio escogido por el cliente

            switch (menu)
            {
            case 1: repository = new CustomerRepositoryList();
                break;

            case 2: repository = new CustomerRepositorySQL();
                break;
            }


            var customer1 = new SilverCustomer()
            {
                Id        = 5,
                Name      = "Enrico",
                Addresses = new List <Address>()
                {
                    new Address()
                    {
                        Id         = 1,
                        City       = "Barcelona",
                        Country    = "España",
                        Line1      = "Calle de prueba 111",
                        Line2      = "1-1",
                        PostalCode = "08030",
                        State      = "Cataluña"
                    }
                },
                Email = "*****@*****.**",
                RemainingPurchases = 10
            };
            var customer2 = new SilverCustomer()
            {
                Id        = 6,
                Name      = "Anais",
                Addresses = new List <Address>()
                {
                    new Address()
                    {
                        Id         = 2,
                        City       = "Barcelona",
                        Country    = "España",
                        Line1      = "Avenida de prueba 111",
                        Line2      = "1-1",
                        PostalCode = "08030",
                        State      = "Cataluña"
                    }
                },
                Email = "*****@*****.**",
                RemainingPurchases = 10
            };
            var customer3 = new SilverCustomer()
            {
                Id        = 7,
                Name      = "Angelo",
                Addresses = new List <Address>()
                {
                    new Address()
                    {
                        Id         = 1,
                        City       = "Turin",
                        Country    = "Italia",
                        Line1      = "Via di prova 111",
                        Line2      = "1-1",
                        PostalCode = "08030",
                        State      = "Cataluña"
                    }
                },
                Email = "*****@*****.**",
                RemainingPurchases = 10
            };
            var customer4 = new GoldCustomer()
            {
                Id        = 8,
                Name      = "Arturo",
                Addresses = new List <Address>()
                {
                    new Address()
                    {
                        Id         = 1,
                        City       = "Marxuquera",
                        Country    = "España",
                        Line1      = "Via di prova 111",
                        Line2      = "1-1",
                        PostalCode = "08030",
                        State      = "Cataluña"
                    }
                },
                Email          = "*****@*****.**",
                Discount       = 10,
                DiscountCupons = new List <string>
                {
                    "AHGDI541528nde",
                    "445djKJNDLKGY5"
                }
            };

            repository.Save(customer1);
            repository.Save(customer2);
            repository.Save(customer3);
            repository.Save(customer4);

            var customers = repository.GetAll();

            foreach (var customer in customers)
            {
                string tipoCliente = customer.GetType().ToString();
                tipoCliente = tipoCliente.Replace("TheStore.BL.Models.", "");
                System.Console.WriteLine($"el cliente {customer.Name} con id {customer.Id} es un cliente de tipo {tipoCliente}");
            }
            System.Console.ReadLine();
        }