-
Notifications
You must be signed in to change notification settings - Fork 5
Developer notes
This section provides information on various projects in the CalculationsEngine solution.
The controller has the API endpoints exposed for the following calculations
- APPA
- Apportionment
- Basic Award
- Holiday
- Notice
- Projected Notice Date
- Redundancy Payments
- Refund of Notional Tax
Each calculation has a GET & POST method and basic functionality remains the same for all calculations. GET method serves the basic PING functionality and returns a successful ping response message when the service is up and running. POST method accepts a JSON input that is required to perform the particular calculation. The JSON string is converted to the respective request model and is validated for any model errors and also against the business rules that apply for that calculation. FluentValidation is used for validating against the business rules and they sit under the namespace Insolvency.CalculationsEngine.Redundancy.API.Infrastructure.Middlewares.Validators If the validation fails then a 400 Bad Request is returned. When the input is valid then the calculation is performed and a 200 OK response is returned with the results of the calculation.
Apart from the inputs provided by the user, there are few other inputs that is needed to perform each calculation. These inputs are fed in a JSON format and is available as look up values from the ConfigLookup.Json file. The following are the look ups that are available to perform the calculations:
- Statutory max for different date ranges
- Notional benefits monthly rate
- Benefit waiting days
- Tax rate
- NI rate
- NI threshold limits
- Preferential limit
Extension methods are used as helper methods that calculates to get immediate results that is used further in the calculation. An example of such method is GetServiceYearsAsync which returns the number of years in service from the employment start date to end date. Methods that are specific to the particular calculation can be found in Insolvency.CalculationsEngine.Redundancy.BL.Calculations and the ones that are shared between various calculations can be found in Insolvency.CalculationsEngine.Redundancy.Common.Extensions
Each calculation has its logic to perform the calculation and they are methods can be found in the Services in Insolvency.CalculationsEngine.Redundancy.BL layer. Each calculation is performed by referring to any required lookup values and to any extension methods. Each output values that are calculated is fed into the response model which is returned back to the controller.
The composite calculations like APPA, Holiday and Notice follow the same pattern like any other calculations. For example, APPA accepts either the Arrears of Pay input or the Protective Award input or both the inputs together in a single request. The controller validates both the inputs and then performs the calculation. In the APPACalculationService, the results for AP & PA are calculated separately and a composite logic is applied to select the best weeks that contribute to the claim amount(the best weeks have IsSelected set to True). When the request has list of inputs from both rp1 & rp14a input source, the composite calculation service chooses the inputs from one of the input source based on the total netEntitlement(number of days for Holiday composite). The results are then sent back to the controller as a single response model which contains the results for both AP & PA.
The CalculationsEngine solution contains a suite of unit tests to test the methods within the API, BL & the Common layer. A good test coverage can be found for all controllers, ConfigLookUp values, extension methods and the actual calculation. The tests are written using xUnit, Moq and FluentAssertion Nuget packages.