-
Notifications
You must be signed in to change notification settings - Fork 22
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 #53 from JoergHoffmannatGitHub/master
- Loading branch information
Showing
10 changed files
with
365 additions
and
243 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 |
---|---|---|
|
@@ -31,8 +31,11 @@ public void AgentObjectInitialization() | |
{ | ||
var sut = new Agent | ||
{ | ||
// ExtensibleData | ||
Id = "A-1", | ||
// HypermediaEnabledData | ||
Links = { new Link(), { "rel", new Uri("https://www.familysearch.org/platform/collections/tree") }, { "rel", "template" } }, | ||
// Agent | ||
Accounts = { new OnlineAccount() }, | ||
Addresses = { new Address() }, | ||
Emails = { "[email protected]" }, | ||
|
@@ -77,20 +80,7 @@ private static void VerifyXmlSerialization(Agent sut) | |
|
||
stream.Seek(0, SeekOrigin.Begin); | ||
var result = new StreamReader(stream).ReadToEnd(); | ||
Assert.That(result, Does.Contain("<agent ")); | ||
Assert.That(result, Does.Contain("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"")); | ||
Assert.That(result, Does.Contain("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"")); | ||
Assert.That(result, Does.Contain("xmlns=\"http://gedcomx.org/v1/\"")); | ||
Assert.That(result.Contains("id"), Is.EqualTo(sut.Id != null)); | ||
Assert.That(result.Contains("<link"), Is.EqualTo(sut.AnyLinks())); | ||
Assert.That(result.Contains("<account"), Is.EqualTo(sut.AnyAccounts())); | ||
Assert.That(result.Contains("<address"), Is.EqualTo(sut.AnyAddresses())); | ||
Assert.That(result.Contains("<email"), Is.EqualTo(sut.AnyEmails())); | ||
Assert.That(result.Contains("<homepage"), Is.EqualTo(sut.Homepage != null)); | ||
Assert.That(result.Contains("<identifier"), Is.EqualTo(sut.AnyIdentifiers())); | ||
Assert.That(result.Contains("<name"), Is.EqualTo(sut.AnyNames())); | ||
Assert.That(result.Contains("<openid"), Is.EqualTo(sut.Openid != null)); | ||
Assert.That(result.Contains("<phone"), Is.EqualTo(sut.AnyPhones())); | ||
result.ShouldContain(sut); | ||
} | ||
|
||
private static void VerifyJsonSerialization(Agent sut) | ||
|
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.Xml.Serialization; | ||
|
||
using Gx.Common; | ||
using Gx.Conclusion; | ||
using Gx.Records; | ||
using Gx.Source; | ||
using Gx.Types; | ||
|
||
using Newtonsoft.Json; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace Gedcomx.Model.Test | ||
{ | ||
/// <summary> | ||
/// Test calss for <see cref="Fact"/> | ||
/// </summary> | ||
[TestFixture] | ||
public class FactTest | ||
{ | ||
[Test] | ||
public void FactEmpty() | ||
{ | ||
var sut = new Fact(); | ||
|
||
VerifyXmlSerialization(sut); | ||
VerifyJsonSerialization(sut); | ||
} | ||
|
||
[Test] | ||
public void FactFilled() | ||
{ | ||
var sut = new Fact | ||
{ | ||
// ExtensibleData | ||
Id = "F-1", | ||
// Conclusion | ||
KnownConfidence = ConfidenceLevel.Medium, | ||
SortKey = "sort key", | ||
Lang = "lang", | ||
Attribution = new Attribution(), | ||
Sources = { new SourceReference(), new SourceDescription() { Id = "S-1" } }, | ||
Analysis = new ResourceReference(), | ||
Notes = { new Note() }, | ||
// Fact | ||
Primary = true, | ||
KnownType = FactType.Adoption, | ||
Date = new DateInfo(), | ||
Place = new PlaceReference(), | ||
Value = "value", | ||
Qualifiers = { new Qualifier() }, | ||
Fields = { new Field() } | ||
}; | ||
|
||
VerifyXmlSerialization(sut); | ||
VerifyJsonSerialization(sut); | ||
} | ||
|
||
private static void VerifyXmlSerialization(Fact sut) | ||
{ | ||
var serializer = new XmlSerializer(typeof(Fact)); | ||
using var stream = new MemoryStream(); | ||
serializer.Serialize(stream, sut); | ||
|
||
stream.Seek(0, SeekOrigin.Begin); | ||
var result = new StreamReader(stream).ReadToEnd(); | ||
result.ShouldContain(sut); | ||
} | ||
|
||
private static void VerifyJsonSerialization(Fact sut) | ||
{ | ||
JsonSerializerSettings jsonSettings = new() | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore | ||
}; | ||
|
||
Assert.DoesNotThrow(() => JsonConvert.DeserializeObject<Fact>(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.