Untitled
unknown
plain_text
a year ago
4.8 kB
23
Indexable
Never
using NUnit.Framework; using System; using System.Collections.Generic; namespace YourNamespace.Tests { [TestFixture] public class SingleRangeFeeCalculationEngineTests { private SingleRangeFeeCalculationEngine _feeCalculationEngine; [SetUp] public void Setup() { _feeCalculationEngine = new SingleRangeFeeCalculationEngine(); } [TestCase(1, "2023-08-14", 1000, null, 0.1, ExpectedResult = 100)] [TestCase(2, "2023-08-14", null, 10, 0.05, ExpectedResult = 0.5)] [TestCase(3, "2023-08-14", 1500, null, 0.15, ExpectedResult = 225)] [TestCase(4, "2023-08-14", null, 15, 0.03, ExpectedResult = 0.45)] [TestCase(5, "2023-08-14", 500, 5, 0.2, ExpectedResult = 20)] [TestCase(6, "2023-08-14", 2000, null, 0.05, ExpectedResult = 100)] [TestCase(7, "2023-08-14", null, 20, 0.1, ExpectedResult = 2)] [TestCase(8, "2023-08-14", 1200, null, 0.12, ExpectedResult = 144)] [TestCase(9, "2023-08-14", null, 8, 0.06, ExpectedResult = 0.48)] [TestCase(10, "2023-08-14", 300, 3, 0.15, ExpectedResult = 13.5)] [TestCase(11, "2023-08-14", 1000, 10, 0.1, 0.05, ExpectedResult = 100)] [TestCase(12, "2023-08-14", null, 12, 0.2, 0.15, ExpectedResult = 0.3)] [TestCase(13, "2023-08-14", null, null, 0.1)] public decimal Calculate_ValidInput_ReturnsExpectedAmount(int planId, string asOfDateString, decimal? assetValue, int? participantValue, double feeRate, params double[] additionalFeeRates) { var input = new RangeFeeCalculationInputRecord { PlanId = planId, AsOfDate = DateTime.Parse(asOfDateString), AssetCalculationValue = assetValue, ParticipantCalculationValue = participantValue, RangeBasedFeeRates = new List<RangeBasedFeeRateRecord> { new RangeBasedFeeRateRecord { FeeRate = (decimal)feeRate } } }; foreach (var additionalFeeRate in additionalFeeRates) { input.RangeBasedFeeRates.Add(new RangeBasedFeeRateRecord { FeeRate = (decimal)additionalFeeRate }); } var result = _feeCalculationEngine.Calculate(input); return result.Amount; } [TestCase(1, "2023-08-14", 1000, 10, 0.1, 0.05)] [TestCase(2, "2023-08-14", null, null, 0.1)] [TestCase(3, "2023-08-14", 1500, 20, 0.15, 0.2)] [TestCase(4, "2023-08-14", null, 8, 0.07, 0.09)] [TestCase(5, "2023-08-14", 500, null, 0.18, 0.25)] [TestCase(6, "2023-08-14", 2000, 5, 0.12, 0.08)] [TestCase(7, "2023-08-14", null, 15, 0.05, 0.07)] [TestCase(8, "2023-08-14", 1200, 20, 0.08, 0.1)] [TestCase(9, "2023-08-14", null, null, 0.2)] [TestCase(10, "2023-08-14", 300, 3, 0.18, 0.22)] public void Calculate_InvalidInput_MultipleValues(int planId, string asOfDateString, decimal? assetValue, int? participantValue, params double[] feeRates) { var input = new RangeFeeCalculationInputRecord { PlanId = planId, AsOfDate = DateTime.Parse(asOfDateString), AssetCalculationValue = assetValue, ParticipantCalculationValue = participantValue, RangeBasedFeeRates = new List<RangeBasedFeeRateRecord>() }; foreach (var feeRate in feeRates) { input.RangeBasedFeeRates.Add(new RangeBasedFeeRateRecord { FeeRate = (decimal)feeRate }); } Assert.Throws<ArgumentException>(() => _feeCalculationEngine.Calculate(input)); } [TestCase(1, "2023-08-14", null, null, 0.1)] [TestCase(2, "2023-08-14", 1000, 10, 0.1, 0.05)] public void Calculate_InvalidInput_NullValuesOrMultipleValues(int planId, string asOfDateString, decimal? assetValue, int? participantValue, params double[] feeRates) { var input = new RangeFeeCalculationInputRecord { PlanId = planId, AsOfDate = DateTime.Parse(asOfDateString), AssetCalculationValue = assetValue, ParticipantCalculationValue = participantValue, RangeBasedFeeRates = new List<RangeBasedFeeRateRecord>() }; foreach (var feeRate in feeRates) { input.RangeBasedFeeRates.Add(new RangeBasedFeeRateRecord { FeeRate = (decimal)feeRate }); } Assert.Throws<ArgumentException>(() => _feeCalculationEngine.Calculate(input)); } // Agrega más casos de prueba para otros escenarios negativos } }