public void TestATS() { Station station = new Station(10); List <ITerminal> terminals = new List <ITerminal>(); for (int i = 0; i < 30; i++) { ITerminal terminal = new Terminal(i); terminal.Plug(); terminals.Add(terminal); station.AddTerminal(GenerateNumber(i), terminal); } Random r = new Random(); int j = 0; for (int i = 0; i < 5; i++) { ITerminal terminal1 = terminals[j]; ITerminal terminal2 = terminals[j + 1]; ITerminal terminal3 = terminals[j + 2]; terminal1.Call(GenerateNumber(j + 1)); Assert.AreEqual(true, terminal2.IsRinging); Thread.Sleep(r.Next(100, 300)); terminal3.Call(GenerateNumber(j + 1)); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(3, station.GetPortCountInUse()); IPort port1 = station.GetPortByTerminal(terminal1); IPort port2 = station.GetPortByTerminal(terminal2); IPort port3 = station.GetPortByTerminal(terminal3); Assert.AreEqual(PortState.OutgoingCall, port1.PortState); Assert.AreEqual(PortState.IncomingCall, port2.PortState); Assert.AreEqual(PortState.OutgoingCall, port3.PortState); terminal2.Answer(); Assert.AreEqual(false, terminal2.IsRinging); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(PortState.Busy, port1.PortState); Assert.AreEqual(PortState.Busy, port2.PortState); Assert.AreEqual(PortState.OutgoingCall, port3.PortState); terminal2.Drop(); Assert.AreEqual(true, terminal2.IsRinging); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(2, station.GetPortCountInUse()); Assert.AreEqual(PortState.Free, port1.PortState); Assert.AreEqual(PortState.IncomingCall, port2.PortState); Assert.AreEqual(PortState.OutgoingCall, port3.PortState); terminal2.Answer(); Assert.AreEqual(false, terminal2.IsRinging); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(PortState.Free, port1.PortState); Assert.AreEqual(PortState.Busy, port2.PortState); Assert.AreEqual(PortState.Busy, port3.PortState); terminal2.Drop(); Assert.AreEqual(false, terminal2.IsRinging); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(0, station.GetPortCountInUse()); Assert.AreEqual(PortState.Free, port1.PortState); Assert.AreEqual(PortState.Free, port2.PortState); Assert.AreEqual(PortState.Free, port3.PortState); terminal1.Call(GenerateNumber(j + 2)); Assert.AreEqual(true, terminal3.IsRinging); Thread.Sleep(r.Next(100, 300)); port1 = station.GetPortByTerminal(terminal1); port3 = station.GetPortByTerminal(terminal3); Assert.AreEqual(2, station.GetPortCountInUse()); Assert.AreEqual(PortState.OutgoingCall, port1.PortState); Assert.AreEqual(PortState.IncomingCall, port3.PortState); terminal1.Drop(); Assert.AreEqual(false, terminal3.IsRinging); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(0, station.GetPortCountInUse()); Assert.AreEqual(PortState.Free, port1.PortState); Assert.AreEqual(PortState.Free, port2.PortState); terminal1.Call(GenerateNumber(j + 2)); Assert.AreEqual(true, terminal3.IsRinging); Thread.Sleep(r.Next(100, 300)); terminal2.Call(GenerateNumber(j + 2)); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(3, station.GetPortCountInUse()); port1 = station.GetPortByTerminal(terminal1); port2 = station.GetPortByTerminal(terminal2); port3 = station.GetPortByTerminal(terminal3); Assert.AreEqual(PortState.OutgoingCall, port1.PortState); Assert.AreEqual(PortState.OutgoingCall, port2.PortState); Assert.AreEqual(PortState.IncomingCall, port3.PortState); terminal1.Drop(); Assert.AreEqual(true, terminal3.IsRinging); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(2, station.GetPortCountInUse()); Assert.AreEqual(PortState.OutgoingCall, port2.PortState); Assert.AreEqual(PortState.IncomingCall, port3.PortState); terminal2.Drop(); Assert.AreEqual(false, terminal3.IsRinging); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(0, station.GetPortCountInUse()); j += 2; } }
static void Main(string[] args) { #region Subscribers: Subscriber subscriber_1 = new Subscriber("Peter", "Parker"); Subscriber subscriber_2 = new Subscriber("Bill", "Murray"); Subscriber subscriber_3 = new Subscriber("Andrew", "Boget"); #endregion IBilling billing = new Billing(); IStation station = new Station(); Operator operator_ = new Operator(station, billing); #region Contracts: operator_.SignContract(subscriber_1.FirstName, subscriber_1.LastName, 111111, TariffOption.FreeAtNight); operator_.SignContract(subscriber_2.FirstName, subscriber_2.LastName, 222222, TariffOption.FreeMinutesStandart); operator_.SignContract(subscriber_3.FirstName, subscriber_3.LastName, 333333, TariffOption.FreeMinutesEasy); #endregion #region Terminals: ITerminal terminal_1 = station.ReturnTerminal(111111); ITerminal terminal_2 = station.ReturnTerminal(222222); ITerminal terminal_3 = station.ReturnTerminal(333333); #endregion #region Tests: terminal_1.Connect(); terminal_2.Connect(); terminal_3.Connect(); terminal_1.Call(222222); terminal_2.Answer(); terminal_1.Reject(); terminal_1.Call(333333); terminal_3.Answer(); terminal_3.Reject(); terminal_1.Call(222222); terminal_2.Answer(); terminal_1.Reject(); terminal_2.Call(333333); terminal_3.Answer(); terminal_1.Call(333333); terminal_2.Reject(); terminal_3.Call(111111); terminal_1.Answer(); terminal_3.Reject(); operator_.ChangeTariff(222222, TariffOption.FreeAtNight); terminal_2.Call(111111); terminal_1.Answer(); terminal_3.Call(222222); terminal_2.Reject(); terminal_2.Call(333333); terminal_3.Answer(); terminal_2.Reject(); terminal_2.Disconect(); billing.GetFullStatistic(111111); billing.GetFullStatistic(222222); billing.GetFullStatistic(333333); billing.GetStatisticByCost(111111, 10, 60); billing.GetStatisticByTargetAbonent(111111, 222222); #endregion #region Close application Console.WriteLine("\nPress any key to close."); Console.ReadKey(); #endregion }