Exemplo n.º 1
0
        public void GetAll()
        {
            var repository = new Mock<IRepository<Employer>>();
            var controller = new EmployerController(repository.Object, null, null, null, null, null, null);
            var expected = new List<Employer>();

            repository.Setup(x => x.FindAll()).Returns(expected);
            var actual = controller.Get();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemplo n.º 2
0
        public void GetById()
        {
            var repository = new Mock<IRepository<Employer>>();
            var totalCostCalculator = new Mock<ITotalCostCalculator>();
            var costPerPayPeriodCalculator = new Mock<ICostPerPayPeriodCalculator>();
            var salaryPerPayPeriodCalculator = new Mock<IGrossSalaryPerPayPeriodCalculator>();
            var netSalaryPerPayPeriodCalculator = new Mock<INetSalaryPerPayPeriodCalculator>();
            var totalDependentCostCalculator = new Mock<ITotalDependentCostCalculator>();
            var dependentCostPerPayPeriodCalculator = new Mock<IDependentCostPerPayPeriodCalculator>();
            var controller = new EmployerController(repository.Object, totalCostCalculator.Object, costPerPayPeriodCalculator.Object, salaryPerPayPeriodCalculator.Object, netSalaryPerPayPeriodCalculator.Object, totalDependentCostCalculator.Object, dependentCostPerPayPeriodCalculator.Object);
            var expectedEmployer = new Employer {
                Employees = new List<Employee> {
                    new Employee()
                }
            };
            var employerId = 1;
            var expectedTotalCost = 20;
            var expectedCostPerPeriod = 2;
            var expectedGrossSalaryPerPayPeriod = 3;
            var expectedNetSalaryPerPayPeriod = 10;
            var expectedTotalDependentCost = 12;
            var expectedDependentCostPerPeriod = 12;

            repository.Setup(x => x.Find(employerId)).Returns(expectedEmployer);
            foreach (var employee in expectedEmployer.Employees) {
                totalCostCalculator.Setup(x => x.Calculate(employee)).Returns(expectedTotalCost);
                costPerPayPeriodCalculator.Setup(x => x.Calculate(employee)).Returns(expectedCostPerPeriod);
                salaryPerPayPeriodCalculator.Setup(x => x.Calculate(employee)).Returns(expectedGrossSalaryPerPayPeriod);
                netSalaryPerPayPeriodCalculator.Setup(x => x.Calculate(employee)).Returns(expectedNetSalaryPerPayPeriod);
                totalDependentCostCalculator.Setup(x => x.Calculate(employee)).Returns(expectedTotalDependentCost);
                dependentCostPerPayPeriodCalculator.Setup(x => x.Calculate(employee)).Returns(expectedDependentCostPerPeriod);
            }
            var actual = controller.Get(employerId);

            Assert.AreEqual(expectedEmployer, actual);
            foreach (var employee in actual.Employees) {
                Assert.AreEqual(expectedTotalCost, employee.TotalCost);
                Assert.AreEqual(expectedCostPerPeriod, employee.CostPerPayPeriod);
                Assert.AreEqual(expectedGrossSalaryPerPayPeriod, employee.GrossSalaryPerPayPeriod);
                Assert.AreEqual(expectedNetSalaryPerPayPeriod, employee.NetSalaryPerPayPeriod);
                Assert.AreEqual(expectedTotalDependentCost, employee.TotalDependentCost);
                Assert.AreEqual(expectedDependentCostPerPeriod, employee.DependentCostPerPayPeriod);
            }
        }