// The following method is executed in the Main() method which is located in the TestExecution class
        public static void CallHistoryTest()
        {
            GSM myGSM = new GSM("Galaxy Note III", "Samsung");  // Initialize a new phone

            myGSM.AddCall(DateTime.Now.AddSeconds(8432), "0888123456", 36);         // Stuff it's call history with entries
            myGSM.AddCall(DateTime.Now.AddSeconds(12415), "+359888123456", 511);
            myGSM.AddCall(DateTime.Now.AddSeconds(22425), "0877123456", 14);
            myGSM.AddCall(DateTime.Now.AddSeconds(29434), "+359888123456", 643);
            myGSM.AddCall(DateTime.Now.AddSeconds(42213), "0899123456", 186);
            myGSM.AddCall(DateTime.Now.AddSeconds(52411), "+359888123456", 152);

            myGSM.DisplayCallHistory(); // Display the call history
            Console.WriteLine();
            Console.WriteLine("Price: {0:f2}", myGSM.TotalPrice(.37));  // Display the price for all the entries
            Console.WriteLine();

            myGSM.DeleteCall(FindIndexOfLongestCall(myGSM));    // Remove the entry at the index where the longest call is kept

            myGSM.DisplayCallHistory();
            Console.WriteLine();
            Console.WriteLine("Price: {0:f2}", myGSM.TotalPrice(.37));  // Display the price for the entries that remain
            Console.WriteLine();

            myGSM.ClearHistory();       // Clear the history

            myGSM.DisplayCallHistory();
            Console.WriteLine();
            Console.WriteLine("Price: {0:f2}", myGSM.TotalPrice(.37));
            Console.WriteLine();
        }
Пример #2
0
        public static void Start()
        {
            //Create an instance of the GSM class.
            var myPhone = new GSM("GalaxyS6", "Samsung");

            //Add few calls.
            myPhone.AddCall(new Call(new DateTime(2015, 3, 5, 9, 30, 10), "0883448036", 140));
            myPhone.AddCall(new Call(new DateTime(2015, 3, 4, 10, 12, 53), "0883428135", 230));
            myPhone.AddCall(new Call(new DateTime(2015, 3, 12, 19, 3, 32), "0883451438", 423));

            //Print call information
            myPhone.PrintCallHistory();
            Console.WriteLine();

            //Print the total price of the calls in the history for 0.37 per minute
            Console.WriteLine("Total calls price: ${0:0.##}", myPhone.GetCallsTotalPrise(0.37M));

            //Remove the longest call from the history and calculate the total price again
            var longestCall = myPhone.CallHistory.OrderByDescending(x => x.Duration).First();
            myPhone.DeleteCall(longestCall);
            Console.WriteLine("Longest call removed!");
            Console.WriteLine("Total calls price: ${0:0.##}", myPhone.GetCallsTotalPrise(0.37M));
            Console.WriteLine();
            myPhone.PrintCallHistory();

            //Finally clear the call history and print it.
            myPhone.ClearHistory();
            Console.WriteLine("History cleared!");
            myPhone.PrintCallHistory();
        }
        public void CallHistoryTest()
        {
            phone.AddCall(call1);
            phone.AddCall(call2);
            phone.AddCall(call3);

            foreach (var call in phone.CallHistory)
            {
                Console.WriteLine(call);
            }
            Console.WriteLine();

            Console.WriteLine("Total price of calls: {0:0.00}", phone.CalculatePrice(0.37m)); Console.WriteLine();

            phone.RemoveCall(2);
            Console.WriteLine("Total price without longest call: {0:0.00}", phone.CalculatePrice(0.37m)); Console.WriteLine();

            phone.ClearHistory();
            foreach (var call in phone.CallHistory)
            {
                Console.WriteLine(call);
            }
        }