using System; using System.IO; namespace BlockBuster { class Class1 { private static void ReportError(Customer c, string expectedResult) { Console.WriteLine("*** ERROR with " + c.Name + " *** Expected result was:\n" + expectedResult + "\n" + "Got result:\n" + c.Statement); } [STAThread] static void Main(string[] args) { // ----- create some movies Movie terminator = new Movie("Terminator", MoviePriceCode.Regular); Movie terminator2 = new Movie("Terminator II", MoviePriceCode.Regular); Movie matrix = new Movie("Matrix", MoviePriceCode.Regular); Movie matrixReload = new Movie("Matrix - Reload", MoviePriceCode.NewRelease); Movie lotr1 = new Movie("LOTR - The Fellowship of the Ring", MoviePriceCode.Regular); Movie lotr2 = new Movie("LOTR - The Two Towers", MoviePriceCode.NewRelease); Movie bugsBunny = new Movie("Bugs Bunny", MoviePriceCode.Childrens); Movie tomAndJerry = new Movie("Tom & Jerry", MoviePriceCode.Childrens); // ----- create some customers with their rentals and compare the results with // the expected results fetched from text files int errors = 0; Customer johnDoe = new Customer("John Doe"); johnDoe.AddRental(new Rental(terminator, 1)); johnDoe.AddRental(new Rental(matrixReload, 1)); johnDoe.AddRental(new Rental(bugsBunny, 1)); StreamReader sr = File.OpenText("JohnDoe.txt"); string johnDoeStatement = sr.ReadToEnd(); sr.Close(); if(johnDoeStatement != johnDoe.Statement) { ReportError(johnDoe, johnDoeStatement); errors++; } Customer arnie = new Customer("Arnie S."); arnie.AddRental(new Rental(terminator, 10)); arnie.AddRental(new Rental(terminator2, 10)); arnie.AddRental(new Rental(matrix, 5)); arnie.AddRental(new Rental(matrixReload, 5)); sr = File.OpenText("ArnieS.txt"); string arnieStatement = sr.ReadToEnd(); sr.Close(); if(arnieStatement != arnie.Statement) { ReportError(arnie, arnieStatement); errors++; } Customer mary = new Customer("Mrs. Mary"); mary.AddRental(new Rental(bugsBunny, 3)); mary.AddRental(new Rental(tomAndJerry, 7)); sr = File.OpenText("Mary.txt"); string maryStatement = sr.ReadToEnd(); sr.Close(); if(maryStatement != mary.Statement) { ReportError(mary, maryStatement); errors++; } Console.WriteLine("Tests ended with " + errors + " errors."); } } }