public void Setup() { this.db = new PostgresqlDatabase(); // try to get rid of me this.chargerMock = new Mock <ICharger>(); this.billingSystem = new BillingSystem(this.db, this.chargerMock.Object); this.billingSystem.Init(); }
public void Setup() { customerRepoMock = new Mock <ICustomerRepository>(); subscriptionRepoMock = new Mock <ISubscriptionRepository>(); chargerMock = new Mock <ICharger>(); billingSystem = new BillingSystem(customerRepoMock.Object, subscriptionRepoMock.Object, chargerMock.Object); }
static void Main(string[] args) { Console.WriteLine("#########################################"); Console.WriteLine("# Welcome to workshop 5 | Testable Code #"); Console.WriteLine("#########################################"); Console.WriteLine(); var db = new PostgresqlDatabase(); db.Customers.Add(new Customer { Id = Guid.NewGuid(), Name = "John Doe" }); db.Customers.Add(new Customer { Id = Guid.NewGuid(), Name = "Maggie Musterman" }); db.Customers.Add(new Customer { Id = Guid.NewGuid(), Name = "Some Dude" }); // ---------------------------------------------------------------- // Optimize the code below ... var billingSystem = new BillingSystem(db, new CreditCardCharger()); billingSystem.Init(); // bad! billingSystem.Process(); // ---------------------------------------------------------------- Console.WriteLine(); Console.WriteLine("Good bye! See you next time!"); Console.ReadLine(); }
public void RemoveBillingSystem(BillingSystem system) { if (system != null) { CallCompleted -= system.OnCallCompleted; } }
public void AddBillingSystem(BillingSystem system) { if (system != null) { CallCompleted += system.OnCallCompleted; } }
static void Main() { ITarget target = new EmployeeAdapter(); BillingSystem client = new BillingSystem(target); client.ShowEmployeeList(); }
static void Main(string[] args) { IATE ate = new ATE(); CallHandler handler = new CallHandler(); IBillingSystem bs = new BillingSystem(ate); IContract c1 = ate.SignContract(new Client("Vasya", "Topolev"), TypeOfTariff.Mini); IContract c2 = ate.SignContract(new Client("Petya", "Sosnov"), TypeOfTariff.Maxi); IContract c3 = ate.SignContract(new Client("Gena", "Beresov"), TypeOfTariff.Mini); c1.Client.PutMoney(5000); c1.Client.WithdrawMoney(30); Terminal t1 = ate.NewTerminal(c1); Terminal t2 = ate.NewTerminal(c2); Terminal t3 = ate.NewTerminal(c3); t1.ConnectToATS(); t2.ConnectToATS(); t3.ConnectToATS(); t1.Call(t2.Number); Thread.Sleep(1111); t2.EndCall(); t3.Call(t1.Number); Thread.Sleep(2222); t3.EndCall(); t2.Call(t1.Number); Thread.Sleep(3333); t1.EndCall(); Console.ReadKey(); }
public Station() { _agreements = new List <Agreement>(); _portsMap = new Dictionary <PhoneNumber, IPort>(); _ports = new List <IPort>(); _terminals = new List <ITerminal>(); _billingSystem = new BillingSystem(); }
internal static void Main(string[] args) { BillingSystem sys = new BillingSystem(); sys.Init(args); sys.Loop(); sys.Release(); }
static void Main(string[] args) { Console.WriteLine("#########################################"); Console.WriteLine("# Welcome to workshop 5 | Testable Code #"); Console.WriteLine("#########################################"); Console.WriteLine(); var db = new PostgresqlDatabase(); db.Customers.Add(new Customer { Id = Guid.NewGuid(), Name = "John Doe" }); db.Customers.Add(new Customer { Id = Guid.NewGuid(), Name = "Maggie Musterman" }); db.Customers.Add(new Customer { Id = Guid.NewGuid(), Name = "Some Dude" }); // Replace this by AUTOFAC var database = new PostgresqlDatabase(); var billingSystem = new BillingSystem( new CustomerRepository(database), new SubscriptionRepository(database), new CreditCardCharger()); /* * USE AUTOFAC HERE!! * * var billingSystem = container.Resolve<BillingSystem>(); */ var containerConfig = new ContainerBuilder(); containerConfig.RegisterType <CustomerRepository>().As <ICustomerRepository>(); containerConfig.RegisterType <SubscriptionRepository>().As <ISubscriptionRepository>(); containerConfig.RegisterType <CreditCardCharger>().As <ICharger>(); // this tells Autofac to only create a single instance of PostgresqlDatabase and // use that one instance everytime a ICustomerDatabase or ISubscriptionDatabase // is needed containerConfig .RegisterType <PostgresqlDatabase>() .As <ICustomerDatabase>() .InstancePerLifetimeScope(); containerConfig .RegisterType <PostgresqlDatabase>() .As <ISubscriptionDatabase>() .InstancePerLifetimeScope(); billingSystem.Process(); Console.WriteLine(); Console.WriteLine("Good bye! See you next time!"); Console.ReadLine(); }
public Company(BillingSystem billingSystem) { _billingSystem = billingSystem; // Billing system subscribes on user registration. RegisterUserEvent += _billingSystem.OnRegisterUserExecute; // ATS of billing system subscribes on user registration. RegisterUserEvent += _billingSystem.ATS.OnRegisterUserExecute; }
static void Main(string[] args) { IATE ate = new ATE(); IReportRender render = new ReportRender(); BillingSystem bs = new BillingSystem(ate); IContract c1 = ate.RegisterContract(new Subscriber("John", "Smith"), TariffType.Pro); IContract c2 = ate.RegisterContract(new Subscriber("James", "Bond"), TariffType.Pro); IContract c3 = ate.RegisterContract(new Subscriber("Jansen", "Born"), TariffType.Pro); c1.Subscriber.AddMoney(10); var t1 = ate.GetNewTerminal(c1); var t2 = ate.GetNewTerminal(c2); var t3 = ate.GetNewTerminal(c3); t1.ConnectToPort(); t2.ConnectToPort(); t3.ConnectToPort(); t1.Call(t2.TelephoneNumber); Thread.Sleep(2000); t2.EndCall(); t3.Call(t1.TelephoneNumber); Thread.Sleep(1000); t3.EndCall(); t2.Call(t1.TelephoneNumber); Thread.Sleep(3000); t1.EndCall(); t1.Disconnect(); t2.Disconnect(); t3.Disconnect(); t3.Call(t1.TelephoneNumber); Console.WriteLine(); Console.WriteLine("Sorted records:"); foreach (var item in render.SortCalls(bs.GetReport(t1.TelephoneNumber), TypeSort.SortByCallType)) { Console.WriteLine( "Calls:\n Type {0} |\n Date: {1} |\n Duration: {2:mm:ss} | Cost: {3} | Telephone number: {4}", item.CallType, item.Date, item.Time, item.Cost, item.Number); } Console.ReadKey(); }
private void loadBilling() { BillingSystem billingMain = new BillingSystem(); billingMain.TopLevel = false; billingMain.AutoScroll = true; billingMain.FormBorderStyle = FormBorderStyle.None; billingMain.Dock = DockStyle.Fill; this.pnlDisplay.Controls.Clear(); this.pnlDisplay.Controls.Add(billingMain); billingMain.Show(); }
static void Main(string[] args) { List<IPort> ports = new List<IPort> { new PortReal(), new PortReal(),new PortReal() }; StationReal n = new StationReal(ports); BillingSystem s = new BillingSystem(); s.RegisterEventHandlerForStation(n); ITerminal t = new TerminalReal(new PhoneNumber("123-45-67")); ITerminal t1 = new TerminalReal(new PhoneNumber("765-43-21")); ITerminal t2 = new TerminalReal(new PhoneNumber("000-11-11")); n.Add(t); n.Add(t1); n.Add(t2); t2.Plug(); t.Plug(); t1.Plug(); TariffList tariffs = new TariffList(); //Add new tariff tariffs.Add(new Tariff { FreeMinutes = 10, Name = "Gold tariff", PriceOfMinute = 5 }); //Change tariff for client if (n.SetTariffForTerminal(new PhoneNumber("123-45-67"), tariffs.GetByName("Gold tariff"))) { Console.WriteLine("123-45-67 changed tariff to Gold tariff"); } t.Call(new PhoneNumber("765-43-21")); t1.Answer(); t1.Drop(); double score = s.CalculateClient(new PhoneNumber("123-45-67")); Console.WriteLine(score); t1.Call(new PhoneNumber("123-45-67")); t.Answer(); //Try call, when target is alredy talk t2.Call(new PhoneNumber("765-43-21")); t1.Drop(); DateTime startDate = new DateTime(2010,11,15); var calls = s.GetCallInfoByPeriod(new PhoneNumber("765-43-21"), startDate, new DateTime(2015,11,11)); BillingSystem.ShowCallInfo(calls); var calls1 = s.GetCallInfoByNumber(new PhoneNumber("765-43-21")); BillingSystem.ShowCallInfo(calls1); score = s.CalculateClient(new PhoneNumber("765-43-21")); Console.WriteLine(score); var clientCalls = s.GetCallInfoByNumber(new PhoneNumber("123-45-67")); BillingSystem.ShowCallInfo(clientCalls); }
static void Main(string[] args) { Station station = new Station(); BillingSystem billingSystem = new BillingSystem(); User user1 = new User("Vasya", "Levashko"); User user2 = new User("Lesha", "Kazakov"); station.CreateAgreement(user1); station.CreateAgreement(user2); user1.Terminal.Call(user2.Terminal.Number); user1.Terminal.EndCall(); Console.ReadLine(); }
static void Main(string[] args) { ATS ats = new ATS(); ReportShow show = new ReportShow(); BillingSystem billingSystem = new BillingSystem(ats); Contract contract1 = ats.RegisterContract(new Client("Ivan", "Ivanov", 30), TariffTypes.Standart); Contract contract2 = ats.RegisterContract(new Client("Ilja", "Iljin", 10), TariffTypes.Elementary); Contract contract3 = ats.RegisterContract(new Client("Dima", "Grachev", 50), TariffTypes.Lux); contract1.Client.AddMoney(50); var t1 = ats.GetNewTerminal(contract1); var t2 = ats.GetNewTerminal(contract2); var t3 = ats.GetNewTerminal(contract3); t1.ConnectToPort(); t2.ConnectToPort(); t3.ConnectToPort(); t1.Call(t2.Number); Thread.Sleep(1000); t2.EndCall(); Thread.Sleep(1000); t3.Call(t1.Number); Thread.Sleep(1000); t3.EndCall(); t2.Call(t1.Number); Thread.Sleep(30000); t1.EndCall(); t3.Call(1234567); t2.Call(t2.Number); Console.WriteLine("Sorted records:"); foreach (var item in show.SortCalls(billingSystem.GetReport(t2.Number), SortTypes.SortByPrice)) { Console.WriteLine("Calls:\n Type {0} |\n Date: {1} |\n Duration: {2} | Cost: {3} | Telephone number: {4}", item.CallType, item.Date, item.Time.ToString("mm:ss"), item.Price, item.Number); } Console.ReadKey(); }
static void Main(string[] args) { IATE ate = new AutomaticTelephoneExchange.ATE(); IReportRender render = new ReportRender(); IBillingSystem bs = new BillingSystem(ate); IContract c1 = ate.RegisterContract(new Subscriber("Leo", "Smith"), Enums.TariffType.Light); IContract c2 = ate.RegisterContract(new Subscriber("Jack", "Jones"), Enums.TariffType.Pro); IContract c3 = ate.RegisterContract(new Subscriber("Harry", "Williams"), Enums.TariffType.Light); c1.Subscriber.AddMoney(10); var t1 = ate.GetNewTerminal(c1); var t2 = ate.GetNewTerminal(c2); var t3 = ate.GetNewTerminal(c3); t1.ConnectToPort(); t2.ConnectToPort(); t3.ConnectToPort(); t1.Call(t2.Number); Thread.Sleep(2000); t2.EndCall(); t3.Call(t1.Number); Thread.Sleep(60000); t3.EndCall(); t2.Call(t1.Number); Thread.Sleep(3000); t1.EndCall(); Console.WriteLine(); Console.WriteLine("Sorted records:"); foreach (var item in render.SortCalls(bs.GetReport(t1.Number), Enums.TypeSort.SortByCallType)) { Console.WriteLine("Calls:\n Type {0} |\n Date: {1} |\n Duration: {2} | Cost: {3} | Telephone number: {4}", item.CallType, item.Date, item.Time.ToString("mm:ss"), item.Cost, item.Number); } Console.ReadKey(); }
private static void WorkWithBillingSystem(BillingSystem billingSystem) { Console.WriteLine(new string('-', 50)); Console.WriteLine("Calls with cost > 5000BYR: "); foreach (var item in billingSystem.GetCalls(item => item.Statistic.Cost > 5000)) Console.WriteLine(item); Console.WriteLine(new string('-', 50)); Console.WriteLine("Calls grouped by number: "); foreach (var group in billingSystem.GetCallsGroupedByNumber()) { Console.WriteLine("-> " + group.Key + " <-"); foreach (var item in group) Console.WriteLine(item); } Console.WriteLine(new string('-', 50)); Console.WriteLine("Sorted calls by cost: "); foreach (var item in billingSystem.GetSortedCallsByCost()) Console.WriteLine(item); Console.WriteLine(new string('-', 50)); Console.WriteLine("Calls by first client"); foreach (var item in billingSystem.GetCallsByClient(billingSystem.Clients[0])) Console.WriteLine(item); Console.WriteLine(new string('-', 50)); }
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); }
static void Main() { //create a new billing system BillingSystem billingSystem = new BillingSystem(4); //create some customers RegularCustomer regularCustomer1 = new RegularCustomer("Customer1"); RegularCustomer regularCustomer2 = new RegularCustomer("Customer2", 100.5); VIPCustomer vIPCustomer1 = new VIPCustomer("Customer3", "Tel-Aviv"); VIPCustomer vIPCustomer2 = new VIPCustomer("Customer4", "Jerusalem", 1000); ////we can't create a Customer class instance //Customer customer = new Customer("Customer5"); //Add Customers to the billing system //would be better to add an overload taking parmas array try { Console.WriteLine($"adding 4 customers"); billingSystem.AddCustomer(regularCustomer1); billingSystem.AddCustomer(vIPCustomer1); billingSystem.AddCustomer(regularCustomer2); billingSystem.AddCustomer(vIPCustomer2); } catch (TooManyCustomersException e) { Console.WriteLine($"Max customers reached: {e.MaxCustomersAllowed}"); } //print the system before change Console.WriteLine(billingSystem); //Calling the UpdateBalane billingSystem.UpdateBalance(amountToAdd); Console.WriteLine($"Adding {amountToAdd} to all Customers\nVip should get 80% of the amount: {amountToAdd * 0.8}\nAnd Regular customers should get 100%\n"); //print the system after change Console.WriteLine(billingSystem); try { Console.WriteLine(billingSystem[2, "Customer1"]); } catch (ArgumentException e) { Console.WriteLine($"Argument Exception !: {e.Message}"); } #region Sorting Exmp Console.WriteLine("Sorting Customers by default Icomparer [by Id]"); billingSystem.Sort(); Console.WriteLine(billingSystem); Console.WriteLine("Sorting Customers by a specified Icomparer [by balance]"); billingSystem.Sort(new CompareCustomerByBalance()); Console.WriteLine(billingSystem); Console.WriteLine("Sorting Customers by a specified Icomparer [by name(Generic implementation)]"); billingSystem.Sort(new CompareCustomerByNameGeneric()); Console.WriteLine(billingSystem); #endregion for (int i = 0; i < billingSystem.Length; i++) { if (!(billingSystem[i] is IAdressable adressable)) { continue; } Console.WriteLine(adressable.GetAdress()); } #region Exc #7 Random rnd = new Random(); CustomerService customerService = new CustomerService(); billingSystem.OnUnreasonableCustomerBalance += customerService.OnUnreasonableCustomerBalance; AccountingClerk accountingClerk = new AccountingClerk(); billingSystem.OnUnreasonableCustomerBalance += accountingClerk.OnUnreasonableCustomerBalance; billingSystem.DoToAllCustomers(c => { c.AddToBalance(rnd.Next(2000001)); }); #endregion }
static void Main(string[] args) { BillingSystem billingSystem = new BillingSystem(); using AutomaticTelephoneExchange ATE = new AutomaticTelephoneExchange(); SubscribeBillingToAte(ATE, billingSystem); List <Client> clients = new List <Client>() { new Client("Mike"), new Client("Mick"), new Client("Alex") }; List <Terminal> terminals = new List <Terminal>() { new Terminal("1111", "1"), new Terminal("2222", "2"), new Terminal("3333", "3") }; List <Contract> contracts = new List <Contract>(); for (int i = 0; i < 3; i++) { contracts.Add(ATE.AddContractWith(clients[i], terminals[i].PhoneNumber)); } billingSystem.Contracts = contracts; for (int i = 0; i < 3; i++) { clients[i].ConnectToPort(terminals[i], ATE.GetNotBindPort()); } clients[0].Call(terminals[0], "2222"); clients[2].Call(terminals[2], "2222"); Thread.Sleep(1000); clients[1].EndCall(terminals[1]); Thread.Sleep(1000); clients[0].Call(terminals[0], "3333"); Thread.Sleep(5000); clients[0].EndCall(terminals[0]); clients[0].Call(terminals[0], "2222"); Thread.Sleep(2500); clients[0].EndCall(terminals[0]); List <ExendetCallInfo> callInfos = billingSystem.GetCallInfoByDate("1111").ToList(); Console.WriteLine("\n\n\nСортировка по дате :"); foreach (var call in callInfos) { Console.WriteLine($"Длительность - {call.Duration.ToString()}\n Цена - {call.Cost}\n Номер абонента которому звонили - {call.OutPhoneNumber} "); } Console.WriteLine("\n\n\nСортировка по цене :"); List <ExendetCallInfo> callInfos2 = billingSystem.GetCallInfoByCost("1111").ToList(); foreach (var call in callInfos2) { Console.WriteLine($"Длительность - {call.Duration.ToString()}\n Цена - {call.Cost}\n Номер абонента которому звонили - {call.OutPhoneNumber} "); } Console.WriteLine("\n\n\nСортировка по номеру :"); List <ExendetCallInfo> callInfos3 = billingSystem.GetCallInfoByOutNumber("1111").ToList(); foreach (var call in callInfos3) { Console.WriteLine($"Длительность - {call.Duration.ToString()}\n Цена - {call.Cost}\n Номер абонента которому звонили - {call.OutPhoneNumber} "); } List <Port> ports = new List <Port>(ATE.GetPorts()); for (int i = 0; i < 3; i++) { clients[i].UnConnectToPort(terminals[i], ports[i]); } UnSubscribeBillingToAte(ATE, billingSystem); }
private static void UnSubscribeBillingToAte(AutomaticTelephoneExchange automaticTelephoneExchange, BillingSystem billingSystem) { automaticTelephoneExchange.BillTheCAllEventHandler -= billingSystem.BillTheCallEventHandler; }
public SystemFacade(BillingSystem billingSystem, ReportingSystem reportingSystem) { _billingSystem = billingSystem; _reportingSystem = reportingSystem; }
static void Main(string[] args) { var ats = Builder.ATS; var billingSystem = new BillingSystem(ats); var company = new Company(billingSystem); var tariff = Builder.Tariff; var subscriber1 = Builder.GetSubscriber("Tanya", "Kozlyakovskaya"); var subscriber2 = Builder.GetSubscriber("Valera", "Zolotov"); var subscriber3 = Builder.GetSubscriber("Maxim", "Kotov"); var subscriber4 = Builder.GetSubscriber("Nastya", "Polivoda"); var terminal1 = company.GetTerminal(company.RegisterContract(subscriber1, tariff)); var terminal2 = company.GetTerminal(company.RegisterContract(subscriber2, tariff)); var terminal3 = company.GetTerminal(company.RegisterContract(subscriber3, tariff)); var terminal4 = company.GetTerminal(company.RegisterContract(subscriber4, tariff)); terminal1.ConnectPort(); terminal2.ConnectPort(); terminal3.ConnectPort(); terminal4.ConnectPort(); // Call from disconnected terminal terminal4.Call(terminal1.Port.TelephoneNumber); Console.WriteLine("--------------------------"); // Proper call. (Answer to a call). terminal1.Call(terminal2.Port.TelephoneNumber); Console.WriteLine("--------------------------"); terminal3.Call(terminal4.Port.TelephoneNumber); // Proper call. (Decline a call). terminal2.Call(terminal1.Port.TelephoneNumber); Console.WriteLine("--------------------------"); // Call from proper terminal to disconnected. terminal1.Call(terminal4.Port.TelephoneNumber); Console.WriteLine("--------------------------"); // Proper terminal calls itself. terminal3.Call(terminal3.Port.TelephoneNumber); Console.WriteLine("--------------------------"); // Proper call. (Answer to a call). terminal1.Call(terminal2.Port.TelephoneNumber); Console.WriteLine("--------------------------"); // Proper call. (Answer to a call). terminal1.Call(terminal2.Port.TelephoneNumber); Console.WriteLine("--------------------------"); Console.WriteLine("=========================="); Console.WriteLine($"All information about calls\n{billingSystem.GetAllInfo()}"); Console.WriteLine("=========================="); Console.WriteLine($"Information about calls for {terminal1.Port.TelephoneNumber}:\n{billingSystem.GetReport(terminal1.Port.TelephoneNumber)}"); Console.WriteLine("=========================="); Console.WriteLine($"Information about incoming calls for {terminal1.Port.TelephoneNumber}:\n" + $"{billingSystem.GetFilteredReportBy(terminal1.Port.TelephoneNumber, ReportFilter.Incoming)}"); Console.WriteLine("=========================="); Console.WriteLine($"Information about calls for {terminal1.Port.TelephoneNumber} with {terminal2.Port.TelephoneNumber}:\n" + $"{billingSystem.GetFilterReportBySubscriber(terminal1.Port.TelephoneNumber, terminal2.Port.TelephoneNumber)}"); Console.WriteLine("=========================="); Console.WriteLine("The end"); Console.ReadKey(); }
static void Main(string[] args) { IStation station = new Station(); IBillingSystem bilSys = new BillingSystem(); bilSys.StationEventInit(station); IPhone phone1 = new Phone() { PhoneNumber = "1" }; IPhone phone2 = new Phone() { PhoneNumber = "2" }; IPhone phone3 = new Phone() { PhoneNumber = "3" }; IPhone phone4 = new Phone() { PhoneNumber = "4" }; station.AddNewPhone(phone1); station.AddNewPhone(phone2); station.AddNewPhone(phone3); station.AddNewPhone(phone4); IAbonent abonent1 = new Abonent() { Name = "a", Phone = phone1 }; IAbonent abonent2 = new Abonent() { Name = "b", Phone = phone2 }; IAbonent abonent3 = new Abonent() { Name = "c", Phone = phone3 }; IAbonent abonent4 = new Abonent() { Name = "d", Phone = phone4 }; bilSys.RegisterAbonent(abonent1); bilSys.RegisterAbonent(abonent2); bilSys.RegisterAbonent(abonent3); bilSys.RegisterAbonent(abonent4); abonent1.Phone.Call(phone3.PhoneNumber); abonent3.Phone.AnswerCall(); abonent2.Phone.Call(phone4.PhoneNumber); abonent4.Phone.DropCall(); abonent1.Phone.DropCall(); abonent1.Phone.Call(phone2.PhoneNumber); abonent2.Phone.AnswerCall(); abonent3.Phone.Call(phone4.PhoneNumber); abonent4.Phone.DropCall(); abonent1.Phone.DropCall(); abonent1.Phone.DisconnectFromStation(); station.AddNewPhone(abonent1.Phone); IReport report1 = bilSys.GetReportForAbonent(abonent1); Console.WriteLine(report1.GetOrderedByAbonent()); }
static void Main(string[] args) { IPort port = new Port(); ITerminal t1 = new Terminal(); ITerminal t2 = new Terminal(); ITerminal t3 = new Terminal(); IPhoneNumber p1 = new PhoneNumber("11111111"); IPhoneNumber p2 = new PhoneNumber("22222222"); IPhoneNumber p3 = new PhoneNumber("33333333"); IStation station = new Station(new List <IPort>() { new Port(), new Port() }, new List <ITerminal>() { t1, t2, t3 }); station.AddPort(port); IBillingSystem system = new BillingSystem(station, new List <IPhoneNumber>() { p1, p2, p3 }); IUser user1 = new User("Ivan", 100); IUser user2 = new User("Petya", 100); IUser user3 = new User("Dima", 100); system.RegisterUser(user1); system.RegisterUser(user2); system.RegisterUser(user3); IUserService userService = new UserService(); userService.ConnectToPort(user1, system.GetFreePort()); userService.ConnectToPort(user2, system.GetFreePort()); userService.ConnectToPort(user3, system.GetFreePort()); userService.Call(user1, p2); userService.Answer(user2); Thread.Sleep(2000); userService.EndCall(user2); Console.WriteLine(); userService.Call(user1, p2); userService.Answer(user2); Thread.Sleep(3000); userService.EndCall(user1); Console.WriteLine(); userService.Call(user1, p2); userService.Answer(user2); Thread.Sleep(1000); userService.EndCall(user2); Console.WriteLine(); userService.Call(user2, p1); userService.Call(user3, p1); userService.Reject(user1); Console.WriteLine(); userService.Call(user2, p1); userService.Reject(user2); Console.WriteLine(); userService.Call(user2, p1); userService.Answer(user1); Thread.Sleep(1000); userService.EndCall(user1); Console.WriteLine(); userService.Call(user2, p3); userService.Answer(user3); Thread.Sleep(1000); userService.EndCall(user2); Console.WriteLine(); foreach (var item in system.Users) { Console.WriteLine($"{item.Name} history"); system.CallService.GetUserCallsByCallStatePerMonth(item, Enums.CallState.NoAnswer); Console.WriteLine(); } Console.WriteLine("Press any key to continue...\n\n\n"); Console.ReadLine(); }
public void Setup() { billingSystem = new BillingSystem(chargerMock.Object, repoMock.Object); }
public AutomaticPhoneExchange(BillingSystem billingsystem) { ThisBillingSystem = billingsystem; }
public ATE() { Ports = new List <IPort>(); Abonents = new BillingSystem(); OnGoingCalls = new List <ICallData>(); }
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(); }
private static void WorkWithStation(Station station, BillingSystem billingSystem) { foreach (var item in station.Terminals) item.InsertIntoPort(); station.Terminals[0].OutgoingCall("+375(152)24-15-10"); station.Terminals[0].OutgoingCall("+375(152)24-15-10"); station.TerminalByNumber("4568").OutgoingCall("+375(1512)2-70-15"); station.TerminalByNumber("4568").OutgoingCall("+375(1512)2-70-16"); Console.WriteLine(billingSystem.Contracts[0].ChangeTariffPlan(new TariffPlan("Middle", 30000, 20, 250)) ? "Tariff plan is changed!" : "Tariff plan can be changed only 1 time per month!"); Console.WriteLine(billingSystem.Contracts[1].ChangeTariffPlan(new TariffPlan("Middle", 30000, 20, 250)) ? "Tariff plan is changed!" : "Tariff plan can be changed only 1 time per month!"); station.Terminals[0].OutgoingCall("+375(1512)2-70-15"); station.Terminals[3].RemoveFromPort(); station.Terminals[2].OutgoingCall("+375(17)25-25-25"); station.Terminals[2].RemoveFromPort(); station.Terminals[2].OutgoingCall("+375(17)25-25-25"); }
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)); }