Ejemplo n.º 1
0
        public void WhenNoDiscountApplied_AmountHasNotChanged()
        {
            var noDiscount = new NoDiscount(0);

            Assert.Equal(0, noDiscount.Amount);
            Assert.Equal(0, noDiscount.Priority);
            Assert.True(noDiscount.CanApply());
        }
Ejemplo n.º 2
0
        private IFinalPrice UseNoDiscount(IFinalPrice cart, ref string view)
        {
            var noDiscount = new NoDiscount(cart);

            noDiscount.CalculatePriceWithoutDiscount();
            view += "Price without any discount  : $" + cart.GetFinalPrice() + " \n";

            return(noDiscount.AdjustedCart);
        }
        public double Calculate(Budget budget)
        {
            IDiscount d1 = new DiscountForUpToFiveItems();
            IDiscount d2 = new DiscountForOverFiveHundredItems();
            IDiscount d3 = new NoDiscount();

            d1.Next = d2;
            d2.Next = d3;

            return(d1.Discount(budget));
        }
Ejemplo n.º 4
0
        public double Calculate(IBudget budget)
        {
            IDiscount d1 = new DiscountForFiveItems();
            IDiscount d2 = new DiscountForAValueGreaterThan500();
            IDiscount d3 = new NoDiscount();

            d1.Next = d2;
            d2.Next = d3;

            return(d1.Discount(budget));
        }
Ejemplo n.º 5
0
        public void NoDiscount_Should_ReturnStandartPrice()
        {
            // Arrange
            var noDiscount = new NoDiscount();

            var license1 = new TwoDaysMovieLicense("Movie Name 1", DateTime.UtcNow, noDiscount);
            var license2 = new LongTermMovieLicense("Movie Name 2", DateTime.UtcNow, noDiscount);

            // Act - Assert
            license1.GetPrice().Should().Be(4);
            license2.GetPrice().Should().Be(8);
        }
        public void BasketTotalNoDiscount()
        {
            //Arrange
            Product p1 = new Product("p1", 100, 100);
            Product p2 = new Product("p2", 200, 100);

            Basket.AddOrderProduct(new BasketProduct(p1, 1));
            Basket.AddOrderProduct(new BasketProduct(p2, 1));
            //Act
            DiscountBase discountStrategy = new NoDiscount();
            double       discountedPrice  = Basket.calcDiscountedTotal(discountStrategy);

            //Assert
            discountedPrice.Should().Be(300);
        }
Ejemplo n.º 7
0
        public List <ProductDetail> GetProductDetails(List <Cart> cartItems, List <Product> products)
        {
            var productDetails = new List <ProductDetail>();

            foreach (var item in cartItems)
            {
                if (products.Any(x => x.Name == item.Product))
                {
                    var product       = products.First(x => x.Name == item.Product);
                    var productDetail = new ProductDetail();
                    productDetail.Product  = item.Product;
                    productDetail.Quantity = item.Quantity;
                    productDetail.Price    = product.Price;


                    //ProcessDiscountLogic
                    IDiscount discount = new NoDiscount();
                    switch (product.DiscountType)
                    {
                    case "DiscountA":
                        discount = new DiscountA();
                        break;

                    case "DiscountB":
                        discount = new DiscountB();
                        break;

                    case "DiscountCD":
                        discount = new DiscountCD();
                        break;

                    default:
                        break;
                    }

                    productDetail.Price = discount.ApplyDiscount(productDetail);

                    productDetails.Add(productDetail);
                }
            }
            return(productDetails);
        }
Ejemplo n.º 8
0
        public static void Main()
        {
            Signature.Sign("Bridge Pattern", "Author: Piotr Stefaniak", "Based on Pluralsight course");
            Console.WriteLine();

            var now        = DateTime.Now;
            var noDiscount = new NoDiscount();

            Console.WriteLine("Creating TwoDaysMovieLicense with NoDiscount");
            var twoDaysMovieLicenseNoDiscount = new TwoDaysMovieLicense("Frozen", now, noDiscount);

            PrintLicenseDetails(twoDaysMovieLicenseNoDiscount);

            Console.WriteLine("Creating YearMovieLicense with NoDiscount");
            var yearMovieLicenseNoDiscount = new YearMovieLicense("Matrix", now, noDiscount);

            PrintLicenseDetails(yearMovieLicenseNoDiscount);

            var seniorDiscount   = new SeniorDiscount();
            var militaryDiscount = new MilitaryDiscount();

            Console.WriteLine("Creating TwoDaysMovieLicense with SeniorDiscount");
            var twoDaysMovieLicenseSeniorDiscount = new TwoDaysMovieLicense("Frozen", now, seniorDiscount);

            PrintLicenseDetails(twoDaysMovieLicenseSeniorDiscount);

            Console.WriteLine("Creating YearMovieLicense with MilitaryDiscount");
            var yearMovieLicenseMilitaryDiscount = new YearMovieLicense("Matrix", now, militaryDiscount);

            PrintLicenseDetails(yearMovieLicenseMilitaryDiscount);

            Console.WriteLine("Thanks to Bridge pattern both MovieLicense and Discount entities can exist independently.");
            Console.WriteLine();

            Console.WriteLine("Bridge pattern allow us to split a class hierarchy");
            Console.WriteLine("through composition to reduce coupling.");
        }