using ShippingCosts.Contracts; using ShippingCosts.Implementations; namespace ShippingCosts.Test; public sealed class LuxuryShippingCostCalculatorTests : ShippingCostCalculatorBaseTestBase { private readonly LuxuryShippingCostCalculator _calculator = new(CreateDefaultProvider()); [Fact] public void CarrierName() { _calculator.CarrierName.Should() .NotBeNullOrWhiteSpace() .And.Be("LuxuryShipping"); } [Theory] [MemberData(nameof(CalculateShippingCostsData))] public void CalculateShippingCosts(string targetCountry, IMeasuredBox box, decimal? expectedCost) { decimal? shippingCosts = _calculator.CalculateShippingCosts(targetCountry, box); if (expectedCost is null) { shippingCosts.Should().BeNull(); } else { shippingCosts.Should().NotBeNull() .And.Be(expectedCost); } } public static TheoryData CalculateShippingCostsData() => new() { { "France", CreateBox(5, 10, 15, 2.2), 501.1875M }, { "Brazil", CreateBox(30, 20, 10, 0.85), 4444M }, { "Portugal", CreateBox(30, 20, 10, 0.85), null } }; private static ICountryDistanceProvider CreateDefaultProvider() { const string France = "France"; const string Brazil = "Brazil"; var provider = Substitute.For(); provider.IsPossibleCountry(Arg.Is(c => c == France || c == Brazil)) .Returns(true); provider.GetDistanceTo(Arg.Is(France)) .Returns(new CountryDistanceInformation(891, true, false)); provider.GetDistanceTo(Arg.Is(Brazil)) .Returns(new CountryDistanceInformation(7432, false, false)); return provider; } }