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

57 lines
2.1 KiB
C#

using ShippingCosts.Contracts;
using ShippingCosts.Implementations;
namespace ShippingCosts.Test;
public sealed class CountryDistanceProviderTests
{
private readonly ICountryDistanceProvider _provider = new CountryDistanceProvider();
[Theory]
[InlineData("India", true)]
[InlineData("Chile", false)]
public void IsPossibleCountry(string country, bool isAvailable)
{
_provider.IsPossibleCountry(country)
.Should().Be(isAvailable);
}
[Theory]
[InlineData("Brazil", 9820, false, false)]
[InlineData("France", 1036, false, true)]
[InlineData("Italy", 763, true, true)]
[InlineData("Japan", 9278, false, false)]
[InlineData("Switzerland", 692, true, false)]
public void GetDistanceTo_ExistingCountry(string countryName, int expectedDistance, bool expectedIsDirectNeighbor,
bool expectedIsEuMember)
{
_provider.GetDistanceTo(countryName)
.Should().NotBeNull("country exists and is in database")
.And.BeOfType<CountryDistanceInformation>()
.And.Match<CountryDistanceInformation>(x =>
x.ApproxDistance == expectedDistance &&
x.IsDirectNeighbor == expectedIsDirectNeighbor &&
x.IsEuMember == expectedIsEuMember);
}
[Theory]
[InlineData("NonExistingCountry")]
[InlineData("Atlantis")]
public void GetDistanceTo_NonExistingCountry(string countryName)
{
_provider.GetDistanceTo(countryName).Should().BeNull("country does not exist");
}
[Fact]
public void GetDistanceTo_EmptyCountryName()
{
_provider.GetDistanceTo(string.Empty).Should().BeNull("country name is empty");
}
[Fact]
public void GetDistanceTo_NotDefinedCountry()
{
_provider.GetDistanceTo("Sweden")
.Should().BeNull("country exists, but is not in internal database");
}
}