forked from FamilySearch/gedcomx-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Field.
- Loading branch information
1 parent
c0921fd
commit f1475d3
Showing
6 changed files
with
97 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Xml.Serialization; | ||
|
||
using Gx.Records; | ||
|
||
using Gx.Types; | ||
|
||
using Newtonsoft.Json; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace Gedcomx.Model.Test; | ||
|
||
/// <summary> | ||
/// Test calss for <see cref="Field"/> | ||
/// </summary> | ||
[TestFixture] | ||
public class FieldTest | ||
{ | ||
[Test] | ||
public void FieldEmpty() | ||
{ | ||
Field sut = new(); | ||
|
||
VerifyXmlSerialization(sut); | ||
VerifyJsonSerialization(sut); | ||
} | ||
|
||
[Test] | ||
public void FieldObjectInitialization() | ||
{ | ||
Field sut = new() | ||
{ | ||
// ExtensibleData | ||
Id = "F-1", | ||
// HypermediaEnabledData | ||
Links = { new(), { "rel", new Uri("https://www.familysearch.org/platform/collections/tree") }, { "rel", "template" } }, | ||
// Field | ||
KnownType = FieldType.Abusua, | ||
Values = { new() } | ||
}; | ||
|
||
VerifyXmlSerialization(sut); | ||
VerifyJsonSerialization(sut); | ||
} | ||
|
||
private static void VerifyXmlSerialization(Field sut) | ||
{ | ||
XmlSerializer serializer = new(typeof(Field)); | ||
using MemoryStream stream = new(); | ||
serializer.Serialize(stream, sut); | ||
|
||
stream.Seek(0, SeekOrigin.Begin); | ||
var result = new StreamReader(stream).ReadToEnd(); | ||
result.ShouldContain(sut); | ||
} | ||
|
||
private static void VerifyJsonSerialization(Field sut) | ||
{ | ||
JsonSerializerSettings jsonSettings = new() | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore | ||
}; | ||
|
||
Assert.DoesNotThrow(() => JsonConvert.DeserializeObject<Field>(JsonConvert.SerializeObject(sut, jsonSettings), jsonSettings)); | ||
} | ||
} |
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