Skip to content

Commit

Permalink
Adapt ISupportsLinks for FamilySearch#43 and FamilySearch#48.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoergHoffmannatGitHub committed Jan 7, 2023
1 parent 0411c97 commit e1ab9ad
Show file tree
Hide file tree
Showing 16 changed files with 157 additions and 228 deletions.
9 changes: 8 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ root = true
[*]
indent_style = space


# XML project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2
Expand All @@ -20,9 +19,17 @@ indent_size = 2
indent_size = 4
insert_final_newline = true
charset = utf-8-bom

###############################
# .NET Coding Conventions #
###############################
[*.{cs,vb}]
# Organize usings
dotnet_sort_system_directives_first = true

###############################
# .NUnit Coding Conventions #
###############################

# NUnit2045: Use Assert.Multiple
dotnet_diagnostic.NUnit2045.severity = silent
57 changes: 13 additions & 44 deletions Gedcomx.Model.Rs/Entry.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using Gedcomx.Model;
using Gx.Links;
using Newtonsoft.Json;
// <auto-generated>
// <auto-generated>
//
//
// Generated by <a href="http://enunciate.codehaus.org">Enunciate</a>.
// </auto-generated>
using System;
using System.Collections.Generic;
using System.Linq;

using Gedcomx.Model;
using Gedcomx.Model.Util;

using Newtonsoft.Json;

namespace Gx.Atom
{

Expand All @@ -32,7 +33,7 @@ public partial class Entry : Gx.Atom.ExtensibleElement, ISupportsLinks
private Gx.Atom.Content _content;
private System.Collections.Generic.List<Gx.Atom.Person> _contributors;
private string _id;
private System.Collections.Generic.List<Gx.Links.Link> _links;
private Gx.Model.Collections.Links _links;
private DateTime? _published;
private bool _publishedSpecified;
private string _rights;
Expand Down Expand Up @@ -165,17 +166,22 @@ public string Id
[System.Xml.Serialization.XmlElementAttribute(ElementName = "link", Namespace = "http://www.w3.org/2005/Atom")]
[Newtonsoft.Json.JsonProperty("links")]
[JsonConverter(typeof(JsonHypermediaLinksConverter))]
public System.Collections.Generic.List<Gx.Links.Link> Links
public Gx.Model.Collections.Links Links
{
get
{
return this._links;
return this._links ?? (_links = new Gx.Model.Collections.Links());
}
set
{
this._links = value;
}
}
public bool ShouldSerializeLinks() => AnyLinks();
public bool AnyLinks()
{
return _links?.Any() ?? false;
}
/// <summary>
/// instant in time associated with an event early in the life cycle of the entry.
/// </summary>
Expand Down Expand Up @@ -334,43 +340,6 @@ public System.Xml.XmlAttribute[] OtherAttributes
}
}

/// <summary>
/// Add a hypermedia link. Links are not specified by GEDCOM X core, but as extension elements by GEDCOM X RS.
/// </summary>
/// <param name="link">The hypermedia link. Links are not specified by GEDCOM X core, but as extension elements by GEDCOM X RS.</param>
public void AddLink(Link link)
{
if (this.Links == null)
{
Links = new List<Link>();
}

this.Links.Add(link);
}

/// <summary>
/// Add a hypermedia link.
/// </summary>
/// <param name="rel">The link rel.</param>
/// <param name="href">The target URI.</param>
public void AddLink(string rel, Uri href)
{
AddLink(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 AddTemplatedLink(string rel, string template)
{
Link link = new Link();
link.Rel = rel;
link.Template = template;
AddLink(link);
}

/// <summary>
/// Get a link by its rel. Links are not specified by GEDCOM X core, but as extension elements by GEDCOM X RS.
/// </summary>
Expand Down
59 changes: 15 additions & 44 deletions Gedcomx.Model.Rs/Feed.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
using Gedcomx.Model;
using Gx.Links;
using Newtonsoft.Json;
// <auto-generated>
// <auto-generated>
//
//
// Generated by <a href="http://enunciate.codehaus.org">Enunciate</a>.
// </auto-generated>
using System;
using System.Collections.Generic;
using System.Linq;

using Gedcomx.Model;
using Gedcomx.Model.Util;

using Gx.Links;

using Newtonsoft.Json;

namespace Gx.Atom
{

Expand Down Expand Up @@ -39,7 +42,7 @@ public partial class Feed : Gx.Atom.ExtensibleElement, ISupportsLinks
private bool _resultsSpecified;
private int? _index;
private bool _indexSpecified;
private System.Collections.Generic.List<Gx.Links.Link> _links;
private Gx.Model.Collections.Links _links;
private string _logo;
private string _rights;
private string _subtitle;
Expand Down Expand Up @@ -206,17 +209,22 @@ public bool IndexSpecified
[System.Xml.Serialization.XmlElementAttribute(ElementName = "link", Namespace = "http://www.w3.org/2005/Atom")]
[Newtonsoft.Json.JsonProperty("links")]
[JsonConverter(typeof(JsonHypermediaLinksConverter))]
public System.Collections.Generic.List<Gx.Links.Link> Links
public Gx.Model.Collections.Links Links
{
get
{
return this._links;
return this._links ?? (_links = new Gx.Model.Collections.Links());
}
set
{
this._links = value;
}
}
public bool ShouldSerializeLinks() => AnyLinks();
public bool AnyLinks()
{
return _links?.Any() ?? false;
}
/// <summary>
/// identifies an image that provides visual identification for the feed.
/// </summary>
Expand Down Expand Up @@ -351,43 +359,6 @@ public System.Collections.Generic.List<Gx.Records.Field> Facets
}
}

/// <summary>
/// Add a hypermedia link. Links are not specified by GEDCOM X core, but as extension elements by GEDCOM X RS.
/// </summary>
/// <param name="link">The hypermedia link. Links are not specified by GEDCOM X core, but as extension elements by GEDCOM X RS.</param>
public void AddLink(Link link)
{
if (this._links == null)
{
_links = new List<Link>();
}

this._links.Add(link);
}

/// <summary>
/// Add a hypermedia link.
/// </summary>
/// <param name="rel">The link rel.</param>
/// <param name="href">The target URI.</param>
public void AddLink(String rel, Uri href)
{
AddLink(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 AddTemplatedLink(String rel, String template)
{
Link link = new Link();
link.Rel = rel;
link.Template = template;
AddLink(link);
}

/// <summary>
/// Get a link by its rel. Links are not specified by GEDCOM X core, but as extension elements by GEDCOM X RS.
/// </summary>
Expand Down
36 changes: 29 additions & 7 deletions Gedcomx.Model.Test/AgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Gx.Agent;
using Gx.Common;
using Gx.Conclusion;
using Gx.Links;

using Newtonsoft.Json;

Expand All @@ -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]"));
Expand All @@ -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));
Expand All @@ -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()));
Expand Down
13 changes: 7 additions & 6 deletions Gedcomx.Model.Test/SerializableTest.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
using System;
using System.Reflection;
using System.Reflection;
using System.Xml.Serialization;

using Newtonsoft.Json;

using NUnit.Framework;

namespace Genealogy.Model.Test;
namespace Gedcomx.Model.Test;

/// <summary>
/// Test calss for serializeable classes.
/// </summary>
[TestFixture]
public class SerializableTest
{
private JsonSerializerSettings _jsonSettings = new()
private readonly JsonSerializerSettings _jsonSettings = new()
{
NullValueHandling = NullValueHandling.Ignore
};
Expand All @@ -34,7 +37,6 @@ private static void VerifyXmlSerialization(object sut, Type type)

stream.Seek(0, SeekOrigin.Begin);
var result = new StreamReader(stream).ReadToEnd();
//Assert.That(result, Does.Contain("<" + type.Name + " ").IgnoreCase);
stream.Seek(0, SeekOrigin.Begin);
Assert.DoesNotThrow(() => serializer.Deserialize(stream));
}
Expand All @@ -51,6 +53,5 @@ private static IEnumerable<TestCaseData> TestSerializableTypes()
select t;
return from type in types
select new TestCaseData(type).SetName($"Serialize({type.Name})");
;
}
}
2 changes: 1 addition & 1 deletion Gedcomx.Model/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Gx.Model.Collections.Emails Emails
}
set
{
this._emails = (Gx.Model.Collections.Emails)value;
this._emails = value;
}
}
public bool ShouldSerializeEmails() => AnyEmails();
Expand Down
2 changes: 1 addition & 1 deletion Gedcomx.Model/Collections/Emails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Gx.Model.Collections
{
/// <summary>
/// A list of reference to Emails resources.
/// A list of <see cref="ResourceReference"/> to Emails.
/// </summary>
public class Emails : List<ResourceReference>
{
Expand Down
27 changes: 27 additions & 0 deletions Gedcomx.Model/Collections/Links.cs
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 });
}
}
Loading

0 comments on commit e1ab9ad

Please sign in to comment.