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.
- Collection.
- Loading branch information
1 parent
cd03f6e
commit ebd2f48
Showing
7 changed files
with
181 additions
and
111 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 |
---|---|---|
|
@@ -2,95 +2,92 @@ | |
|
||
using Gx.Agent; | ||
using Gx.Common; | ||
using Gx.Conclusion; | ||
using Gx.Links; | ||
|
||
using Newtonsoft.Json; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace Gedcomx.Model.Test | ||
namespace Gedcomx.Model.Test; | ||
|
||
/// <summary> | ||
/// Test calss for <see cref="Agent"/> | ||
/// </summary> | ||
[TestFixture] | ||
public class AgentTest | ||
{ | ||
/// <summary> | ||
/// Test calss for <see cref="Agent"/> | ||
/// </summary> | ||
[TestFixture] | ||
public class AgentTest | ||
[Test] | ||
public void AgentEmpty() | ||
{ | ||
[Test] | ||
public void AgentEmpty() | ||
{ | ||
var sut = new Agent(); | ||
Agent sut = new(); | ||
|
||
VerifyXmlSerialization(sut); | ||
VerifyJsonSerialization(sut); | ||
} | ||
VerifyXmlSerialization(sut); | ||
VerifyJsonSerialization(sut); | ||
} | ||
|
||
[Test] | ||
public void AgentObjectInitialization() | ||
[Test] | ||
public void AgentObjectInitialization() | ||
{ | ||
Agent sut = new() | ||
{ | ||
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]" }, | ||
Homepage = new ResourceReference(), | ||
Identifiers = { new Identifier() }, | ||
Names = { "Jane Doe" }, | ||
Openid = new ResourceReference(), | ||
Phones = { new ResourceReference() }, | ||
}; | ||
// ExtensibleData | ||
Id = "A-1", | ||
// HypermediaEnabledData | ||
Links = { new(), { "rel", new Uri("https://www.familysearch.org/platform/collections/tree") }, { "rel", "template" } }, | ||
// Agent | ||
Accounts = { new() }, | ||
Addresses = { new() }, | ||
Emails = { "[email protected]" }, | ||
Homepage = new(), | ||
Identifiers = { new() }, | ||
Names = { "Jane Doe" }, | ||
Openid = new(), | ||
Phones = { new() } | ||
}; | ||
|
||
Assert.That(sut.Names[0].Value, Is.EqualTo("Jane Doe")); | ||
Assert.That(sut.Emails[0].Resource, Is.EqualTo("mailto:[email protected]")); | ||
Assert.That(sut.Names[0].Value, Is.EqualTo("Jane Doe")); | ||
Assert.That(sut.Emails[0].Resource, Is.EqualTo("mailto:[email protected]")); | ||
|
||
VerifyXmlSerialization(sut); | ||
VerifyJsonSerialization(sut); | ||
} | ||
VerifyXmlSerialization(sut); | ||
VerifyJsonSerialization(sut); | ||
} | ||
|
||
[Test] | ||
public void SetAccountTest() | ||
{ | ||
var agent = new Agent(); | ||
agent.Accounts.Add(new OnlineAccount()); | ||
agent.Addresses.Add(new Address()); | ||
agent.Emails.Add(new ResourceReference()); | ||
agent.Homepage = new ResourceReference(); | ||
agent.Identifiers.Add(new Identifier()); | ||
agent.Names.Add(new TextValue()); | ||
agent.Openid = new ResourceReference(); | ||
agent.Phones.Add(new ResourceReference()); | ||
agent.Id = "id"; | ||
agent.Links.Add(new Link()); | ||
[Test] | ||
public void SetAccountTest() | ||
{ | ||
Agent agent = new(); | ||
agent.Accounts.Add(new()); | ||
agent.Addresses.Add(new()); | ||
agent.Emails.Add(new ResourceReference()); | ||
agent.Homepage = new(); | ||
agent.Identifiers.Add(new()); | ||
agent.Names.Add(new TextValue()); | ||
agent.Openid = new(); | ||
agent.Phones.Add(new()); | ||
agent.Id = "id"; | ||
agent.Links.Add(new()); | ||
|
||
VerifyXmlSerialization(agent); | ||
VerifyJsonSerialization(agent); | ||
} | ||
VerifyXmlSerialization(agent); | ||
VerifyJsonSerialization(agent); | ||
} | ||
|
||
private static void VerifyXmlSerialization(Agent sut) | ||
{ | ||
var serializer = new XmlSerializer(typeof(Agent)); | ||
using var stream = new MemoryStream(); | ||
serializer.Serialize(stream, sut); | ||
private static void VerifyXmlSerialization(Agent sut) | ||
{ | ||
XmlSerializer serializer = new(typeof(Agent)); | ||
using MemoryStream stream = new(); | ||
serializer.Serialize(stream, sut); | ||
|
||
stream.Seek(0, SeekOrigin.Begin); | ||
var result = new StreamReader(stream).ReadToEnd(); | ||
result.ShouldContain(sut); | ||
} | ||
stream.Seek(0, SeekOrigin.Begin); | ||
var result = new StreamReader(stream).ReadToEnd(); | ||
result.ShouldContain(sut); | ||
} | ||
|
||
private static void VerifyJsonSerialization(Agent sut) | ||
private static void VerifyJsonSerialization(Agent sut) | ||
{ | ||
JsonSerializerSettings jsonSettings = new() | ||
{ | ||
JsonSerializerSettings jsonSettings = new() | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore | ||
}; | ||
NullValueHandling = NullValueHandling.Ignore | ||
}; | ||
|
||
Assert.DoesNotThrow(() => JsonConvert.DeserializeObject<Agent>(JsonConvert.SerializeObject(sut, jsonSettings), jsonSettings)); | ||
} | ||
Assert.DoesNotThrow(() => JsonConvert.DeserializeObject<Agent>(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System.Xml.Serialization; | ||
|
||
using Gx.Records; | ||
|
||
using Newtonsoft.Json; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace Gedcomx.Model.Test; | ||
|
||
/// <summary> | ||
/// Test calss for <see cref="Collection"/> | ||
/// </summary> | ||
[TestFixture] | ||
public class CollectionTest | ||
{ | ||
[Test] | ||
public void CollectionEmpty() | ||
{ | ||
Collection sut = new(); | ||
|
||
VerifyXmlSerialization(sut); | ||
VerifyJsonSerialization(sut); | ||
} | ||
|
||
[Test] | ||
public void CollectionObjectInitialization() | ||
{ | ||
Collection sut = new() | ||
{ | ||
// ExtensibleData | ||
Id = "A-1", | ||
// HypermediaEnabledData | ||
Links = { new(), { "rel", new Uri("https://www.familysearch.org/platform/collections/tree") }, { "rel", "template" } }, | ||
// Collection | ||
Lang = "en", | ||
Title = "title", | ||
Size = 5, | ||
Content = { new() }, | ||
Attribution = new() | ||
}; | ||
|
||
VerifyXmlSerialization(sut); | ||
VerifyJsonSerialization(sut); | ||
} | ||
|
||
private static void VerifyXmlSerialization(Collection sut) | ||
{ | ||
XmlSerializer serializer = new(typeof(Collection)); | ||
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(Collection sut) | ||
{ | ||
JsonSerializerSettings jsonSettings = new() | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore | ||
}; | ||
|
||
Assert.DoesNotThrow(() => JsonConvert.DeserializeObject<Collection>(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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,6 @@ | |
|
||
using Gedcomx.Model.Util; | ||
|
||
using Gx.Model; | ||
|
||
using Newtonsoft.Json; | ||
|
||
namespace Gx.Common | ||
|
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.