diff --git a/src/Cnpj.cs b/src/Cnpj.cs index a5f45bf..283f825 100644 --- a/src/Cnpj.cs +++ b/src/Cnpj.cs @@ -142,7 +142,7 @@ public static Cnpj Parse(string value) /// contains a valid Cnpj. If the method returns false, result equals Empty. /// /// true if the parse operation was successful; otherwise, false. - public static bool TryParse(string value, out Cnpj result) + public static bool TryParse(string? value, out Cnpj result) { var normalized = Format(value); if (!Validate(normalized)) diff --git a/src/Cpf.cs b/src/Cpf.cs index 2b33258..701dd2b 100644 --- a/src/Cpf.cs +++ b/src/Cpf.cs @@ -132,7 +132,7 @@ public static Cpf Parse(string value) /// contains a valid Cpf. If the method returns false, result equals Empty. /// /// true if the parse operation was successful; otherwise, false. - public static bool TryParse(string value, out Cpf result) + public static bool TryParse(string? value, out Cpf result) { var normalized = Format(value, withMask: false); if (!Validate(normalized)) diff --git a/src/CpfCnpj.cs b/src/CpfCnpj.cs index f13ea89..4e0b55e 100644 --- a/src/CpfCnpj.cs +++ b/src/CpfCnpj.cs @@ -170,7 +170,7 @@ public static CpfCnpj Parse(string value) /// contains a valid CpfCnpj. If the method returns false, result equals Empty. /// /// true if the parse operation was successful; otherwise, false. - public static bool TryParse(string value, out CpfCnpj result) + public static bool TryParse(string? value, out CpfCnpj result) { var type = Validate(value); if (type is null) diff --git a/tests/BrazilModels.Tests/CnpjTests.cs b/tests/BrazilModels.Tests/CnpjTests.cs index d837949..f496c1a 100644 --- a/tests/BrazilModels.Tests/CnpjTests.cs +++ b/tests/BrazilModels.Tests/CnpjTests.cs @@ -3,6 +3,7 @@ namespace BrazilModels.Tests; +[TestFixture] public class CnpjTests { [Test] @@ -49,7 +50,8 @@ public void ShouldCompareAsString(ValidCnpj first, ValidCnpj second) { var cnpj1 = new Cnpj(first); var cnpj2 = new Cnpj(second); - var strCompare = string.Compare(first.Cleared, second.Cleared, StringComparison.OrdinalIgnoreCase); + var strCompare = string.Compare(first.Cleared, second.Cleared, + StringComparison.OrdinalIgnoreCase); cnpj1.CompareTo(cnpj2).Should().Be(strCompare); } @@ -187,12 +189,19 @@ public void ShouldCreateUnformattedCnpj(CleanCnpj input) } [PropertyTest] - public void ShouldThrowInvalidFormattedCnpj(InvalidCnpj input) + public void ShouldReturnFalseForInvalidFormattedCnpj(InvalidCnpj input) { Cnpj.TryParse(input.Value, out var cnpj).Should().BeFalse(); cnpj.Value.Should().Be(Cnpj.Empty); } + [Test] + public void ShouldReturnFalseForNullString() + { + Cnpj.TryParse(null, out var cnpj).Should().BeFalse(); + cnpj.Value.Should().Be(Cnpj.Empty); + } + [PropertyTest] public void ShouldThrowInvalidUnformattedCnpj(InvalidCnpj input) { diff --git a/tests/BrazilModels.Tests/TaxIdTests.cs b/tests/BrazilModels.Tests/CpfCnpjTests.cs similarity index 95% rename from tests/BrazilModels.Tests/TaxIdTests.cs rename to tests/BrazilModels.Tests/CpfCnpjTests.cs index ea8fb74..717dbca 100644 --- a/tests/BrazilModels.Tests/TaxIdTests.cs +++ b/tests/BrazilModels.Tests/CpfCnpjTests.cs @@ -1,6 +1,7 @@ namespace BrazilModels.Tests; -public class TaxIdTests +[TestFixture] +public class CpfCnpjTests { [Test] public void ShouldHaveEmptyFormattedTaxId() => @@ -14,7 +15,7 @@ public void ShouldHaveEmptyTaxId() => public void NewTaxIdShouldBeEmpty() => new CpfCnpj().Should().Be(CpfCnpj.Empty); - public class TaxIdCnpjTests + public class CnpjTests { [PropertyTest] public void ShouldHaveCnpjType(ValidCnpj cnpj) => @@ -52,7 +53,8 @@ public void ShouldCompareAsString(ValidCnpj first, ValidCnpj second) { var cnpj1 = new CpfCnpj(first); var cnpj2 = new CpfCnpj(second); - var strCompare = string.Compare(first.Cleared, second.Cleared, StringComparison.OrdinalIgnoreCase); + var strCompare = string.Compare(first.Cleared, second.Cleared, + StringComparison.OrdinalIgnoreCase); cnpj1.CompareTo(cnpj2).Should().Be(strCompare); } @@ -167,12 +169,19 @@ public void ShouldCreateUnformattedTaxId(CleanCnpj input) } [PropertyTest] - public void ShouldThrowInvalidFormattedTaxId(InvalidCnpj input) + public void ShouldReturnFalseForInvalidFormattedTaxId(InvalidCnpj input) { CpfCnpj.TryParse(input.Value, out var cnpj).Should().BeFalse(); cnpj.Value.Should().Be(CpfCnpj.Empty); } + [Test] + public void ShouldReturnFalseForNullString() + { + CpfCnpj.TryParse(null, out var cnpj).Should().BeFalse(); + cnpj.Value.Should().Be(CpfCnpj.Empty); + } + [PropertyTest] public void ShouldThrowInvalidUnformattedTaxId(InvalidCnpj input) { @@ -182,9 +191,8 @@ public void ShouldThrowInvalidUnformattedTaxId(InvalidCnpj input) } } - public class TaxIdCpfTests + public class CpfTests { - [PropertyTest] public void ShouldHaveCnpjType(ValidCpf cpf) => new CpfCnpj(cpf).Type.Should().Be(DocumentType.CPF); @@ -221,7 +229,8 @@ public void ShouldCompareAsString(ValidCpf first, ValidCpf second) { var cpf1 = new CpfCnpj(first); var cpf2 = new CpfCnpj(second); - var strCompare = string.Compare(first.Cleared, second.Cleared, StringComparison.OrdinalIgnoreCase); + var strCompare = string.Compare(first.Cleared, second.Cleared, + StringComparison.OrdinalIgnoreCase); cpf1.CompareTo(cpf2).Should().Be(strCompare); } diff --git a/tests/BrazilModels.Tests/CpfTests.cs b/tests/BrazilModels.Tests/CpfTests.cs index 19f82f8..db7989d 100644 --- a/tests/BrazilModels.Tests/CpfTests.cs +++ b/tests/BrazilModels.Tests/CpfTests.cs @@ -1,5 +1,6 @@ namespace BrazilModels.Tests; +[TestFixture] public class CpfTests { [Test] @@ -46,7 +47,8 @@ public void ShouldCompareAsString(ValidCpf first, ValidCpf second) { var cpf1 = new Cpf(first); var cpf2 = new Cpf(second); - var strCompare = string.Compare(first.Cleared, second.Cleared, StringComparison.OrdinalIgnoreCase); + var strCompare = string.Compare(first.Cleared, second.Cleared, + StringComparison.OrdinalIgnoreCase); cpf1.CompareTo(cpf2).Should().Be(strCompare); } @@ -185,12 +187,19 @@ public void ShouldCreateUnformattedCpf(CleanCpf input) } [PropertyTest] - public void ShouldThrowInvalidFormattedCpf(InvalidCpf input) + public void ShouldReturnFalseForInvalidFormattedCpf(InvalidCpf input) { Cpf.TryParse(input.Value, out var cpf).Should().BeFalse(); cpf.Value.Should().Be(Cpf.Empty); } + [Test] + public void ShouldReturnFalseForNullString() + { + Cpf.TryParse(null, out var cnpj).Should().BeFalse(); + cnpj.Value.Should().Be(Cpf.Empty); + } + [PropertyTest] public void ShouldThrowInvalidUnformattedCpf(InvalidCpf input) { diff --git a/tests/BrazilModels.Tests/TypeConvertersTests.cs b/tests/BrazilModels.Tests/TypeConvertersTests.cs index 368b1c8..c0cede1 100644 --- a/tests/BrazilModels.Tests/TypeConvertersTests.cs +++ b/tests/BrazilModels.Tests/TypeConvertersTests.cs @@ -2,8 +2,10 @@ using BrazilModels; using BrazilModels.Tests.Utils; +#pragma warning disable S2187 namespace BrazilModels.Tests; +[TestFixture] public class TypeConverterTests : BaseTest { public class CpfTests @@ -102,7 +104,7 @@ public void ConvertToShouldWorkString(ValidCnpj input) } } - public class TaxIdTests + public class CpfCnpjTests { [Test] public void ConverterIdValidShouldBeTrueToString()