From 9eba4ba43770aa614ddcc8cb5375e4c799b1a22f Mon Sep 17 00:00:00 2001 From: kronic Date: Tue, 8 Aug 2023 10:54:00 +0300 Subject: [PATCH 1/3] Remove redundant ";" --- XmlSchemaClassGenerator.Tests/SharedTestFunctions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XmlSchemaClassGenerator.Tests/SharedTestFunctions.cs b/XmlSchemaClassGenerator.Tests/SharedTestFunctions.cs index e97b8796..a2299fe0 100644 --- a/XmlSchemaClassGenerator.Tests/SharedTestFunctions.cs +++ b/XmlSchemaClassGenerator.Tests/SharedTestFunctions.cs @@ -126,7 +126,7 @@ void validate2(object s, ValidationEventArgs e) { if (HandleValidationError(output, xmlLines, e)) throw e.Exception; - }; + } settings.ValidationEventHandler += validate2; From 85289d535416b45a694ee9e42e88b93261e5e007 Mon Sep 17 00:00:00 2001 From: kronic Date: Tue, 8 Aug 2023 11:04:49 +0300 Subject: [PATCH 2/3] Add DecimalFractionDigits zero test --- .../IntegerTypeTests.cs | 182 +++++++++++++++--- 1 file changed, 153 insertions(+), 29 deletions(-) diff --git a/XmlSchemaClassGenerator.Tests/IntegerTypeTests.cs b/XmlSchemaClassGenerator.Tests/IntegerTypeTests.cs index effa751f..5e7bbed6 100644 --- a/XmlSchemaClassGenerator.Tests/IntegerTypeTests.cs +++ b/XmlSchemaClassGenerator.Tests/IntegerTypeTests.cs @@ -65,15 +65,15 @@ public void TestTotalDigits(int totalDigits, string expectedType) var xsd = @$" - - - - - - - - - + + + + + + + + + "; @@ -99,15 +99,15 @@ public void TestFallbackType(int totalDigits, bool useTypeAsFallback, string exp var xsd = @$" - - - - - - - - - + + + + + + + + + "; @@ -147,16 +147,16 @@ public void TestInclusiveRange(long minInclusive, ulong maxInclusive, string exp var xsd = @$" - - - - - - - - - - + + + + + + + + + + "; @@ -173,5 +173,129 @@ public void TestInclusiveRange(long minInclusive, ulong maxInclusive, string exp Assert.Contains(expectedProperty, generatedProperty); } - } + + [Theory] + [InlineData(2, "sbyte")] + [InlineData(4, "short")] + [InlineData(9, "int")] + [InlineData(18, "long")] + [InlineData(28, "decimal")] + [InlineData(29, "string")] + public void TestDecimalFractionDigitsZeroTotalDigits(int totalDigits, string expectedType) + { + var xsd = @$" + + + + + + + + + + + + +"; + + var generatedType = ConvertXml(nameof(TestTotalDigits), xsd, new Generator + { + NamespaceProvider = new NamespaceProvider + { + GenerateNamespace = key => "Test" + } + }); + + var expectedProperty = $"public {expectedType} SomeValue"; + Assert.Contains(expectedProperty, generatedType.First()); + } + + + [Theory] + [InlineData(4, false, "long")] + [InlineData(30, false, "long")] + [InlineData(4, true, "short")] + [InlineData(30, true, "long")] + public void TestDecimalFractionDigitsFallbackType(int totalDigits, bool useTypeAsFallback, string expectedType) + { + var xsd = @$" + + + + + + + + + + + + +"; + + var generatedType = ConvertXml(nameof(TestTotalDigits), xsd, new Generator + { + NamespaceProvider = new NamespaceProvider + { + GenerateNamespace = key => "Test" + }, + IntegerDataType = typeof(long), + UseIntegerDataTypeAsFallback = useTypeAsFallback + }); + + var expectedProperty = $"public {expectedType} SomeValue"; + Assert.Contains(expectedProperty, generatedType.First()); + } + + [Theory] + [InlineData(1, 100, "byte")] + [InlineData(byte.MinValue, byte.MaxValue, "byte")] + [InlineData(-100, 100, "sbyte")] + [InlineData(sbyte.MinValue, sbyte.MaxValue, "sbyte")] + [InlineData(1, 1000, "ushort")] + [InlineData(ushort.MinValue, ushort.MaxValue, "ushort")] + [InlineData(-1000, 1000, "short")] + [InlineData(short.MinValue, short.MaxValue, "short")] + [InlineData(1, 100000, "uint")] + [InlineData(uint.MinValue, uint.MaxValue, "uint")] + [InlineData(-100000, 100000, "int")] + [InlineData(int.MinValue, int.MaxValue, "int")] + [InlineData(1, 10000000000, "ulong")] + [InlineData(ulong.MinValue, ulong.MaxValue, "ulong")] + [InlineData(-10000000000, 10000000000, "long")] + [InlineData(long.MinValue, long.MaxValue, "long")] + public void TestDecimalFractionDigitsZeroInclusiveRange(long minInclusive, ulong maxInclusive, string expectedType) + { + var xsd = @$" + + + + + + + + + + + + + + +"; + + var generatedType = ConvertXml(nameof(TestTotalDigits), xsd, new Generator + { + NamespaceProvider = new NamespaceProvider + { + GenerateNamespace = key => "Test" + } + }); + + var expectedProperty = $"public {expectedType} SomeValue"; + var generatedProperty = generatedType.First(); + + Assert.Contains(expectedProperty, generatedProperty); + } + } + } From 58dd1752831fd9c9d8383ec65f46acf2d677f543 Mon Sep 17 00:00:00 2001 From: kronic Date: Tue, 8 Aug 2023 11:24:01 +0300 Subject: [PATCH 3/3] Add decimal FractionDigitsRestrictionModel.Value is 0 as integer --- XmlSchemaClassGenerator/CodeUtilities.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/XmlSchemaClassGenerator/CodeUtilities.cs b/XmlSchemaClassGenerator/CodeUtilities.cs index 88b85b7b..d7a050f7 100644 --- a/XmlSchemaClassGenerator/CodeUtilities.cs +++ b/XmlSchemaClassGenerator/CodeUtilities.cs @@ -111,7 +111,8 @@ public static Type GetEffectiveType(this XmlSchemaDatatype type, GeneratorConfig XmlTypeCode.Time => typeof(DateTime), XmlTypeCode.Idref => typeof(string), XmlTypeCode.Integer or XmlTypeCode.NegativeInteger or XmlTypeCode.NonNegativeInteger or XmlTypeCode.NonPositiveInteger or XmlTypeCode.PositiveInteger => GetIntegerDerivedType(type, configuration, restrictions), - _ => type.ValueType, + XmlTypeCode.Decimal when restrictions.OfType().SingleOrDefault() is { IsSupported: true, Value: 0 } => GetIntegerDerivedType(type, configuration, restrictions), + _ => type.ValueType, }; if (schemaType.IsDerivedFrom(GuidQualifiedName))