diff options
| author | Murilo Ijanc <[email protected]> | 2026-07-26 12:42:38 -0300 |
|---|---|---|
| committer | Murilo Ijanc <[email protected]> | 2026-07-26 13:10:34 -0300 |
| commit | a2b10fd494fb389e556e40134031eb86e56e11e7 (patch) | |
| tree | 08b6df8a06f2c7c15488b90d57a6d8286cd57a22 /tests/Cepis.Tests/ModelTests.cs | |
| download | csharp-a2b10fd494fb389e556e40134031eb86e56e11e7.tar.gz | |
Initial importv0.1.0
Diffstat (limited to 'tests/Cepis.Tests/ModelTests.cs')
| -rw-r--r-- | tests/Cepis.Tests/ModelTests.cs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/Cepis.Tests/ModelTests.cs b/tests/Cepis.Tests/ModelTests.cs new file mode 100644 index 0000000..7d9d0d6 --- /dev/null +++ b/tests/Cepis.Tests/ModelTests.cs @@ -0,0 +1,68 @@ +using System.Text.Json; + +namespace Cepis.Tests; + +/// <summary>The data objects on their own, with no server involved.</summary> +public sealed class ModelTests +{ + [Fact] + public void EveryFieldDefaultsToTheEmptyString() + { + var address = new Address(); + + Assert.Equal("", address.Cep); + Assert.Equal("", address.Logradouro); + Assert.Equal("", address.Siafi); + Assert.Null(address.Geo); + } + + [Fact] + public void FormattedCepAddsTheMask() => + Assert.Equal("01001-000", new Address { Cep = "01001000" }.FormattedCep); + + [Fact] + public void FormattedCepLeavesAnythingElseAlone() => + Assert.Equal("123", new Address { Cep = "123" }.FormattedCep); + + [Fact] + public void TwoAddressesForTheSamePlaceAreEqual() + { + var one = new Address { Cep = "01001000", Localidade = "São Paulo" }; + var other = new Address { Cep = "01001000", Localidade = "São Paulo" }; + + Assert.Equal(one, other); + Assert.Equal(one.GetHashCode(), other.GetHashCode()); + } + + [Fact] + public void EqualityIgnoresFieldsThisLibraryDoesNotModel() + { + var plain = new Address { Cep = "01001000" }; + var enriched = plain with + { + Extra = new Dictionary<string, JsonElement>(StringComparer.Ordinal) + { + ["cep_pai"] = JsonDocument.Parse("\"01000000\"").RootElement, + }, + }; + + Assert.Equal(plain, enriched); + Assert.DoesNotContain("cep_pai", enriched.ToString(), StringComparison.Ordinal); + } + + [Fact] + public void TheCoordinateIsPreciseOnlyForAStreet() + { + Assert.True(new Geo { Precisao = "logradouro" }.IsPrecise); + Assert.False(new Geo { Precisao = "localidade" }.IsPrecise); + Assert.False(new Geo().IsPrecise); + } + + [Fact] + public void HealthIsOkOnlyForTheDocumentedStatus() + { + Assert.True(new Health { Status = "ok" }.Ok); + Assert.False(new Health { Status = "degradado" }.Ok); + Assert.False(new Health().Ok); + } +} |