ex-int-04-shipping-cost/ShippingCosts.Test/ShippingCostCalculatorBaseTests.cs
github-classroom[bot] 5db225db88
Initial commit
2025-04-29 15:01:53 +00:00

56 lines
2.1 KiB
C#

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<IShippingCostCalculator>("base class has to implement the interface");
}
public static TheoryData<IMeasuredBox, int, string> SumOfLongestAndShortestSidesData()
{
return new TheoryData<IMeasuredBox, int, string>
{
{ 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<IMeasuredBox>();
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);
}
}