-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
keep nill value for ref types that has nillable in xsd
- Loading branch information
1 parent
3c0cfab
commit 91b054f
Showing
18 changed files
with
439 additions
and
367 deletions.
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
46 changes: 46 additions & 0 deletions
46
backend/tests/DataModeling.Tests/XmlDeserializeSerializeTests.cs
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,46 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Xml.Linq; | ||
using System.Xml.Serialization; | ||
using DataModeling.Tests.BaseClasses; | ||
using DataModeling.Tests.Utils; | ||
using FluentAssertions; | ||
using SharedResources.Tests; | ||
using Xunit; | ||
|
||
namespace DataModeling.Tests; | ||
|
||
public class XmlDeserializeSerializeTests : CsharpModelConversionTestsBase<XmlDeserializeSerializeTests> | ||
{ | ||
[Theory] | ||
[InlineData("Model/XmlSchema/XsAll/xsall-example.xsd", "Model/Xml/XsAll/xsall-example-nillable-sample.xml")] | ||
public void XmlDeserializeSerializeShouldKeepNillValue(string xsdSchemaPath, string xmlPath) | ||
{ | ||
Given.That.XsdSchemaLoaded(xsdSchemaPath) | ||
.When.LoadedXsdSchemaConvertedToJsonSchema() | ||
.And.ConvertedJsonSchemaConvertedToModelMetadata() | ||
.And.ModelMetadataConvertedToCsharpClass() | ||
.And.CSharpClassesCompiledToAssembly() | ||
.Then.CompiledAssembly.Should().NotBeNull(); | ||
|
||
And.DeserializeAndSerializeShouldProduceSameXml(xmlPath); | ||
} | ||
|
||
private void DeserializeAndSerializeShouldProduceSameXml(string xmlPath) | ||
{ | ||
Type csharpType = CompiledAssembly.Types().Single(type => type.CustomAttributes.Any(att => att.AttributeType == typeof(XmlRootAttribute))); | ||
|
||
string loadedXml = SharedResourcesHelper.LoadTestDataAsString(xmlPath); | ||
|
||
// Deserialize xml to new object of type csharpType | ||
object deserializedObject = SerializationHelper.Deserialize(loadedXml, csharpType); | ||
|
||
// serialize xml back to string | ||
string serializedXml = SerializationHelper.SerializeXml(deserializedObject); | ||
|
||
// Compare the original xml with the serialized xml | ||
var expected = XDocument.Parse(loadedXml); | ||
var result = XDocument.Parse(serializedXml); | ||
Assert.True(XNode.DeepEquals(expected, result)); | ||
} | ||
} |
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
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
Oops, something went wrong.