Exemplo n.º 1
0
        public void TestApplicantSalaryWithTaxes()
        {
            Mock <IApplicantRepository> mockApplicRepo  = new Mock <IApplicantRepository>(MockBehavior.Loose);
            Mock <IPaymentRepository>   mockPaymentRepo = new Mock <IPaymentRepository>(MockBehavior.Loose);

            List <Applicant> listapp = new List <Applicant>()
            {
                new Applicant()
                {
                    ApplId = 7, ApplName = "Kesha Bolbo", ApplIncome = 9000
                },
                new Applicant()
                {
                    ApplId = 9, ApplName = "Lexi Grey", ApplIncome = 6000
                },
                new Applicant()
                {
                    ApplId = 1, ApplName = "Arkagij Petrov", ApplIncome = 5000
                },
                new Applicant()
                {
                    ApplId = 3, ApplName = "Darina Kadurova", ApplIncome = 4100
                },
                new Applicant()
                {
                    ApplId = 4, ApplName = "Alina Komarova", ApplIncome = 3900
                },
            };
            List <Payment> listpayment = new List <Payment>()
            {
                new Payment()
                {
                    PayApplId = 7, PayIspayed = "payed"
                },
                new Payment()
                {
                    PayApplId = 9, PayIspayed = "payed"
                },
                new Payment()
                {
                    PayApplId = 1, PayIspayed = "payed"
                },
                new Payment()
                {
                    PayApplId = 3, PayIspayed = "not payed"
                },
                new Payment()
                {
                    PayApplId = 4, PayIspayed = "not payed"
                },
            };

            List <ApplicantSalaryWithTax> expectedTax = new List <ApplicantSalaryWithTax>()
            {
                new ApplicantSalaryWithTax()
                {
                    ApplicantName = "Kesha Bolbo", SalaryWithTax = 7650, Pay = "payed"
                },
                new ApplicantSalaryWithTax()
                {
                    ApplicantName = "Lexi Grey", SalaryWithTax = 5100, Pay = "payed"
                },
                new ApplicantSalaryWithTax()
                {
                    ApplicantName = "Arkagij Petrov", SalaryWithTax = 4250, Pay = "payed"
                },
                new ApplicantSalaryWithTax()
                {
                    ApplicantName = "Darina Kadurova", SalaryWithTax = 3485, Pay = "not payed"
                },
                new ApplicantSalaryWithTax()
                {
                    ApplicantName = "Alina Komarova", SalaryWithTax = 3315, Pay = "not payed"
                },
            };

            mockApplicRepo.Setup(repo => repo.GetAll()).Returns(listapp.AsQueryable);
            mockPaymentRepo.Setup(repo => repo.GetAll()).Returns(listpayment.AsQueryable);

            ApplicantLogic logic = new ApplicantLogic(mockApplicRepo.Object, mockPaymentRepo.Object);

            var result = logic.GetApplicantsSalaryWithTax();

            Assert.That(result, Is.EquivalentTo(expectedTax));
            mockApplicRepo.Verify(repo => repo.GetAll(), Times.Once);
        }
Exemplo n.º 2
0
        private static void ApplicantBusinessLogicMenu()
        {
            ApplicantLogic app_logic = new ApplicantLogic();

            Console.Clear();
            Console.WriteLine("Choose an action:");
            Console.WriteLine("1) Display all applicants");
            Console.WriteLine("2) Update an applicant");
            Console.WriteLine("3) Create an applicant");
            Console.WriteLine("4) Delete an applicant");
            Console.WriteLine("5) Show net salary");
            Console.WriteLine("6) exit");
            Console.Write("\r\nSelect an option: ");

            switch (Console.ReadLine())
            {
            case "1":
                Console.WriteLine("Table applicants:");
                foreach (Applicant item in app_logic.GetAllApplicants().ToList())
                {
                    Console.WriteLine($"Applicant Id: {item.ApplId}, Name: {item.ApplName}, Position: {item.ApplJob}, Income: {item.ApplIncome}");
                }

                Console.ReadLine();

                break;

            case "2":
                Console.WriteLine(" Update an applicant:");
                Console.WriteLine("Write id of person which needs to update:");
                int takeId = int.Parse(Console.ReadLine());
                Console.WriteLine("Write new email address of the applicant ");
                string newAddress = Console.ReadLine();
                app_logic.ChangeApplicantAddress(takeId, newAddress);
                break;

            case "3":
                try
                {
                    Console.WriteLine("Create new applicant");
                    Console.WriteLine("Create new id (id should be more than 10):");
                    int modifyId = int.Parse(Console.ReadLine());
                    Console.WriteLine("Create a name of applicant:");
                    string newName = Console.ReadLine();
                    Console.WriteLine("Write a gender");
                    string newgender = Console.ReadLine();
                    Console.WriteLine("Enter new email address: ");
                    string newMail = Console.ReadLine();
                    Console.WriteLine("Enter income: ");
                    int newIncome = int.Parse(Console.ReadLine());
                    Console.WriteLine("Type bithdate [yyyy-mm-dd]");
                    DateTime newBirthday = DateTime.Parse(Console.ReadLine());
                    Console.WriteLine("Whats the applicant's job?");
                    string newJob = Console.ReadLine();
                    app_logic.CreateNewApplicant(modifyId, newName, newgender, newMail, newIncome, newBirthday, newJob);
                }
                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 applicant by id:");
                Console.WriteLine("Enter id:");
                int del_Id = int.Parse(Console.ReadLine());
                app_logic.RemoveApplicant(del_Id);
                break;

            case "5":
                Console.WriteLine("Show Net salary:");
                var salary = app_logic.GetApplicantsSalaryWithTax();
                foreach (var sal in salary)
                {
                    Console.WriteLine($" Name: {sal.ApplicantName}, Net Salary: {sal.SalaryWithTax}, Taxes: {sal.Tax}, Ispayed: {sal.Pay} ");
                }

                Console.WriteLine("Tasks output:");
                Task <IList <ApplicantSalaryWithTax> > taxTask = app_logic.GetApplicantSalaryWithTaxAsync();
                taxTask.Wait();
                if (taxTask.IsCompletedSuccessfully)
                {
                    foreach (var task in taxTask.Result)
                    {
                        Console.WriteLine($"Person: {task.ApplicantName},    Net Salary: {task.SalaryWithTax}, Tax: {task.Tax}, IsPayed:{task.Pay}");
                    }
                }

                Console.ReadLine();
                break;
            }
        }