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.
Adapt ISupportsLinks for FamilySearch#43 and FamilySearch#48.
- Loading branch information
1 parent
0411c97
commit e1ab9ad
Showing
16 changed files
with
157 additions
and
228 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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
using Gx.Agent; | ||
using Gx.Common; | ||
using Gx.Conclusion; | ||
using Gx.Links; | ||
|
||
using Newtonsoft.Json; | ||
|
||
|
@@ -26,20 +27,21 @@ public void AgentEmpty() | |
} | ||
|
||
[Test] | ||
public void AgentFilled() | ||
public void AgentObjectInitialization() | ||
{ | ||
var sut = new Agent | ||
{ | ||
Id = "O-1", | ||
Names = { "Jane Doe" }, | ||
Id = "A-1", | ||
Links = { new Link(), { "rel", new Uri("https://www.familysearch.org/platform/collections/tree") }, { "rel", "template" } }, | ||
Accounts = { new OnlineAccount() }, | ||
Addresses = { new Address() }, | ||
Emails = { "[email protected]" }, | ||
Homepage = new ResourceReference(), | ||
Identifiers = { new Identifier() }, | ||
Names = { "Jane Doe" }, | ||
Openid = new ResourceReference(), | ||
Phones = { new ResourceReference() }, | ||
}; | ||
sut.Accounts.Add(new OnlineAccount()); | ||
sut.Addresses.Add(new Address()); | ||
sut.Identifiers.Add(new Identifier()); | ||
sut.Phones.Add(new ResourceReference()); | ||
|
||
Assert.That(sut.Names[0].Value, Is.EqualTo("Jane Doe")); | ||
Assert.That(sut.Emails[0].Resource, Is.EqualTo("mailto:[email protected]")); | ||
|
@@ -48,6 +50,25 @@ public void AgentFilled() | |
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()); | ||
|
||
VerifyXmlSerialization(agent); | ||
VerifyJsonSerialization(agent); | ||
} | ||
|
||
private static void VerifyXmlSerialization(Agent sut) | ||
{ | ||
var serializer = new XmlSerializer(typeof(Agent)); | ||
|
@@ -61,6 +82,7 @@ private static void VerifyXmlSerialization(Agent sut) | |
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())); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Gx.Links; | ||
|
||
namespace Gx.Model.Collections | ||
{ | ||
/// <summary> | ||
/// A list of <see cref="Link"/>. | ||
/// </summary> | ||
public class Links : List<Link> | ||
{ | ||
/// <summary> | ||
/// Add a hypermedia link. | ||
/// </summary> | ||
/// <param name="rel">The link rel.</param> | ||
/// <param name="href">The target URI.</param> | ||
public void Add(string rel, Uri href) => Add(new Link(rel, href.ToString())); | ||
|
||
/// <summary> | ||
/// Add a templated link. | ||
/// </summary> | ||
/// <param name="rel">The link rel.</param> | ||
/// <param name="template">The link template.</param> | ||
public void Add(string rel, string template) => Add(new Link { Rel = rel, Template = template }); | ||
} | ||
} |
Oops, something went wrong.