From 789b378300fb56512a22801638aa743e238f2121 Mon Sep 17 00:00:00 2001 From: Stuart Blackburn Date: Thu, 14 Mar 2024 20:27:34 +0000 Subject: [PATCH 1/6] task: updated nugets --- src/Primitively.Abstractions/Primitively.Abstractions.csproj | 2 +- .../Primitively.AspNetCore.Mvc.csproj | 2 +- test/Acme.TestLib/Acme.TestLib.csproj | 2 +- test/Acme.TestLib2/Acme.TestLib2.csproj | 2 +- .../Primitively.IntegrationTests.csproj | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Primitively.Abstractions/Primitively.Abstractions.csproj b/src/Primitively.Abstractions/Primitively.Abstractions.csproj index 89cbeed..d4f15f6 100644 --- a/src/Primitively.Abstractions/Primitively.Abstractions.csproj +++ b/src/Primitively.Abstractions/Primitively.Abstractions.csproj @@ -16,7 +16,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/Primitively.AspNetCore.Mvc/Primitively.AspNetCore.Mvc.csproj b/src/Primitively.AspNetCore.Mvc/Primitively.AspNetCore.Mvc.csproj index 8c17a7d..04e5f27 100644 --- a/src/Primitively.AspNetCore.Mvc/Primitively.AspNetCore.Mvc.csproj +++ b/src/Primitively.AspNetCore.Mvc/Primitively.AspNetCore.Mvc.csproj @@ -12,7 +12,7 @@ - + diff --git a/test/Acme.TestLib/Acme.TestLib.csproj b/test/Acme.TestLib/Acme.TestLib.csproj index 3a7e3a7..829f97e 100644 --- a/test/Acme.TestLib/Acme.TestLib.csproj +++ b/test/Acme.TestLib/Acme.TestLib.csproj @@ -25,7 +25,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/test/Acme.TestLib2/Acme.TestLib2.csproj b/test/Acme.TestLib2/Acme.TestLib2.csproj index b1fe6e9..241f0a1 100644 --- a/test/Acme.TestLib2/Acme.TestLib2.csproj +++ b/test/Acme.TestLib2/Acme.TestLib2.csproj @@ -25,7 +25,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/test/Primitively.IntegrationTests/Primitively.IntegrationTests.csproj b/test/Primitively.IntegrationTests/Primitively.IntegrationTests.csproj index 6c83200..d7908b1 100644 --- a/test/Primitively.IntegrationTests/Primitively.IntegrationTests.csproj +++ b/test/Primitively.IntegrationTests/Primitively.IntegrationTests.csproj @@ -25,7 +25,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all From 1a2ddd05d3a7b433d3d35038bbd3ba506d43a0f5 Mon Sep 17 00:00:00 2001 From: Stuart Blackburn Date: Thu, 28 Mar 2024 23:31:59 +0000 Subject: [PATCH 2/6] fix: updated Integer source gen template to fix HasValue bug --- src/Directory.Build.props | 2 +- src/Primitively/EmbeddedResources/Integer/Base.cs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 14b1752..ebdec12 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -25,7 +25,7 @@ $(MSBuildThisFileDirectory)..\artifacts - 1.4.15-rc.3 + 1.4.17 diff --git a/src/Primitively/EmbeddedResources/Integer/Base.cs b/src/Primitively/EmbeddedResources/Integer/Base.cs index ae0ebb1..38b902d 100644 --- a/src/Primitively/EmbeddedResources/Integer/Base.cs +++ b/src/Primitively/EmbeddedResources/Integer/Base.cs @@ -2,23 +2,25 @@ { private readonly global::PRIMITIVE_VALUE_TYPE _value = default; - public const string Example = @"PRIMITIVE_EXAMPLE"; + public const string Example = "PRIMITIVE_EXAMPLE"; public const global::PRIMITIVE_VALUE_TYPE Minimum = PRIMITIVE_MINIMUM; public const global::PRIMITIVE_VALUE_TYPE Maximum = PRIMITIVE_MAXIMUM; public PRIMITIVE_TYPE(global::PRIMITIVE_VALUE_TYPE value) { - if (value >= PRIMITIVE_MINIMUM && value <= PRIMITIVE_MAXIMUM) + if (value >= Minimum && value <= Maximum) { _value = value; + HasValue = true; } } private PRIMITIVE_TYPE(string value) { - if (global::PRIMITIVE_VALUE_TYPE.TryParse(value, out var result) && result >= PRIMITIVE_MINIMUM && result <= PRIMITIVE_MAXIMUM) + if (global::PRIMITIVE_VALUE_TYPE.TryParse(value, out var result) && result >= Minimum && result <= Maximum) { _value = result; + HasValue = true; } } @@ -27,7 +29,7 @@ private PRIMITIVE_TYPE(string value) global::PRIMITIVE_VALUE_TYPE global::Primitively.IPrimitive.Value => _value; [global::System.Text.Json.Serialization.JsonIgnore] - public bool HasValue => _value != default; + public bool HasValue { get; } = false; [global::System.Text.Json.Serialization.JsonIgnore] public global::System.Type ValueType => typeof(global::PRIMITIVE_VALUE_TYPE); From 43db3f314b776a3c406eb26135772739e3755410 Mon Sep 17 00:00:00 2001 From: Stuart Blackburn Date: Thu, 28 Mar 2024 23:47:23 +0000 Subject: [PATCH 3/6] fix: fluent validation tests --- .../IntegerTests/Byte/FluentValidationTests.cs | 5 +++-- .../IntegerTests/Int/FluentValidationTests.cs | 5 +++-- .../IntegerTests/Long/FluentValidationTests.cs | 5 +++-- .../IntegerTests/SByte/FluentValidationTests.cs | 5 +++-- .../IntegerTests/Short/FluentValidationTests.cs | 5 +++-- .../IntegerTests/UInt/FluentValidationTests.cs | 5 +++-- .../IntegerTests/ULong/FluentValidationTests.cs | 5 +++-- .../IntegerTests/UShort/FluentValidationTests.cs | 5 +++-- 8 files changed, 24 insertions(+), 16 deletions(-) diff --git a/test/Primitively.IntegrationTests/IntegerTests/Byte/FluentValidationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/Byte/FluentValidationTests.cs index 9930eb0..f4a42e6 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/Byte/FluentValidationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/Byte/FluentValidationTests.cs @@ -25,8 +25,9 @@ public FluentValidationTests() [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1")] + [InlineData("0", true, true)] + [InlineData("00", true, true)] [InlineData("001", true, true)] [InlineData(ByteId.Example, true, true)] public void ConvertFromThisToThatWithExpectedResults(string? value, bool nonNullableIsValid = false, bool nullableIsValid = false) diff --git a/test/Primitively.IntegrationTests/IntegerTests/Int/FluentValidationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/Int/FluentValidationTests.cs index 819468c..528fefb 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/Int/FluentValidationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/Int/FluentValidationTests.cs @@ -25,8 +25,9 @@ public FluentValidationTests() [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1", true, true)] + [InlineData("0", true, true)] + [InlineData("00", true, true)] [InlineData("001", true, true)] [InlineData(IntId.Example, true, true)] public void ConvertFromThisToThatWithExpectedResults(string? value, bool nonNullableIsValid = false, bool nullableIsValid = false) diff --git a/test/Primitively.IntegrationTests/IntegerTests/Long/FluentValidationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/Long/FluentValidationTests.cs index fee756f..3c71f34 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/Long/FluentValidationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/Long/FluentValidationTests.cs @@ -25,8 +25,9 @@ public FluentValidationTests() [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1", true, true)] + [InlineData("0", true, true)] + [InlineData("00", true, true)] [InlineData("001", true, true)] [InlineData(LongId.Example, true, true)] public void ConvertFromThisToThatWithExpectedResults(string? value, bool nonNullableIsValid = false, bool nullableIsValid = false) diff --git a/test/Primitively.IntegrationTests/IntegerTests/SByte/FluentValidationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/SByte/FluentValidationTests.cs index 9a1e0a8..61d1bdb 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/SByte/FluentValidationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/SByte/FluentValidationTests.cs @@ -25,8 +25,9 @@ public FluentValidationTests() [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1", true, true)] + [InlineData("0", true, true)] + [InlineData("00", true, true)] [InlineData("001", true, true)] [InlineData(SByteId.Example, true, true)] public void ConvertFromThisToThatWithExpectedResults(string? value, bool nonNullableIsValid = false, bool nullableIsValid = false) diff --git a/test/Primitively.IntegrationTests/IntegerTests/Short/FluentValidationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/Short/FluentValidationTests.cs index 3313273..62b4a78 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/Short/FluentValidationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/Short/FluentValidationTests.cs @@ -25,8 +25,9 @@ public FluentValidationTests() [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1", true, true)] + [InlineData("0", true, true)] + [InlineData("00", true, true)] [InlineData("001", true, true)] [InlineData(ShortId.Example, true, true)] public void ConvertFromThisToThatWithExpectedResults(string? value, bool nonNullableIsValid = false, bool nullableIsValid = false) diff --git a/test/Primitively.IntegrationTests/IntegerTests/UInt/FluentValidationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/UInt/FluentValidationTests.cs index f4faa71..889eb69 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/UInt/FluentValidationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/UInt/FluentValidationTests.cs @@ -25,8 +25,9 @@ public FluentValidationTests() [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1")] + [InlineData("0", true, true)] + [InlineData("00", true, true)] [InlineData("001", true, true)] [InlineData(UIntId.Example, true, true)] public void ConvertFromThisToThatWithExpectedResults(string? value, bool nonNullableIsValid = false, bool nullableIsValid = false) diff --git a/test/Primitively.IntegrationTests/IntegerTests/ULong/FluentValidationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/ULong/FluentValidationTests.cs index d66e4d8..29a9c32 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/ULong/FluentValidationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/ULong/FluentValidationTests.cs @@ -25,8 +25,9 @@ public FluentValidationTests() [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1")] + [InlineData("0", true, true)] + [InlineData("00", true, true)] [InlineData("001", true, true)] [InlineData(ULongId.Example, true, true)] public void ConvertFromThisToThatWithExpectedResults(string? value, bool nonNullableIsValid = false, bool nullableIsValid = false) diff --git a/test/Primitively.IntegrationTests/IntegerTests/UShort/FluentValidationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/UShort/FluentValidationTests.cs index c5664f5..dc5b4ea 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/UShort/FluentValidationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/UShort/FluentValidationTests.cs @@ -25,8 +25,9 @@ public FluentValidationTests() [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1")] + [InlineData("0", true, true)] + [InlineData("00", true, true)] [InlineData("001", true, true)] [InlineData(UShortId.Example, true, true)] public void ConvertFromThisToThatWithExpectedResults(string? value, bool nonNullableIsValid = false, bool nullableIsValid = false) From cbb5086396f8442c3df0885d7faf7b048ccacaaa Mon Sep 17 00:00:00 2001 From: Stuart Blackburn Date: Fri, 29 Mar 2024 01:47:21 +0000 Subject: [PATCH 4/6] fix: instantiation tests --- .../IntegerTests/Byte/InstantiationTests.cs | 26 ++++--------------- .../IntegerTests/Int/InstantiationTests.cs | 26 ++++--------------- .../IntegerTests/Long/InstantiationTests.cs | 26 ++++--------------- .../IntegerTests/SByte/InstantiationTests.cs | 26 ++++--------------- .../IntegerTests/Short/InstantiationTests.cs | 26 ++++--------------- .../IntegerTests/UInt/InstantiationTests.cs | 26 ++++--------------- .../IntegerTests/ULong/InstantiationTests.cs | 26 ++++--------------- .../IntegerTests/UShort/InstantiationTests.cs | 26 ++++--------------- 8 files changed, 40 insertions(+), 168 deletions(-) diff --git a/test/Primitively.IntegrationTests/IntegerTests/Byte/InstantiationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/Byte/InstantiationTests.cs index 650ae81..2a97741 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/Byte/InstantiationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/Byte/InstantiationTests.cs @@ -10,31 +10,15 @@ public class InstantiationTests [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1")] + [InlineData("0", true)] + [InlineData("00", true)] [InlineData("001", true)] [InlineData(ByteId.Example, true)] - public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = default) + public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = false) { - var expectedInteger = hasValue ? ByteId.Parse(from) : default; - var expectedString = expectedInteger.ToString(); - - var @this = (ByteId)from; - string to = @this; - var that = ByteId.Parse(to); - var and = new ByteId(that); - string back = and; + var @this = ByteId.Parse(from); @this.HasValue.Should().Be(hasValue); - @this.Should().Be(expectedInteger); - @this.ToString().Should().Be(expectedString); - to.Should().Be(expectedString); - that.HasValue.Should().Be(hasValue); - that.Should().Be(expectedInteger); - that.ToString().Should().Be(expectedString); - and.HasValue.Should().Be(hasValue); - and.Should().Be(expectedInteger); - and.ToString().Should().Be(expectedString); - back.Should().Be(expectedString); } } diff --git a/test/Primitively.IntegrationTests/IntegerTests/Int/InstantiationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/Int/InstantiationTests.cs index 3ae864b..34addab 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/Int/InstantiationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/Int/InstantiationTests.cs @@ -10,31 +10,15 @@ public class InstantiationTests [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1", true)] + [InlineData("0", true)] + [InlineData("00", true)] [InlineData("001", true)] [InlineData(IntId.Example, true)] - public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = default) + public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = false) { - var expectedInteger = hasValue ? IntId.Parse(from) : default; - var expectedString = expectedInteger.ToString(); - - var @this = (IntId)from; - string to = @this; - var that = IntId.Parse(to); - var and = new IntId(that); - string back = and; + var @this = IntId.Parse(from); @this.HasValue.Should().Be(hasValue); - @this.Should().Be(expectedInteger); - @this.ToString().Should().Be(expectedString); - to.Should().Be(expectedString); - that.HasValue.Should().Be(hasValue); - that.Should().Be(expectedInteger); - that.ToString().Should().Be(expectedString); - and.HasValue.Should().Be(hasValue); - and.Should().Be(expectedInteger); - and.ToString().Should().Be(expectedString); - back.Should().Be(expectedString); } } diff --git a/test/Primitively.IntegrationTests/IntegerTests/Long/InstantiationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/Long/InstantiationTests.cs index cadee51..55f1ff2 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/Long/InstantiationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/Long/InstantiationTests.cs @@ -10,31 +10,15 @@ public class InstantiationTests [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1", true)] + [InlineData("0", true)] + [InlineData("00", true)] [InlineData("001", true)] [InlineData(LongId.Example, true)] - public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = default) + public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = false) { - var expectedInteger = hasValue ? LongId.Parse(from) : default; - var expectedString = expectedInteger.ToString(); - - var @this = (LongId)from; - string to = @this; - var that = LongId.Parse(to); - var and = new LongId(that); - string back = and; + var @this = LongId.Parse(from); @this.HasValue.Should().Be(hasValue); - @this.Should().Be(expectedInteger); - @this.ToString().Should().Be(expectedString); - to.Should().Be(expectedString); - that.HasValue.Should().Be(hasValue); - that.Should().Be(expectedInteger); - that.ToString().Should().Be(expectedString); - and.HasValue.Should().Be(hasValue); - and.Should().Be(expectedInteger); - and.ToString().Should().Be(expectedString); - back.Should().Be(expectedString); } } diff --git a/test/Primitively.IntegrationTests/IntegerTests/SByte/InstantiationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/SByte/InstantiationTests.cs index 4cb266f..92e2b5b 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/SByte/InstantiationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/SByte/InstantiationTests.cs @@ -10,31 +10,15 @@ public class InstantiationTests [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1", true)] + [InlineData("0", true)] + [InlineData("00", true)] [InlineData("001", true)] [InlineData(SByteId.Example, true)] - public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = default) + public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = false) { - var expectedInteger = hasValue ? SByteId.Parse(from) : default; - var expectedString = expectedInteger.ToString(); - - var @this = (SByteId)from; - string to = @this; - var that = SByteId.Parse(to); - var and = new SByteId(that); - string back = and; + var @this = SByteId.Parse(from); @this.HasValue.Should().Be(hasValue); - @this.Should().Be(expectedInteger); - @this.ToString().Should().Be(expectedString); - to.Should().Be(expectedString); - that.HasValue.Should().Be(hasValue); - that.Should().Be(expectedInteger); - that.ToString().Should().Be(expectedString); - and.HasValue.Should().Be(hasValue); - and.Should().Be(expectedInteger); - and.ToString().Should().Be(expectedString); - back.Should().Be(expectedString); } } diff --git a/test/Primitively.IntegrationTests/IntegerTests/Short/InstantiationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/Short/InstantiationTests.cs index 8dc042f..0fb6b48 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/Short/InstantiationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/Short/InstantiationTests.cs @@ -10,31 +10,15 @@ public class InstantiationTests [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1", true)] + [InlineData("0", true)] + [InlineData("00", true)] [InlineData("001", true)] [InlineData(ShortId.Example, true)] - public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = default) + public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = false) { - var expectedInteger = hasValue ? ShortId.Parse(from) : default; - var expectedString = expectedInteger.ToString(); - - var @this = (ShortId)from; - string to = @this; - var that = ShortId.Parse(to); - var and = new ShortId(that); - string back = and; + var @this = ShortId.Parse(from); @this.HasValue.Should().Be(hasValue); - @this.Should().Be(expectedInteger); - @this.ToString().Should().Be(expectedString); - to.Should().Be(expectedString); - that.HasValue.Should().Be(hasValue); - that.Should().Be(expectedInteger); - that.ToString().Should().Be(expectedString); - and.HasValue.Should().Be(hasValue); - and.Should().Be(expectedInteger); - and.ToString().Should().Be(expectedString); - back.Should().Be(expectedString); } } diff --git a/test/Primitively.IntegrationTests/IntegerTests/UInt/InstantiationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/UInt/InstantiationTests.cs index d70f62c..538e66c 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/UInt/InstantiationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/UInt/InstantiationTests.cs @@ -10,31 +10,15 @@ public class InstantiationTests [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1")] + [InlineData("0", true)] + [InlineData("00", true)] [InlineData("001", true)] [InlineData(UIntId.Example, true)] - public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = default) + public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = false) { - var expectedInteger = hasValue ? UIntId.Parse(from) : default; - var expectedString = expectedInteger.ToString(); - - var @this = (UIntId)from; - string to = @this; - var that = UIntId.Parse(to); - var and = new UIntId(that); - string back = and; + var @this = UIntId.Parse(from); @this.HasValue.Should().Be(hasValue); - @this.Should().Be(expectedInteger); - @this.ToString().Should().Be(expectedString); - to.Should().Be(expectedString); - that.HasValue.Should().Be(hasValue); - that.Should().Be(expectedInteger); - that.ToString().Should().Be(expectedString); - and.HasValue.Should().Be(hasValue); - and.Should().Be(expectedInteger); - and.ToString().Should().Be(expectedString); - back.Should().Be(expectedString); } } diff --git a/test/Primitively.IntegrationTests/IntegerTests/ULong/InstantiationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/ULong/InstantiationTests.cs index 506bf97..b365f91 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/ULong/InstantiationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/ULong/InstantiationTests.cs @@ -10,31 +10,15 @@ public class InstantiationTests [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1")] + [InlineData("0", true)] + [InlineData("00", true)] [InlineData("001", true)] [InlineData(ULongId.Example, true)] - public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = default) + public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = false) { - var expectedInteger = hasValue ? ULongId.Parse(from) : default; - var expectedString = expectedInteger.ToString(); - - var @this = (ULongId)from; - string to = @this; - var that = ULongId.Parse(to); - var and = new ULongId(that); - string back = and; + var @this = ULongId.Parse(from); @this.HasValue.Should().Be(hasValue); - @this.Should().Be(expectedInteger); - @this.ToString().Should().Be(expectedString); - to.Should().Be(expectedString); - that.HasValue.Should().Be(hasValue); - that.Should().Be(expectedInteger); - that.ToString().Should().Be(expectedString); - and.HasValue.Should().Be(hasValue); - and.Should().Be(expectedInteger); - and.ToString().Should().Be(expectedString); - back.Should().Be(expectedString); } } diff --git a/test/Primitively.IntegrationTests/IntegerTests/UShort/InstantiationTests.cs b/test/Primitively.IntegrationTests/IntegerTests/UShort/InstantiationTests.cs index e2220b8..7b7993a 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/UShort/InstantiationTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/UShort/InstantiationTests.cs @@ -10,31 +10,15 @@ public class InstantiationTests [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1")] + [InlineData("0", true)] + [InlineData("00", true)] [InlineData("001", true)] [InlineData(UShortId.Example, true)] - public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = default) + public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = false) { - var expectedInteger = hasValue ? UShortId.Parse(from) : default; - var expectedString = expectedInteger.ToString(); - - var @this = (UShortId)from; - string to = @this; - var that = UShortId.Parse(to); - var and = new UShortId(that); - string back = and; + var @this = UShortId.Parse(from); @this.HasValue.Should().Be(hasValue); - @this.Should().Be(expectedInteger); - @this.ToString().Should().Be(expectedString); - to.Should().Be(expectedString); - that.HasValue.Should().Be(hasValue); - that.Should().Be(expectedInteger); - that.ToString().Should().Be(expectedString); - and.HasValue.Should().Be(hasValue); - and.Should().Be(expectedInteger); - and.ToString().Should().Be(expectedString); - back.Should().Be(expectedString); } } From cb38b89a014863ef1fed00f2d2833d8ac88bcfc1 Mon Sep 17 00:00:00 2001 From: Stuart Blackburn Date: Fri, 29 Mar 2024 02:03:32 +0000 Subject: [PATCH 5/6] fix: validation method tests for ints --- .../IntegerTests/Int/ValidateMethodTests.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/Primitively.IntegrationTests/IntegerTests/Int/ValidateMethodTests.cs b/test/Primitively.IntegrationTests/IntegerTests/Int/ValidateMethodTests.cs index bc95df5..ddf3025 100644 --- a/test/Primitively.IntegrationTests/IntegerTests/Int/ValidateMethodTests.cs +++ b/test/Primitively.IntegrationTests/IntegerTests/Int/ValidateMethodTests.cs @@ -11,8 +11,9 @@ public class ValidateMethodTests [InlineData("")] [InlineData(" ")] [InlineData(" ")] - [InlineData("0")] - [InlineData("00")] + [InlineData("-1", true)] + [InlineData("0", true)] + [InlineData("00", true)] [InlineData("001", true)] [InlineData(ValidatableInteger.Example, true)] public void ConvertFromThisToThatWithExpectedResults(string? value, bool isValid = false) From 13026ae6e94de2e8f8e6cb1065390a2a3cf84f78 Mon Sep 17 00:00:00 2001 From: Stuart Blackburn Date: Sat, 30 Mar 2024 01:41:25 +0000 Subject: [PATCH 6/6] fix: additional tweaks to patch integer HasValue bugs --- .../EmbeddedResources/Integer/Base.cs | 22 ++++++++++--------- .../PrimitiveJsonConverterTests.cs | 4 ++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Primitively/EmbeddedResources/Integer/Base.cs b/src/Primitively/EmbeddedResources/Integer/Base.cs index 38b902d..d704f9e 100644 --- a/src/Primitively/EmbeddedResources/Integer/Base.cs +++ b/src/Primitively/EmbeddedResources/Integer/Base.cs @@ -6,22 +6,22 @@ public const global::PRIMITIVE_VALUE_TYPE Minimum = PRIMITIVE_MINIMUM; public const global::PRIMITIVE_VALUE_TYPE Maximum = PRIMITIVE_MAXIMUM; + public PRIMITIVE_TYPE() + { + HasValue = IsMatch(_value); + _value = default; + } + public PRIMITIVE_TYPE(global::PRIMITIVE_VALUE_TYPE value) { - if (value >= Minimum && value <= Maximum) - { - _value = value; - HasValue = true; - } + HasValue = IsMatch(value); + _value = HasValue ? value : default; } private PRIMITIVE_TYPE(string value) { - if (global::PRIMITIVE_VALUE_TYPE.TryParse(value, out var result) && result >= Minimum && result <= Maximum) - { - _value = result; - HasValue = true; - } + HasValue = global::PRIMITIVE_VALUE_TYPE.TryParse(value, out var result) && IsMatch(result); + _value = HasValue ? result : default; } object global::Primitively.IPrimitive.Value => _value; @@ -49,3 +49,5 @@ private PRIMITIVE_TYPE(string value) public static PRIMITIVE_TYPE Parse(string value) => new(value); public static bool TryParse(string value, out PRIMITIVE_TYPE result) => (result = new(value)).HasValue; + + private static bool IsMatch(global::PRIMITIVE_VALUE_TYPE value) => value >= Minimum && value <= Maximum; diff --git a/test/Primitively.IntegrationTests/PrimitiveJsonConverterTests.cs b/test/Primitively.IntegrationTests/PrimitiveJsonConverterTests.cs index 6edf3c7..a49e917 100644 --- a/test/Primitively.IntegrationTests/PrimitiveJsonConverterTests.cs +++ b/test/Primitively.IntegrationTests/PrimitiveJsonConverterTests.cs @@ -48,7 +48,7 @@ public void JsonConverter_CanReadDefault() var result = converter.Read(ref reader, typeof(TPrimitive), new JsonSerializerOptions()); result.Should().BeAssignableTo(typeof(TPrimitive)); - result.Should().BeEquivalentTo(default(TPrimitive)); + result.Should().BeEquivalentTo(new TPrimitive()); } [Fact] @@ -67,7 +67,7 @@ public void JsonConverter_CanReadNull() var result = converter.Read(ref reader, typeof(TPrimitive), new JsonSerializerOptions()); result.Should().BeAssignableTo(typeof(TPrimitive)); - result.Should().BeEquivalentTo(default(TPrimitive)); + result.Should().BeEquivalentTo(new TPrimitive()); } #if NET6_0_OR_GREATER