Exemplo n.º 1
0
        //Terminal in operator hard code??
        static void Main(string[] args)
        {
            Billing  billing   = new Billing(new BusinessTarifPlan());
            Operator @operator = new Operator();
            Station  station   = new Station(3);

            @operator.RegisterInBilling += billing.RegisterUser;
            @operator.AddTerminal       += station.AddTerminal;
            station.CallCompleted       += billing.EndOfCall;
            station.GetAbonentByNumber  += @operator.GetAbonentByNumber;

            Abonent a1 = new Abonent("Mike", "Jordan");
            Abonent a2 = new Abonent("Bill", "Jonson");
            Abonent a3 = new Abonent("Mike", "Vazowski");

            Terminal t1 = @operator.RegisterAbonent(a1, 1200);
            Terminal t2 = @operator.RegisterAbonent(a2, 1300);
            Terminal t3 = @operator.RegisterAbonent(a3, 200);

            t1.Call(t2.Number);
            t2.Answer();
            t2.Reject();

            t1.Call(t3.Number);
            t3.Answer();
            t1.Reject();

            t2.Call(t3.Number);
            t3.Answer();
            t3.Reject();

            var reports = billing.GetReports(a1);

            Console.WriteLine(a1 + " : ");
            Console.WriteLine("Ballance: " + billing.GetBallance(a1));
            foreach (var r in reports)
            {
                Console.WriteLine(r);
            }

            var reports2 = billing.GetReports(a2);

            Console.WriteLine(a2 + " : ");
            Console.WriteLine("Ballance: " + billing.GetBallance(a2));
            foreach (var r in reports2)
            {
                Console.WriteLine(r);
            }
        }
Exemplo n.º 2
0
        public void CallTest(Terminal terminal1, Terminal terminal2)
        {
            var ports = new List <Port>()
            {
                new Port(), new Port()
            };

            terminal1.Plug(ports[0]);
            terminal2.Plug(ports[1]);
            var subscribers = new List <BillingSubscriber>()
            {
                new BillingSubscriber(terminal1.Number), new BillingSubscriber(terminal2.Number)
            };
            var billingStation = new BillingStation(subscribers);
            var station        = new Station(ports, billingStation);

            station.NewRequestWaiting(ports[0]);
            station.NewRequestWaiting(ports[1]);
            terminal1.Call(terminal2.Number);
            terminal2.Port.IncomingRequest += ((sender, request) => Assert.Equal(request.Source, terminal1.Number));
            terminal2.Answer();
            terminal1.Port.StationRespond += ((sender, respond) => Assert.Equal(respond.AcceptMessage, "Call Started"));
            Thread.Sleep(1000);
            terminal1.EndCall();
            terminal2.Port.CallEnd += ((sender, args) => Assert.Equal(sender, terminal1));
            var stats = subscribers[0].GetStats();

            foreach (var callInfo in stats)
            {
                Assert.Equal(callInfo.Source, terminal1.Number);
                Assert.Equal(callInfo.Target, terminal2.Number);
                Assert.NotNull(callInfo.Started);
                Assert.NotNull(callInfo.Ended);
            }
        }
Exemplo n.º 3
0
        public void BillingTest_2_clients()
        {
            DateTime startDate = new DateTime(2016, 05, 01, 09, 00, 00);
            DateTime endDate   = new DateTime(2016, 06, 30, 22, 00, 00);

            StaticTime.CurrentTime = startDate;

            TariffStandart tariffStandart = new TariffStandart("Standart", 1.5, 20);
            TariffLight    tariffLight    = new TariffLight("Discount 10", 1.1, 25, 10, 25);
            TariffSpecial  tariffSpecial  = new TariffSpecial("Talk more than 3", 1.2, 30, 3, 100);

            BillingSystem billing = new BillingSystem();

            billing.TariffPlans.Add(tariffStandart);
            billing.TariffPlans.Add(tariffLight);
            billing.TariffPlans.Add(tariffSpecial);

            Client client1        = billing.AddClient("1", "Client 1");
            string client1_number = "111111";

            client1.AddContract("1", client1_number, tariffStandart);
            IContract client1_Contract1 = client1.GetContractByNumber(client1_number);

            Client client2        = billing.AddClient("2", "Client 2");
            string client2_number = "222222";

            client2.AddContract("1", client2_number, tariffLight);
            IContract client2_Contract1 = client2.GetContractByNumber(client2_number);

            Station station = new Station(10);

            station.CallCompletedEvent += billing.OnCallComleted;

            ITerminal terminal1 = new Terminal(1);

            terminal1.Plug();
            station.AddTerminal(client1_Contract1.PhoneNumber, terminal1);

            ITerminal terminal2 = new Terminal(2);

            terminal2.Plug();
            station.AddTerminal(client2_Contract1.PhoneNumber, terminal2);

            terminal1.Call(client2_number);
            StaticTime.AddSeconds(5);
            terminal2.Answer();
            StaticTime.AddMinutes(5);
            terminal2.Drop();

            StaticTime.CurrentTime = startDate.AddDays(1);
            terminal2.Call(client1_number);
            terminal1.Answer();
            StaticTime.AddMinutes(5);
            terminal1.Drop();

            StaticTime.CurrentTime = startDate.AddDays(2);
            terminal2.Call(client1_number);
            terminal1.Answer();
            StaticTime.AddMinutes(10);
            terminal2.Drop();


            IEnumerable <HistoryRecordWithSumm> history_client1 = client1_Contract1.GetCallHistory(startDate, startDate.AddDays(1));

            Assert.AreEqual(tariffStandart.Cost * 5, history_client1.Sum(h => h.Cost));

            IEnumerable <HistoryRecordWithSumm> history1_client2 = client2_Contract1.GetCallHistory(startDate.AddDays(1), startDate.AddDays(2));

            Assert.AreEqual((tariffLight.Cost - tariffLight.Cost / 100 * tariffLight.Discount) * 5, history1_client2.Sum(h => h.Cost));

            IEnumerable <HistoryRecordWithSumm> history2_client2 = client2_Contract1.GetCallHistory(startDate.AddDays(2), startDate.AddDays(3));

            Assert.AreEqual(tariffLight.Cost * 5 + (tariffLight.Cost - tariffLight.Cost / 100 * tariffLight.Discount) * 5, history2_client2.Sum(h => h.Cost));
        }
Exemplo n.º 4
0
        public void BillingTest_3_clients()
        {
            DateTime startDate = new DateTime(2016, 05, 01, 09, 00, 00);
            DateTime endDate   = new DateTime(2016, 06, 30, 22, 00, 00);

            StaticTime.CurrentTime = startDate;

            TariffStandart tariffStandart = new TariffStandart("Standart", 1.5, 20);
            TariffLight    tariffLight    = new TariffLight("Discount 10", 1.1, 25, 10, 25);
            TariffSpecial  tariffSpecial  = new TariffSpecial("Talk more than 3", 1.2, 30, 3, 100);

            BillingSystem billing = new BillingSystem();

            billing.TariffPlans.Add(tariffStandart);
            billing.TariffPlans.Add(tariffLight);
            billing.TariffPlans.Add(tariffSpecial);

            Client client1        = billing.AddClient("1", "Client 1");
            string client1_number = "111111";

            client1.AddContract("1", client1_number, tariffStandart);
            IContract client1_Contract1 = client1.GetContractByNumber(client1_number);

            Client client2        = billing.AddClient("2", "Client 2");
            string client2_number = "222222";

            client2.AddContract("1", client2_number, tariffLight);
            IContract client2_Contract1 = client2.GetContractByNumber(client2_number);

            Client client3        = billing.AddClient("3", "Client 3");
            string client3_number = "333333";

            client3.AddContract("1", client3_number, tariffSpecial);
            IContract client3_Contract1 = client3.GetContractByNumber(client3_number);

            Station station = new Station(10);

            station.CallCompletedEvent += billing.OnCallComleted;

            ITerminal terminal1 = new Terminal(1);

            terminal1.Plug();
            station.AddTerminal(client1_Contract1.PhoneNumber, terminal1);

            ITerminal terminal2 = new Terminal(2);

            terminal2.Plug();
            station.AddTerminal(client2_Contract1.PhoneNumber, terminal2);

            ITerminal terminal3 = new Terminal(3);

            terminal3.Plug();
            station.AddTerminal(client3_Contract1.PhoneNumber, terminal3);

            terminal1.Call(client2_number);

            StaticTime.AddSeconds(5);
            terminal3.Call(client2_number);

            StaticTime.AddSeconds(10);
            terminal2.Answer();

            StaticTime.AddMinutes(5);
            terminal2.Drop();

            StaticTime.AddSeconds(20);
            terminal2.Answer();
            StaticTime.AddMinutes(15);
            terminal2.Drop();

            StaticTime.AddDays(10);
            terminal1.Call(client3_number);
            StaticTime.AddMinutes(2);
            terminal1.Drop();

            StaticTime.AddDays(10);
            terminal1.Call(client3_number);
            StaticTime.AddMinutes(1);
            terminal2.Call(client3_number);

            StaticTime.AddMinutes(2);
            terminal1.Drop();
            StaticTime.AddSeconds(30);
            terminal2.Drop();

            Assert.AreEqual(3, client1_Contract1.GetCallHistory(startDate, endDate).Count());
            Assert.AreEqual(3, client2_Contract1.GetCallHistory(startDate, endDate).Count());
            Assert.AreEqual(4, client3_Contract1.GetCallHistory(startDate, endDate).Count());

            string client1_invoice = client1_Contract1.GenerateInvoice(startDate, endDate);
            string client2_invoice = client2_Contract1.GenerateInvoice(startDate, endDate);
            string client3_invoice = client3_Contract1.GenerateInvoice(startDate, endDate);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            DateTime startDate = new DateTime(2016, 05, 01, 09, 00, 00);
            DateTime endDate   = new DateTime(2016, 06, 30, 22, 00, 00);

            StaticTime.CurrentTime = startDate;

            TariffStandart tariffStandart = new TariffStandart("Standart", 1.5, 20);
            TariffLight    tariffLight    = new TariffLight("Discount 10", 1.1, 25, 10, 25);
            TariffSpecial  tariffSpecial  = new TariffSpecial("Talk more than 3", 1.2, 30, 3, 100);

            BillingSystem billing = new BillingSystem();

            billing.TariffPlans.Add(tariffStandart);
            billing.TariffPlans.Add(tariffLight);
            billing.TariffPlans.Add(tariffSpecial);

            Client client1        = billing.AddClient("1", "Client 1");
            string client1_number = "111111";

            client1.AddContract("1", client1_number, tariffStandart);
            IContract client1_Contract1 = client1.GetContractByNumber(client1_number);

            Client client2        = billing.AddClient("2", "Client 2");
            string client2_number = "222222";

            client2.AddContract("1", client2_number, tariffLight);
            IContract client2_Contract1 = client2.GetContractByNumber(client2_number);

            Station station = new Station(10);

            station.CallCompletedEvent += billing.OnCallComleted;

            ITerminal terminal1 = new Terminal(1);

            terminal1.Plug();
            station.AddTerminal(client1_Contract1.PhoneNumber, terminal1);

            ITerminal terminal2 = new Terminal(2);

            terminal2.Plug();
            station.AddTerminal(client2_Contract1.PhoneNumber, terminal2);

            terminal1.Call(client2_number);
            StaticTime.AddSeconds(5);
            terminal2.Answer();
            StaticTime.AddMinutes(5);
            terminal2.Drop();

            StaticTime.CurrentTime = startDate.AddDays(1);
            terminal2.Call(client1_number);
            terminal1.Answer();
            StaticTime.AddMinutes(5);
            terminal1.Drop();

            StaticTime.CurrentTime = startDate.AddDays(2);
            terminal2.Call(client1_number);
            terminal1.Answer();
            StaticTime.AddMinutes(10);
            terminal2.Drop();

            Console.WriteLine(client1_Contract1.GenerateInvoice(startDate, endDate));
            Console.WriteLine("**************");
            Console.WriteLine(client2_Contract1.GenerateInvoice(startDate, endDate));

            Console.ReadKey();
        }