Exemplo n.º 1
0
        public void SeniorDiscount_Should_ReturnPriceWithDiscount()
        {
            // Arrange
            var seniorDiscount = new SeniorDiscount();

            var twoDaysLicense  = new TwoDaysMovieLicense("Movie Name 1", DateTime.UtcNow, seniorDiscount);
            var longTernLicense = new LongTermMovieLicense("Movie Name 2", DateTime.UtcNow, seniorDiscount);

            // Act - Assert
            twoDaysLicense.GetPrice().Should().Be(4 * 0.8m);
            longTernLicense.GetPrice().Should().Be(8 * 0.8m);
        }
Exemplo n.º 2
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.");
        }