private static void ConnectionDropedTest() { // INIT TEST var a = new TestTerminal("A", new PhoneNumber("101")); var b = new TestTerminal("B", new PhoneNumber("102")); var c = new TestTerminal("C", new PhoneNumber("103")); var aa = new TestPort("AA"); var bb = new TestPort("BB"); var cc = new TestPort("CC"); var station = new TestStation("AAA", new List<ITerminal> { a, b, c }, new List<IPort> { aa, bb, cc }); // START TEST var t1 = station.GetPreparedTerminal() as TestTerminal; var t2 = station.GetPreparedTerminal() as TestTerminal; var t3 = station.GetPreparedTerminal() as TestTerminal; if (t1 == null || t2 == null || t3 == null) return; t1.Plug(); t2.Plug(); t3.Plug(); Console.WriteLine("\n"); t1.Connect(t2.PhoneNumber); t1.SendMessage("Hi!"); t2.SendMessage("Hallo!"); t3.Connect(t2.PhoneNumber); // port not bind because target port busy t1.SendMessage("How are you?!"); aa.Close(); // close port of t1 close t2.SendMessage("I am ok"); // droped because aa closed Console.WriteLine("\n"); aa.Open(); t3.Connect(t1.PhoneNumber); t1.Unplug(); t3.SendMessage("Hi"); // droped because t1 unpluged }
private static void BillingSystemTest() { // INIT TEST var a = new TestTerminal("A", new PhoneNumber("101")); var b = new TestTerminal("B", new PhoneNumber("102")); var aa = new TestPort("AA"); var bb = new TestPort("BB"); var station = new TestStation("AAA", new List<ITerminal> { a, b }, new List<IPort> { aa, bb }); var billing = new TestBillingSystem(); ITariff tariffFirst = new TestTariff(connectCost: 1000, minCost: 300); ITariff tariffSecond = new TestTariff(connectCost: 0, minCost: 500); var provider = new TestProvider(station, billing); // START TEST var t1 = provider.SignContract(tariffFirst) as TestTerminal; var t2 = provider.SignContract(tariffSecond) as TestTerminal; if (t1 == null || t2 == null) return; t1.Plug(); t2.Plug(); Console.WriteLine("------ FIRST MONTH ------"); Console.WriteLine("--- First call ---"); t1.Connect(t2.PhoneNumber); t2.SendMessage("Ololololol"); t2.Disconnect(); Console.WriteLine(" --- Second call ---"); t2.Unplug(); t1.Connect(t2.PhoneNumber); t2.Plug(); Console.WriteLine(" --- third call ---"); t2.Connect(t1.PhoneNumber); t2.SendMessage("Ololol"); t1.Disconnect(); Console.WriteLine("--- statistic ---"); var calls = provider.GetStatisticForPeriod(t1.PhoneNumber); foreach (var call in calls) Console.WriteLine(call); Console.WriteLine($"Debt of {t1.PhoneNumber} - {provider.GetDebt(t1.PhoneNumber)}"); Console.WriteLine($"Debt of {t2.PhoneNumber} - {provider.GetDebt(t2.PhoneNumber)}"); billing.StartNewPeriod(); Console.WriteLine("------ SECOND MONTH ------"); Console.WriteLine("--- statistic ---"); calls = provider.GetStatisticForPeriod(t1.PhoneNumber); foreach (var call in calls) Console.WriteLine(call); Console.WriteLine($"Debt of {t1.PhoneNumber} - {provider.GetDebt(t1.PhoneNumber)}"); Console.WriteLine($"Debt of {t2.PhoneNumber} - {provider.GetDebt(t2.PhoneNumber)}"); Console.WriteLine($"--- {t1.PhoneNumber} changing tariff ---"); if (provider.TryChangeTariff(t1.PhoneNumber, tariffSecond)) Console.WriteLine("tariff changed successfully"); else Console.WriteLine("tariff not changed"); Console.WriteLine($"--- {t1.PhoneNumber} changing tariff for the second time ---"); if (provider.TryChangeTariff(t1.PhoneNumber, tariffFirst)) Console.WriteLine("tariff changed successfully"); else Console.WriteLine("tariff not changed"); }