using ShippingCosts.Contracts; using ShippingCosts.Implementations; namespace ShippingCosts.Test; public sealed class ShippingCostCalculatorBaseTests { [Theory] [MemberData(nameof(SumOfLongestAndShortestSidesData))] public void SumOfLongestAndShortestSides(IMeasuredBox box, int expectedResult, string reason) { TestCalculator.SumCalc(box).Should().Be(expectedResult, reason); } [Fact] public void ImplementsInterface() { new TestCalculator().Should() .BeAssignableTo("base class has to implement the interface"); } public static TheoryData SumOfLongestAndShortestSidesData() { return new TheoryData { { CreateBox(3, 4, 5), 8, "Longest: 5, Shortest: 3, Sum: 8" }, { CreateBox(1, 1, 1), 2, "Longest: 1, Shortest: 1, Sum: 2" }, { CreateBox(12, 12, 12), 24, "Longest: 12, Shortest: 12, Sum: 24" }, { CreateBox(10, 20, 30), 40, "Longest: 30, Shortest: 10, Sum: 40" }, { CreateBox(6, 5, 5), 11, "Longest: 6, Shortest: 5, Sum: 11" }, { CreateBox(0, 4, 5), 0, "impossible width" }, { CreateBox(4, 0, 5), 0, "impossible height" }, { CreateBox(4, 4, 0), 0, "impossible depth" }, { CreateBox(-2, 4, 5), 0, "impossible width" }, { CreateBox(4, -4, 5), 0, "impossible height" }, { CreateBox(2, 4, -5), 0, "impossible depth" } }; static IMeasuredBox CreateBox(int width, int height, int depth) { var box = Substitute.For(); box.Width.Returns(width); box.Height.Returns(height); box.Depth.Returns(depth); return box; } } private sealed class TestCalculator() : ShippingCostCalculatorBase(null!) { public override string CarrierName => string.Empty; public override decimal? CalculateShippingCosts(string targetCountry, IMeasuredBox box) => -1M; public static decimal SumCalc(IMeasuredBox box) => SumOfLongestAndShortestSides(box); } }