Example #1
0
        static void Main(string[] args)
        {
            // Create movies
            Movie movCinderella = new Movie("Cinderella", PriceCodes.Childrens);
            Movie movStarWars   = new Movie("Star Wars", PriceCodes.Regular);
            Movie movGladiator  = new Movie("Gladiator", PriceCodes.NewRelease);

            // Create customers
            Customer custMickeyMouse = new Customer("Mickey Mouse");
            Customer custDonaldDuck  = new Customer("Donald Duck");
            Customer custMinnieMouse = new Customer("Minnie Mouse");

            // Create rentals
            Rental rental1 = new Rental(movCinderella, 5);
            Rental rental2 = new Rental(movStarWars, 5);
            Rental rental3 = new Rental(movGladiator, 5);

            // Assign rentals to customers
            custMickeyMouse.AddRental(rental1);
            custMickeyMouse.AddRental(rental2);
            custMickeyMouse.AddRental(rental3);

            // Generate invoice
            string statement = custMickeyMouse.Statement();

            // Print the statement
            Console.WriteLine(statement);
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            // Create movies
            Movie movCinderella = new Movie("Cinderella", PriceCodes.Childrens);
            Movie movStarWars = new Movie("Star Wars", PriceCodes.Regular);
            Movie movGladiator = new Movie("Gladiator", PriceCodes.NewRelease);

            // Create customers
            Customer custMickeyMouse = new Customer("Mickey Mouse");
            Customer custDonaldDuck = new Customer("Donald Duck");
            Customer custMinnieMouse = new Customer("Minnie Mouse");

            // Create rentals
            Rental rental1 = new Rental(movCinderella, 5);
            Rental rental2 = new Rental(movStarWars, 5);
            Rental rental3 = new Rental(movGladiator, 5);

            // Assign rentals to customers
            custMickeyMouse.AddRental(rental1);
            custMickeyMouse.AddRental(rental2);
            custMickeyMouse.AddRental(rental3);

            // Generate invoice
            string statement = custMickeyMouse.Statement();

            // Print the statement
            Console.WriteLine(statement);
            Console.ReadLine();
        }
Example #3
0
        public void TestCustomer()
        {
            // Test Name property
            Assert.AreEqual("Mickey Mouse", m_MickeyMouse.Name);
            Assert.AreEqual("Donald Duck", m_DonaldDuck.Name);
            Assert.AreEqual("Minnie Mouse", m_MinnieMouse.Name);

            // Test AddRental() method - set up for test
            m_MickeyMouse.AddRental(m_Rental1);
            m_MickeyMouse.AddRental(m_Rental2);
            m_MickeyMouse.AddRental(m_Rental3);

            /* At this point, the structure of the program begins getting in the
             * way of testing. Rentals are imbedded in the Customer object, but
             * there is no property to access them. They can only be accessed
             * internally, by the Statement() method, which imbeds them in the
             * text string passed as it's return value. So, to get these amounts,
             * we will have to parse that value. */

            // Test the Statement() method
            string theResult = m_MickeyMouse.Statement();

            // Parse the result
            char[]   delimiters = "\n\t".ToCharArray();
            string[] results    = theResult.Split(delimiters);

            /* The results[] array will have the following elements:
             *		[0] = junk
             *		[1] = junk
             *		[2] = title #1
             *		[3] = price #1
             *		[4] = junk
             *		[5] = title #2
             *		[6] = price #2
             *		[7] = junk
             *		[8] = title #3
             *		[9] = price #3
             *		[10] = "Amount owed is x"
             *		[11] = "You earned x frequent renter points."
             * We will test the title and price elements, and the total
             * and frequent renter points items. If these tests pass, then
             * we know that AddRentals() is adding rentals to a Customer
             * object properly, and that the Statement() method is
             * generating a statement in the expected format. */

            // Test the title and price items
            Assert.AreEqual("Cinderella", results[2]);
            Assert.AreEqual(3, Convert.ToDouble(results[3]));
            Assert.AreEqual("Star Wars", results[5]);
            Assert.AreEqual(6.5, Convert.ToDouble(results[6]));
            Assert.AreEqual("Gladiator", results[8]);
            Assert.AreEqual(15, Convert.ToDouble(results[9]));
        }