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.
- RecordSet.
- Loading branch information
1 parent
827bafd
commit 33a9abf
Showing
4 changed files
with
116 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.Xml.Serialization; | ||
|
||
using Gx.Records; | ||
|
||
using Newtonsoft.Json; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace Gedcomx.Model.Test; | ||
|
||
/// <summary> | ||
/// Test calss for <see cref="RecordSet"/> | ||
/// </summary> | ||
[TestFixture] | ||
public class RecordSetTest | ||
{ | ||
[Test] | ||
public void RecordSetEmpty() | ||
{ | ||
RecordSet sut = new(); | ||
|
||
VerifyXmlSerialization(sut); | ||
VerifyJsonSerialization(sut); | ||
} | ||
|
||
[Test] | ||
public void RecordSetObjectInitialization() | ||
{ | ||
RecordSet sut = new() | ||
{ | ||
// ExtensibleData | ||
Id = "F-1", | ||
// HypermediaEnabledData | ||
Links = { new(), { "rel", new Uri("https://www.familysearch.org/platform/collections/tree") }, { "rel", "template" } }, | ||
// RecordSet | ||
Lang = "lang", | ||
Metadata = new(), | ||
Records = { new() } | ||
}; | ||
|
||
VerifyXmlSerialization(sut); | ||
VerifyJsonSerialization(sut); | ||
} | ||
|
||
private static void VerifyXmlSerialization(RecordSet sut) | ||
{ | ||
XmlSerializer serializer = new(typeof(RecordSet)); | ||
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(RecordSet sut) | ||
{ | ||
JsonSerializerSettings jsonSettings = new() | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore | ||
}; | ||
|
||
Assert.DoesNotThrow(() => JsonConvert.DeserializeObject<RecordSet>(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
Oops, something went wrong.