public void Test_Calculate_Tax_Procedure_Checks_And_Returns_Error_Message_If_Data_Is_Not_Valid() { /// Arrange var expectedEmployees = new List <Employee> { DataHelper.GetEmployeeA(), DataHelper.GetEmployeeB(), DataHelper.GetEmployeeC() }; var expectedTaxForEmployees = new List <EmployeeTax> { DataHelper.GetTaxForEmployeeA(), DataHelper.GetTaxForEmployeeA() }; this._taxCalculatorService.Setup(p => p.Calculate(DataHelper.GetEmployeeA(), Constants.TaxYear)).Returns(DataHelper.GetTaxForEmployeeA()); /// Act var viewModel = new EmployeeViewModel(this._employeeService.Object, this._taxCalculatorService.Object); viewModel.CalculateTaxForEmployees(expectedEmployees, Constants.TaxYear); /// Assert Assert.AreNotEqual(viewModel.ErrorMessage, string.Empty); Assert.IsFalse(viewModel.IsAllDataValid); Assert.AreEqual(viewModel.ErrorMessage, InvalidInput); this._taxCalculatorService.Verify(p => p.Calculate(It.IsAny <Employee>(), It.IsAny <int>()), Times.AtLeastOnce); this._employeeService.VerifyAll(); }
public void Test_Calculate_Tax_Calculates_All_Tax_details_Successfully() { /// Arrange var expectedEmployees = new List <Employee> { DataHelper.GetEmployeeA() }; var expectedTaxForEmployees = new List <EmployeeTax> { DataHelper.GetTaxForEmployeeA() }; this._taxCalculatorService.Setup(p => p.Calculate(It.IsAny <Employee>(), It.IsAny <int>())).Returns(DataHelper.GetTaxForEmployeeA()); /// Act var viewModel = new EmployeeViewModel(this._employeeService.Object, this._taxCalculatorService.Object); var actual = viewModel.CalculateTaxForEmployees(expectedEmployees, Constants.TaxYear); /// Assert Assert.AreEqual(viewModel.ErrorMessage, string.Empty); Assert.IsTrue(viewModel.IsAllDataValid); Assert.AreEqual(expectedTaxForEmployees.Count, actual.Count); Assert.AreEqual(expectedTaxForEmployees[0].GrossIncome, actual[0].GrossIncome); Assert.AreEqual(expectedTaxForEmployees[0].NetIncome, actual[0].NetIncome); Assert.AreEqual(expectedTaxForEmployees[0].IncomeTax, actual[0].IncomeTax); Assert.AreEqual(expectedTaxForEmployees[0].SuperAmount, actual[0].SuperAmount); Assert.AreEqual(expectedTaxForEmployees[0].PayPeriod, actual[0].PayPeriod); Assert.AreEqual(expectedTaxForEmployees[0].EmployeeName, actual[0].EmployeeName); this._taxCalculatorService.Verify(p => p.Calculate(It.IsAny <Employee>(), It.IsAny <int>()), Times.Once); this._employeeService.VerifyAll(); this._taxCalculatorService.VerifyAll(); }