コード例 #1
0
ファイル: LogicTestsVisa.cs プロジェクト: poli201210/MyApp
        public void TestVisaDaysBeforeLegalExtensions()
        {
            Mock <IVisaRepository>      mockVisaRepo      = new Mock <IVisaRepository>(MockBehavior.Loose);
            Mock <IApplicantRepository> mockApplicantRepo = new Mock <IApplicantRepository>(MockBehavior.Loose);

            List <Visa> listvisa = new List <Visa>()
            {
                new Visa()
                {
                    VisaId = 1, VisaApplId = 2, VisaDuration = 30
                },
                new Visa()
                {
                    VisaId = 2, VisaApplId = 1, VisaDuration = 90
                },
                new Visa()
                {
                    VisaId = 3, VisaApplId = 4, VisaDuration = 70
                },
                new Visa()
                {
                    VisaId = 7, VisaApplId = 7, VisaDuration = 61
                },
            };
            List <Applicant> listapp = new List <Applicant>()
            {
                new Applicant()
                {
                    ApplId = 2, ApplEmail = "*****@*****.**"
                },
                new Applicant()
                {
                    ApplId = 1, ApplEmail = "*****@*****.**"
                },
                new Applicant()
                {
                    ApplId = 4, ApplEmail = "*****@*****.**"
                },
                new Applicant()
                {
                    ApplId = 7, ApplEmail = "*****@*****.**"
                },
            };
            List <VisaDaysBeforeLegalExtension> expectedExten = new List <VisaDaysBeforeLegalExtension>()
            {
                new VisaDaysBeforeLegalExtension()
                {
                    VisaId = 1, Visadays = 0, ApplEmail = "*****@*****.**"
                },
                new VisaDaysBeforeLegalExtension()
                {
                    VisaId = 7, Visadays = 31, ApplEmail = "*****@*****.**"
                },
            };

            mockVisaRepo.Setup(repo => repo.GetAll()).Returns(listvisa.AsQueryable);
            mockApplicantRepo.Setup(repo => repo.GetAll()).Returns(listapp.AsQueryable);
            VisaLogic logic = new VisaLogic(mockApplicantRepo.Object, mockVisaRepo.Object);

            var result = logic.GetVisaActualDays();

            Assert.That(result, Is.EqualTo(expectedExten));
            mockVisaRepo.Verify(repo => repo.GetAll(), Times.Once);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: poli201210/MyApp
        private static void VisaBusinessLogicMenu()
        {
            VisaLogic visaLogic = new VisaLogic();

            Console.Clear();
            Console.WriteLine("Choose an action:");
            Console.WriteLine("1) List all visa");
            Console.WriteLine("2) Update visa");
            Console.WriteLine("3) Create new visa");
            Console.WriteLine("4) Delete unnecessary visa");
            Console.WriteLine("5) Show illegal visa for extension application");
            Console.Write("\r\nSelect an option: ");

            switch (Console.ReadLine())
            {
            case "1":
                Console.WriteLine("Table visa:");
                foreach (Visa v in visaLogic.GetAllVisas().ToList())
                {
                    Console.WriteLine($"visa_id: {v.VisaId},     visa_type:  {v.VisaType},    visa_duration:  {v.VisaDuration},   visa_lastDate: {v.VisaEnddate} ");
                }

                Console.ReadLine();
                break;

            case "2":
                Console.WriteLine("Update visa:");
                Console.WriteLine("Write Id of visa that need to modify");
                int takeId = int.Parse(Console.ReadLine());
                Console.WriteLine("Change the duration of visa:");
                int duration = int.Parse(Console.ReadLine());
                visaLogic.ChangeDays(takeId, duration);
                Console.WriteLine("Changes completed!");
                break;

            case "3":
                try
                {
                    Console.WriteLine("Create new visa:");
                    Console.WriteLine("write new id [9<]:");
                    int id = int.Parse(Console.ReadLine());
                    Console.WriteLine("Write existing applicant id [1-10]:");
                    int tourId = int.Parse(Console.ReadLine());
                    Console.WriteLine("Write type of visa:");
                    string visaType = Console.ReadLine();
                    Console.WriteLine("Enter duration (in days) that visa needs: ");
                    int period = int.Parse(Console.ReadLine());
                    Console.WriteLine("Enter the last date of visa [YYYY-MM-DD]: ");
                    DateTime lastDate = DateTime.Parse(Console.ReadLine());
                    Console.WriteLine("Write is visa is [approved] or [not approved]:");
                    string approving = Console.ReadLine();
                    visaLogic.CreateNewVisa(id, tourId, visaType, period, lastDate, approving);
                    Console.WriteLine("Visa created successfully!");
                    Console.ReadLine();
                }
                catch (Exception ex)
                {
                    string message = string.Empty;
                    if (ex is FormatException)
                    {
                        message = " Incorrect form ";
                    }
                    else
                    {
                        Console.WriteLine(ex.Message);
                    }

                    Console.WriteLine(message);
                }

                break;

            case "4":
                Console.WriteLine("Delete visa by id:");
                Console.WriteLine("Enter id:");
                int tempId = int.Parse(Console.ReadLine());
                visaLogic.RemoveOldVisa(tempId);
                Console.WriteLine("Visa deleted!");
                Console.ReadLine();
                break;

            case "5":
                Console.WriteLine("Show actual days left before application day: ");
                var visa = visaLogic.GetVisaActualDays();
                foreach (var item in visa)
                {
                    Console.WriteLine($"Visa_id: {item.VisaId}, Visa_days: {item.Visadays}, Applicant's email:{item.ApplEmail}");
                }

                Console.WriteLine("task output:");
                Task <IList <VisaDaysBeforeLegalExtension> > visaDaysExtensionTask = visaLogic.GetVisaActualDaysAsync();
                visaDaysExtensionTask.Wait();
                if (visaDaysExtensionTask.IsCompletedSuccessfully)
                {
                    foreach (var visatask in visaDaysExtensionTask.Result)
                    {
                        Console.WriteLine($"Visa id:{visatask.VisaId}, visa days:{visatask.Visadays} ");
                    }
                }

                Console.ReadLine();
                break;
            }
        }