Adding
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
|
||||
namespace Application.UnitTests.Extensions
|
||||
{
|
||||
public class PayoutProfileCalculateTestInput
|
||||
{
|
||||
public PayoutProfileCalculateTestInput(Product product, Role role, PayoutType type, PayoutProfile expectedProfile, int goal,
|
||||
int actual, int expectedPay, double expectedPercentage)
|
||||
{
|
||||
Product = product;
|
||||
Role = role;
|
||||
Type = type;
|
||||
ExpectedProfile = expectedProfile;
|
||||
Goal = goal;
|
||||
Actual = actual;
|
||||
ExpectedPay = expectedPay;
|
||||
ExpectedPercentage = expectedPercentage;
|
||||
}
|
||||
|
||||
public Product Product { get; set; }
|
||||
public Role Role { get; set; }
|
||||
public PayoutType Type { get; set; }
|
||||
public PayoutProfile ExpectedProfile { get; set; }
|
||||
public int Goal { get; set; }
|
||||
public int Actual { get; set; }
|
||||
public int ExpectedPay { get; set; }
|
||||
public double ExpectedPercentage { get; set; }
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Application.UnitTests.Extensions
|
||||
{
|
||||
public class PayoutProfileExtensionsTest
|
||||
{
|
||||
private readonly DateTime _nonOverriddenDateTime = DateTime.ParseExact("2021-12-01", "yyyy-MM-dd", CultureInfo.InvariantCulture);
|
||||
|
||||
[Test]
|
||||
public void Payout_Basic()
|
||||
{
|
||||
var product = Product.Vehicle;
|
||||
var role = Role.BM;
|
||||
var expectedProfile = PayoutProfile.BMVehicle;
|
||||
var goal = 10;
|
||||
var actual = 10;
|
||||
var expectedPay = 125;
|
||||
var expectedPercentage = 1.0;
|
||||
|
||||
var profile = PayoutProfile.LookupProfile(product, role, PayoutType.Department);
|
||||
Assert.NotNull(profile);
|
||||
Assert.AreEqual(profile, expectedProfile);
|
||||
|
||||
double percentage = actual / (double)goal;
|
||||
Assert.AreEqual(expectedPercentage, percentage);
|
||||
|
||||
var range = profile.FindPayoutRange(percentage, _nonOverriddenDateTime);
|
||||
Assert.IsTrue(range.IsInRange(percentage));
|
||||
|
||||
var result = profile.CalculateLineItemPayout(goal, actual, _nonOverriddenDateTime);
|
||||
Assert.AreEqual(expectedPay, result);
|
||||
}
|
||||
|
||||
[TestCase(0, 0)]
|
||||
[TestCase(0.12, 0.1)]
|
||||
[TestCase(41.62, 33.3)]
|
||||
[TestCase(83.38, 66.7)]
|
||||
[TestCase(41.25, 33)]
|
||||
[TestCase(31.25, 25)]
|
||||
[TestCase(123.75, 99)]
|
||||
[TestCase(125.00, 100)]
|
||||
public void Payout_Basic_Percentage(decimal expectedPayout, decimal fromPercentage)
|
||||
{
|
||||
var product = Product.Vehicle;
|
||||
var role = Role.BM;
|
||||
var expectedProfile = PayoutProfile.BMVehicle;
|
||||
var goal = 10;
|
||||
var actual = 10;
|
||||
var expectedPay = expectedPayout;
|
||||
var expectedPercentage = 1.0;
|
||||
|
||||
var profile = PayoutProfile.LookupProfile(product, role, PayoutType.Department);
|
||||
Assert.NotNull(profile);
|
||||
Assert.AreEqual(profile, expectedProfile);
|
||||
|
||||
double percentage = actual / (double)goal;
|
||||
Assert.AreEqual(expectedPercentage, percentage);
|
||||
|
||||
var range = profile.FindPayoutRange(percentage, _nonOverriddenDateTime);
|
||||
Assert.IsTrue(range.IsInRange(percentage));
|
||||
|
||||
var result = profile.CalculateLineItemPayout(goal, actual, _nonOverriddenDateTime, fromPercentage);
|
||||
Assert.AreEqual(expectedPay, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Payout_All_Test()
|
||||
{
|
||||
var payoutProfiles = PayoutProfile.PayoutProfiles;
|
||||
var testInputs = new[]
|
||||
{
|
||||
new PayoutProfileCalculateTestInput(Product.Mortgage, Role.BM, PayoutType.Department,
|
||||
payoutProfiles.Find(payout => payout.Id == 1), 10, 15, 325, 1.5),
|
||||
new PayoutProfileCalculateTestInput(Product.Mortgage, Role.ABM, PayoutType.Department,
|
||||
payoutProfiles.Find(payout => payout.Id == 2), 8, 10, 175, 1.25),
|
||||
new PayoutProfileCalculateTestInput(Product.Mortgage, Role.MSCTeamLead, PayoutType.Department,
|
||||
payoutProfiles.Find(payout => payout.Id == 5), 8, 10, 75, 1.25),
|
||||
new PayoutProfileCalculateTestInput(Product.Mortgage, Role.MSCTeamLead, PayoutType.Personal,
|
||||
payoutProfiles.Find(payout => payout.Id == 4), 8, 10, 150, 1.25),
|
||||
new PayoutProfileCalculateTestInput(Product.Vehicle, Role.BM, PayoutType.Department,
|
||||
payoutProfiles.Find(payout => payout.Id == 6), 10, 10, 125, 1.0),
|
||||
new PayoutProfileCalculateTestInput(Product.Vehicle, Role.PFO, PayoutType.Personal,
|
||||
payoutProfiles.Find(payout => payout.Id == 8), 4, 3, 25, 0.75),
|
||||
// You can't test GAP here, it doesn't pay out like that. @see GapPayoutStrategy
|
||||
};
|
||||
|
||||
foreach (var testInput in testInputs)
|
||||
{
|
||||
var profile = PayoutProfile.LookupProfile(testInput.Product, testInput.Role, testInput.Type);
|
||||
Assert.NotNull(profile);
|
||||
Assert.AreEqual(profile, testInput.ExpectedProfile);
|
||||
Assert.AreEqual(profile.Product, testInput.Product);
|
||||
Assert.IsTrue(profile.Roles.Contains(testInput.Role));
|
||||
|
||||
double percentage = testInput.Actual / (double)testInput.Goal;
|
||||
Assert.AreEqual(testInput.ExpectedPercentage, percentage);
|
||||
|
||||
var range = profile.FindPayoutRange(percentage, _nonOverriddenDateTime);
|
||||
Assert.IsTrue(range.IsInRange(percentage));
|
||||
var result = profile.CalculateLineItemPayout(testInput.Goal, testInput.Actual, _nonOverriddenDateTime);
|
||||
Assert.AreEqual(testInput.ExpectedPay, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user