public void IsInstanceOfType()
        {
            GoldCustomer c1 = new GoldCustomer()
            {
                FirstName = "Abhilash"
            };

            Assert.IsInstanceOfType(c1, typeof(GoldCustomer));
        }
Пример #2
0
        public void ApplyDiscountForGoldCustomer_ReturnDiscountedPrice(int customerId, double amount, double expectedDiscount)
        {
            double          goldDiscountPercent = 30;
            ICustomer       customer            = new GoldCustomer(customerId, goldDiscountPercent);
            DiscountService discountService     = new DiscountService(customer);
            var             result = discountService.ApplyDiscount(amount);

            Assert.AreEqual(result, expectedDiscount);
        }
Пример #3
0
        public void Constructor_Pass_WhilePassingValidParams()
        {
            //Arrange
            var mockLogger     = new Mock <SolidDemo.DIP.Logger.ILogger>();
            var mockValidation = new Mock <IValidation>();

            //Act & Assert
            _ = new GoldCustomer(mockLogger.Object, mockValidation.Object);
        }
Пример #4
0
            public void Demo()
            {
                double   d = 0;
                Customer c = new SilverCustomer();

                d = c.GetDiscount(1000);
                c = new GoldCustomer();
                d = c.GetDiscount(1000);
            }
Пример #5
0
        public void CalculateDiscount_Throws_Exception_WhilePassingInvaidAmount()
        {
            //Arrange
            var mockLogger     = new Mock <SolidDemo.DIP.Logger.ILogger>();
            var mockValidation = new Mock <IValidation>();
            var customer       = new GoldCustomer(mockLogger.Object, mockValidation.Object);

            //Act&&Assert
            Assert.ThrowsException <ArgumentException>(() => customer.CalculateDiscount(0));
        }
Пример #6
0
        public void CalculateDiscount_Pass_WhilePassingVaidAmount()
        {
            //Arrange
            var mockLogger     = new Mock <SolidDemo.DIP.Logger.ILogger>();
            var mockValidation = new Mock <IValidation>();
            var customer       = new GoldCustomer(mockLogger.Object, mockValidation.Object);
            var amount         = 1000.00M;
            var expectedAmount = 800.00M;

            //Act
            var actualDiscountAmount = customer.CalculateDiscount(amount);

            //Assert
            Assert.AreEqual(expectedAmount, actualDiscountAmount);
        }
Пример #7
0
        private static void Casting(GoldCustomer goldCustomer)
        {
            // Upcasting
            Customer customer    = goldCustomer;
            object   upCasting   = goldCustomer;
            var      downCasting = upCasting as GoldCustomer;

            if (downCasting == null)
            {
                Console.WriteLine("There's no such thing like this.");
            }
            else
            {
                Console.WriteLine("You're right!");
            }
        }
Пример #8
0
        public void Add_Pass_WhilePassingValidParams()
        {
            //Arrange
            var mockLogger     = new Mock <SolidDemo.DIP.Logger.ILogger>();
            var mockValidation = new Mock <IValidation>();

            mockValidation.Setup(x => x.Validate(It.IsAny <string>())).Verifiable();
            var customer = new GoldCustomer(mockLogger.Object, mockValidation.Object);

            //Act
            customer.Add("Name");

            //Assert
            mockValidation.Verify(x => x.Validate(It.IsAny <string>()), Times.Exactly(1));
            mockLogger.Verify(x => x.Log(It.IsAny <string>()), Times.Never);
        }
Пример #9
0
        public void Add_Throws_Exception_WhilePassingNullParams()
        {
            //Arrange
            var mockLogger     = new Mock <SolidDemo.DIP.Logger.ILogger>();
            var mockValidation = new Mock <IValidation>();

            mockValidation.Setup(x => x.Validate(It.IsAny <string>()))
            .Callback(() => throw new ArgumentNullException());
            var customer = new GoldCustomer(mockLogger.Object, mockValidation.Object);

            //Act
            customer.Add(null);

            //Assert
            mockValidation.Verify(x => x.Validate(It.IsAny <string>()), Times.Exactly(1));
            mockLogger.Verify(x => x.Log(It.IsAny <string>()), Times.Exactly(1));
        }
Пример #10
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());
        }
Пример #11
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();
        }