private static void AgencyBusinessLogicMenu() { AgencyLogic agencyLogic = new AgencyLogic(); Console.Clear(); Console.WriteLine("Choose an action:"); Console.WriteLine("1) List all agencies"); Console.WriteLine("2) Update agency"); Console.WriteLine("3) Create new agency"); Console.WriteLine("4) Delete agency"); Console.WriteLine("5) Show more successful agencies"); Console.WriteLine("6) Show num of applicants of agency"); Console.Write("\r\nSelect an option: "); switch (Console.ReadLine()) { case "1": Console.WriteLine("Table agency:"); foreach (Agency item in agencyLogic.GetAllAgencies().ToList()) { Console.WriteLine($"agen_id: {item.AgenId}, agen_name: {item.AgenName}, agen_address: {item.AgenAddress}, agen_email: {item.AgenEmail}"); } Console.ReadLine(); break; case "2": Console.WriteLine("Update agency:"); Console.WriteLine("Type id of the agency which needs to modify:"); int takeId = int.Parse(Console.ReadLine()); Console.WriteLine("Type contact email address of the agency"); string newMail = Console.ReadLine(); agencyLogic.ChangeAgencyEmail(takeId, newMail); break; case "3": try { Console.WriteLine("Create new travel agency"); Console.WriteLine("Create new id (id should be more than 7):"); int newId = int.Parse(Console.ReadLine()); Console.WriteLine("Create a name of agency:"); string newName = Console.ReadLine(); Console.WriteLine("Write a location of the agency"); string newgender = Console.ReadLine(); Console.WriteLine("Enter new email address: "); string newEmail = Console.ReadLine(); agencyLogic.CreateNewAgency(newId, newName, newgender, newEmail); } 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 agency by id:"); Console.WriteLine("Enter id:"); int delId = int.Parse(Console.ReadLine()); agencyLogic.DeleteAgency(delId); Console.WriteLine("Agency deleted successfully!"); break; case "5": Console.WriteLine("Show agency successful visas"); var successAg = agencyLogic.GetAgencyWithApprovedVisas(); foreach (var v in successAg) { Console.WriteLine($" AgName: {v.AgenName}, IsApproved:{v.Approved}, ClientJob: {v.Job}, ClientName:{v.ClientName} "); } Console.WriteLine("task output:"); Task <IList <AgencySuccessful> > agTask = agencyLogic.GetAgencyWithApprovedVisasAsync(); agTask.Wait(); if (agTask.IsCompletedSuccessfully) { foreach (var task in agTask.Result) { Console.WriteLine($" AgName: {task.AgenName}, IsApproved:{task.Approved}, ClientJob: {task.Job}, ClientName:{task.ClientName}"); } } Console.ReadLine(); break; case "6": Console.WriteLine("Show number of applicants for the specified agency ...enter name:(eg. TravelAround, CCUnated)"); string newname = Console.ReadLine(); var agencyWanted = agencyLogic.GetAgencyByName(newname); Console.WriteLine($" AgName: {agencyWanted.AgenName}, NumberOfApplicants:{agencyWanted.Number} "); Console.ReadLine(); break; } }
public void TestGetAgencyByName() { Mock <IApplicantRepository> mockApplicRepo = new Mock <IApplicantRepository>(MockBehavior.Loose); Mock <IPaymentRepository> mockPaymentRepo = new Mock <IPaymentRepository>(MockBehavior.Loose); Mock <IAgencyRepository> mockAgRepo = new Mock <IAgencyRepository>(MockBehavior.Loose); Mock <IVisaRepository> mockVisaRepo = new Mock <IVisaRepository>(MockBehavior.Loose); List <Agency> agencyList = new List <Agency>() { new Agency() { AgenId = 1, AgenName = "PegasTouristic" }, new Agency() { AgenId = 5, AgenName = "TravelAround" }, }; List <Applicant> appList = new List <Applicant>() { new Applicant() { ApplId = 1, ApplName = "Aplicant1" }, new Applicant() { ApplId = 2, ApplName = "Aplicant2" }, new Applicant() { ApplId = 3, ApplName = "Aplicant3" }, }; List <Payment> payList = new List <Payment>() { new Payment() { PayId = 1, PayAgenId = 1, PayApplId = 2 }, new Payment() { PayId = 2, PayAgenId = 5, PayApplId = 3 }, new Payment() { PayId = 3, PayAgenId = 5, PayApplId = 1 }, }; List <Visa> listvisa = new List <Visa>() { new Visa() { VisaId = 1, VisaApplId = 2, VisaIsapproved = "approved" }, new Visa() { VisaId = 2, VisaApplId = 1, VisaIsapproved = "approved" }, }; mockApplicRepo.Setup(rep => rep.GetAll()).Returns(appList.AsQueryable()); mockPaymentRepo.Setup(rep => rep.GetAll()).Returns(payList.AsQueryable()); mockAgRepo.Setup(rep => rep.GetAll()).Returns(agencyList.AsQueryable()); mockVisaRepo.Setup(rep => rep.GetAll()).Returns(listvisa.AsQueryable()); AgencyLogic logic = new AgencyLogic(mockAgRepo.Object, mockApplicRepo.Object, mockPaymentRepo.Object, mockVisaRepo.Object); var result = logic.GetAgencyByName("TravelAround"); Assert.That(result.Number, Is.EqualTo(2)); mockAgRepo.Verify(repo => repo.GetAll(), Times.Once); }