public static void CallHistoryTestPrint() { var myPhone = new Gsm( "THL", "China", "Niki", 200.5M, new Battery(BatteryType.Li_Ion, 60, 20), new Display(5.5M, 16000000)); Console.WriteLine(myPhone); myPhone.AddCall(DateTime.Now, 0885998877, 65); myPhone.AddCall(DateTime.UtcNow, 0885665544, 98); myPhone.AddCall(DateTime.Now, 0885552277, 158); myPhone.AddCall(DateTime.Now, 0885996857, 112); myPhone.AddCall(DateTime.Now, 0885995827, 87); Console.WriteLine(myPhone.CallHistory); var priceInfo = new StringBuilder(); priceInfo.AppendFormat("Total price: {0:C2}", myPhone.CallPrice()); myPhone.RemoveLongestCall(); priceInfo.AppendFormat(Environment.NewLine); priceInfo.AppendFormat("Longest Call removed"); priceInfo.AppendFormat(Environment.NewLine); priceInfo.AppendFormat("Total price: {0:C2}", myPhone.CallPrice()); myPhone.ClearCallHistory(); Console.WriteLine(priceInfo); Console.WriteLine(myPhone.CallHistory); }
public static void RunTests() { try { // create an instance of the Gsm class Gsm mobilePhone = new Gsm( MobilePhoneManufacturer.BlackBerry, new Battery(BatteryType.LiIon, null, 432, 0, 7, 0), new Display(320, 240, 2.44, ColorDepth.Colors65K), "BlackBerry Curve 9320", 170, "Julia Roberts"); // add a few calls mobilePhone.AddCallToHistory(2012, 8, 28, 13, 5, "00359 888 967584", 129); mobilePhone.AddCallToHistory(2012, 10, 15, 9, 34, "00359 878 900581", 907); mobilePhone.AddCallToHistory(2012, 12, 9, 2, 15, "00359 882 123456", 457); mobilePhone.AddCallToHistory(2013, 1, 7, 1, 57, "00359 883 969956", 307); mobilePhone.AddCallToHistory(2013, 2, 5, 10, 27, "00359 879 967584", 456); mobilePhone.AddCallToHistory(2013, 2, 12, 15, 45, "00359 885 962387", 812); // display call history Console.WriteLine("Call history:\n{0}", mobilePhone.GetCallHistory()); // calculate total call price (given the price per minute) decimal totalCallPrice = mobilePhone.CalculateTotalCallPrice(0.37M); Console.WriteLine("Total call price: {0:N2}", totalCallPrice); // delete the longest call from history int callsRemoved = mobilePhone.DeleteLongestCallFromHistory(); Console.WriteLine("{0} call(s) removed.", callsRemoved); // calculate total call price after deleting the longest call totalCallPrice = mobilePhone.CalculateTotalCallPrice(0.37M); Console.WriteLine("Total call price: {0:N2}", totalCallPrice); // clear call history mobilePhone.ClearCallHistory(); // print the call history Console.WriteLine("Call history:\n{0}", mobilePhone.GetCallHistory()); } catch (MobilePhoneException mpex) { Console.WriteLine(mpex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void TestClearHistory() { // create an instance of the Gsm class Gsm mobilePhone = new Gsm( MobilePhoneManufacturer.BlackBerry, new Battery(BatteryType.LiIon, null, 432, 0, 7, 0), new Display(320, 240, 2.44, ColorDepth.Colors65K), "BlackBerry Curve 9320", 170, "Julia Roberts"); // add a few calls mobilePhone.AddCallToHistory(2012, 8, 28, 13, 5, "00359 888 967584", 129); mobilePhone.AddCallToHistory(2012, 10, 15, 9, 34, "00359 878 900581", 907); mobilePhone.AddCallToHistory(2012, 12, 9, 2, 15, "00359 882 123456", 457); mobilePhone.AddCallToHistory(2013, 1, 7, 1, 57, "00359 883 969956", 307); mobilePhone.AddCallToHistory(2013, 2, 5, 10, 27, "00359 879 967584", 456); mobilePhone.AddCallToHistory(2013, 2, 12, 15, 45, "00359 885 962387", 812); // clear call history mobilePhone.ClearCallHistory(); Assert.AreEqual(String.Empty, mobilePhone.GetCallHistory()); }