-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #459 from fgheysels/frgh/feat/171_458_datetimeoffset
Allow generation of DateTimeOffset properties for xs:dateTime
- Loading branch information
Showing
6 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml.Schema; | ||
using Xunit; | ||
|
||
namespace XmlSchemaClassGenerator.Tests | ||
{ | ||
public sealed class DateTimeTypeTests | ||
{ | ||
private static IEnumerable<string> ConvertXml(string xsd, Generator generatorPrototype) | ||
{ | ||
var writer = new MemoryOutputWriter(); | ||
|
||
var gen = new Generator | ||
{ | ||
OutputWriter = writer, | ||
Version = new("Tests", "1.0.0.1"), | ||
NamespaceProvider = generatorPrototype.NamespaceProvider, | ||
GenerateNullables = generatorPrototype.GenerateNullables, | ||
DateTimeWithTimeZone = generatorPrototype.DateTimeWithTimeZone, | ||
DataAnnotationMode = generatorPrototype.DataAnnotationMode, | ||
GenerateDesignerCategoryAttribute = generatorPrototype.GenerateDesignerCategoryAttribute, | ||
GenerateComplexTypesForCollections = generatorPrototype.GenerateComplexTypesForCollections, | ||
EntityFramework = generatorPrototype.EntityFramework, | ||
AssemblyVisible = generatorPrototype.AssemblyVisible, | ||
GenerateInterfaces = generatorPrototype.GenerateInterfaces, | ||
MemberVisitor = generatorPrototype.MemberVisitor, | ||
CodeTypeReferenceOptions = generatorPrototype.CodeTypeReferenceOptions | ||
}; | ||
|
||
var set = new XmlSchemaSet(); | ||
|
||
using (var stringReader = new StringReader(xsd)) | ||
{ | ||
var schema = XmlSchema.Read(stringReader, (_, e) => throw new InvalidOperationException($"{e.Severity}: {e.Message}", e.Exception)); | ||
ArgumentNullException.ThrowIfNull(schema); | ||
set.Add(schema); | ||
} | ||
|
||
gen.Generate(set); | ||
|
||
return writer.Content; | ||
} | ||
|
||
[Theory] | ||
[InlineData(false, "System.DateTime")] | ||
[InlineData(true, "System.DateTimeOffset")] | ||
public void TestFallbackType(bool dateTimeWithTimeZone, string expectedType) | ||
{ | ||
var xsd = @$"<?xml version=""1.0"" encoding=""UTF-8""?> | ||
<xs:schema elementFormDefault=""qualified"" xmlns:xs=""http://www.w3.org/2001/XMLSchema""> | ||
<xs:complexType name=""document""> | ||
<xs:sequence> | ||
<xs:element name=""someDate"" type=""xs:dateTime"" /> | ||
</xs:sequence> | ||
</xs:complexType> | ||
</xs:schema>"; | ||
|
||
var generatedType = ConvertXml( | ||
xsd, new() | ||
{ | ||
NamespaceProvider = new() | ||
{ | ||
GenerateNamespace = _ => "Test" | ||
}, | ||
DateTimeWithTimeZone = dateTimeWithTimeZone | ||
}); | ||
|
||
var expectedProperty = $"public {expectedType} SomeDate"; | ||
var generatedProperty = generatedType.First(); | ||
|
||
Assert.Contains(expectedProperty, generatedProperty); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters