/// <summary> /// The menu using object of PaymentLogic class, /// switch to ability to choose the prefered item. /// </summary> private static void PaymentBusinessLogicMenu() { PaymentLogic paymLogic = new PaymentLogic(); Console.Clear(); Console.WriteLine("Choose an action:"); Console.WriteLine("1) List all payment"); Console.WriteLine("2) Update payment"); Console.WriteLine("3) Create new payment"); Console.WriteLine("4) Delete payment"); Console.WriteLine("5) Show payment's commission to the agency"); Console.WriteLine("6) Show average commissions per payment"); Console.Write("\r\nSelect an option: "); switch (Console.ReadLine()) { case "1": Console.WriteLine("Table payment:"); foreach (Payment item in paymLogic.GetAllPayments().ToList()) { Console.WriteLine($"pay_id: {item.PayId}, pay_amount: {item.PayAmount}, pay_applicant_id: {item.PayApplId}, pay_result:{item.PayIspayed}"); } Console.ReadLine(); break; case "2": Console.WriteLine("Update payment:"); Console.WriteLine("Write Id of payment:"); int payId = int.Parse(Console.ReadLine()); Console.WriteLine("Write new price amount for a visa:"); int amount = int.Parse(Console.ReadLine()); paymLogic.ChangePriceAmount(payId, amount); Console.WriteLine("Changes done!"); break; case "3": try { Console.WriteLine("Create new payment:"); Console.WriteLine("write new id :"); int id = int.Parse(Console.ReadLine()); Console.WriteLine("Write existing tourist id:"); int tourId = int.Parse(Console.ReadLine()); Console.WriteLine("Write existing agency id:"); int agenId = int.Parse(Console.ReadLine()); Console.WriteLine("Enter amount of money that visa costs: "); int money = int.Parse(Console.ReadLine()); Console.WriteLine("Enter if amount is [payed] or [not payed]: "); string payorNot = Console.ReadLine(); paymLogic.CreateNewPayment(id, tourId, agenId, money, payorNot); Console.WriteLine("Agency created successfully!"); } catch (Exception ex) { string message = string.Empty; Console.ForegroundColor = ConsoleColor.Red; if (ex is FormatException) { message = " Incorrect form"; } else { Console.WriteLine(ex.Message); } Console.WriteLine(message); } break; case "4": Console.WriteLine("Delete payment by id:"); Console.WriteLine("Write payment id:"); int takeId = int.Parse(Console.ReadLine()); paymLogic.RemoveOldPayment(takeId); Console.WriteLine("Payment deleted successfully!"); break; case "5": Console.WriteLine("Show payment's commission"); var commisions = paymLogic.GetPaymentCommissions(); foreach (var comm in commisions) { Console.WriteLine($" Commission: {comm.AmountOfCommission}, IsPayed:{comm.IsPaid} "); } Console.WriteLine("task output:"); Task <IList <PaymentCommission> > paymentTask = paymLogic.GetPaymentCommissionAsync(); paymentTask.Wait(); if (paymentTask.IsCompletedSuccessfully) { foreach (var task in paymentTask.Result) { Console.WriteLine($" Commission: {task.AmountOfCommission}, IsPayed:{task.IsPaid} "); } } Console.ReadLine(); break; case "6": Console.WriteLine("Show average payment's commission of the agencies"); var comAvg = paymLogic.GetPaymentAverageCommissions(); foreach (var co in comAvg) { Console.WriteLine($" By Companies who: {co.IsPaid}, AvgCommissions:{co.AmountOfCommission} $"); } Console.WriteLine("task output:"); Task <IList <PaymentCommission> > payAvgComTask = paymLogic.GetPaymentAverageCommissionsAsync(); payAvgComTask.Wait(); if (payAvgComTask.IsCompletedSuccessfully) { foreach (var task in payAvgComTask.Result) { Console.WriteLine($" By Companies who: {task.IsPaid}, AvgCommissions:{task.AmountOfCommission} $"); } } Console.ReadLine(); break; } }
public void TestPaymentCommission() { Mock <IPaymentRepository> mockPayRepo = new Mock <IPaymentRepository>(MockBehavior.Loose); Mock <IAgencyRepository> mockAgenRepo = new Mock <IAgencyRepository>(MockBehavior.Loose); Mock <IApplicantRepository> mockAppRepo = new Mock <IApplicantRepository>(MockBehavior.Loose); List <Payment> listPay = new List <Payment>() { new Payment() { PayId = 1, PayAgenId = 1, PayApplId = 2, PayAmount = 50, PayIspayed = "payed" }, new Payment() { PayId = 2, PayAgenId = 2, PayApplId = 3, PayAmount = 100, PayIspayed = "not payed" }, new Payment() { PayId = 3, PayAgenId = 3, PayApplId = 1, PayAmount = 100, PayIspayed = "payed" }, new Payment() { PayId = 4, PayAgenId = 7, PayApplId = 4, PayAmount = 60, PayIspayed = "not payed" }, new Payment() { PayId = 5, PayAgenId = 5, PayApplId = 5, PayAmount = 130, PayIspayed = "payed" }, new Payment() { PayId = 6, PayAgenId = 7, PayApplId = 8, PayAmount = 67, PayIspayed = "payed" }, new Payment() { PayId = 7, PayAgenId = 6, PayApplId = 10, PayAmount = 60, PayIspayed = "payed" }, new Payment() { PayId = 8, PayAgenId = 4, PayApplId = 6, PayAmount = 40, PayIspayed = "not payed" }, new Payment() { PayId = 9, PayAgenId = 5, PayApplId = 7, PayAmount = 10, PayIspayed = "not payed" }, new Payment() { PayId = 10, PayAgenId = 5, PayApplId = 9, PayAmount = 41, PayIspayed = "payed" }, }; List <Agency> listAgency = new List <Agency>() { new Agency() { AgenId = 1, AgenName = "PegasTouristic" }, new Agency() { AgenId = 2, AgenName = "AmediaTour" }, new Agency() { AgenId = 3, AgenName = "StarTravel" }, new Agency() { AgenId = 7, AgenName = "PortalAsia" }, new Agency() { AgenId = 5, AgenName = "TravelAround" }, new Agency() { AgenId = 6, AgenName = "AhmadTravel" }, new Agency() { AgenId = 4, AgenName = "CCUnated" }, }; List <Applicant> listApplicant = new List <Applicant>() { new Applicant() { ApplId = 2 }, new Applicant() { ApplId = 3 }, new Applicant() { ApplId = 1 }, new Applicant() { ApplId = 4 }, new Applicant() { ApplId = 5 }, new Applicant() { ApplId = 8 }, new Applicant() { ApplId = 10 }, new Applicant() { ApplId = 6 }, new Applicant() { ApplId = 7 }, new Applicant() { ApplId = 9 }, }; List <PaymentCommission> expectedExten = new List <PaymentCommission>() { new PaymentCommission() { AmountOfCommission = 6, IsPaid = "payed" }, new PaymentCommission() { AmountOfCommission = 2, IsPaid = "not payed" }, }; mockPayRepo.Setup(repo => repo.GetAll()).Returns(listPay.AsQueryable); mockAppRepo.Setup(repo => repo.GetAll()).Returns(listApplicant.AsQueryable); mockAgenRepo.Setup(repo => repo.GetAll()).Returns(listAgency.AsQueryable); PaymentLogic logic = new PaymentLogic(mockAppRepo.Object, mockAgenRepo.Object, mockPayRepo.Object); var result = logic.GetPaymentCommissions(); Assert.That(result, Is.EqualTo(expectedExten)); mockPayRepo.Verify(repo => repo.GetAll(), Times.Once); }