Skip to content

Commit

Permalink
Merge pull request #53 from JoergHoffmannatGitHub/master
Browse files Browse the repository at this point in the history
Add Test to fix #43 and #48. Work in Progress.
  • Loading branch information
stoicflame authored Jan 23, 2023
2 parents 4d64790 + 14e946b commit 782b5f8
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 243 deletions.
18 changes: 4 additions & 14 deletions Gedcomx.Model.Test/AgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]" },
Expand Down Expand Up @@ -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)
Expand Down
80 changes: 80 additions & 0 deletions Gedcomx.Model.Test/FactTest.cs
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));
}
}
}
138 changes: 68 additions & 70 deletions Gedcomx.Model.Test/GedcomxTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ public void EmmaBocockExampleTest()
Created = DateTime.Parse("1843-07-27"),
Repository = repository
};
Fact birth = new Fact()
.SetType(FactType.Birth)
.SetDate(new DateInfo().SetOriginal("23 June 1843"))
.SetPlace(new PlaceReference().SetOriginal("Broadfield Bar, Abbeydale Road, Ecclesall-Bierlow, York, England, United Kingdom"));
Fact birth = new()
{
KnownType = FactType.Birth,
Date = new DateInfo().SetOriginal("23 June 1843"),
Place = new PlaceReference().SetOriginal("Broadfield Bar, Abbeydale Road, Ecclesall-Bierlow, York, England, United Kingdom")
};
Person emma = (Person)new Person().SetName("Emma Bocock").SetGender(GenderType.Female).SetFact(birth).SetExtracted(true).SetSource(sourceDescription).SetId("P-1");
Person father = (Person)new Person().SetName("William Bocock").SetFact(new Fact().SetType(FactType.Occupation).SetValue("Toll Collector")).SetExtracted(true).SetSource(sourceDescription).SetId("P-2");
Person mother = (Person)new Person().SetName("Sarah Bocock formerly Brough").SetExtracted(true).SetSource(sourceDescription).SetId("P-3");
Expand Down Expand Up @@ -148,22 +150,28 @@ public void SamuelHamExampleTest()
};

//the marriage fact.
Fact marriage = new Fact()
.SetType(FactType.Marriage)
.SetDate(new DateInfo().SetOriginal("3 November 1828").SetFormal("+1828-11-03"))
.SetPlace(new PlaceReference().SetOriginal("Wilton St George, Wilton, Somerset, England"));
Fact marriage = new()
{
KnownType = FactType.Marriage,
Date = new DateInfo().SetOriginal("3 November 1828").SetFormal("+1828-11-03"),
Place = new PlaceReference().SetOriginal("Wilton St George, Wilton, Somerset, England")
};

//the groom's residence.
Fact samsResidence = new Fact()
.SetType(FactType.Residence)
.SetDate(new DateInfo().SetOriginal("3 November 1828").SetFormal("+1828-11-03"))
.SetPlace(new PlaceReference().SetOriginal("parish of Honiton, Devon, England"));
Fact samsResidence = new()
{
KnownType = FactType.Residence,
Date = new DateInfo().SetOriginal("3 November 1828").SetFormal("+1828-11-03"),
Place = new PlaceReference().SetOriginal("parish of Honiton, Devon, England")
};

//the groom's residence.
Fact lizsResidence = new Fact()
.SetType(FactType.Residence)
.SetDate(new DateInfo().SetOriginal("3 November 1828").SetFormal("+1828-11-03"))
.SetPlace(new PlaceReference().SetOriginal("parish of Wilton, Somerset, England"));
Fact lizsResidence = new()
{
KnownType = FactType.Residence,
Date = new DateInfo().SetOriginal("3 November 1828").SetFormal("+1828-11-03"),
Place = new PlaceReference().SetOriginal("parish of Wilton, Somerset, England")
};

//the groom
Person sam = (Person)new Person().SetName("Samuel Ham").SetGender(GenderType.Male).SetFact(samsResidence).SetExtracted(true).SetSource(transcriptionDescription).SetId("P-1");
Expand Down Expand Up @@ -568,20 +576,26 @@ public void WongAloiauExampleTest()
};

//the birth.
Fact birth = new Fact()
.SetType(FactType.Birth)
.SetDate(new DateInfo().SetOriginal("former Qing 1848 year 11th month 22nd day 23-1 hour").SetFormal("+1848-11-22"))
.SetPlace(new PlaceReference().SetOriginal("Pun Sha Village, See Dai Doo, Chung Shan, Guangdong, China"));
Fact birth = new()
{
KnownType = FactType.Birth,
Date = new DateInfo().SetOriginal("former Qing 1848 year 11th month 22nd day 23-1 hour").SetFormal("+1848-11-22"),
Place = new PlaceReference().SetOriginal("Pun Sha Village, See Dai Doo, Chung Shan, Guangdong, China")
};

//the death.
Fact death = new Fact()
.SetType(FactType.Death)
.SetDate(new DateInfo().SetOriginal("Republic of China year 1920 year 7th mo. 12th day 11-13 hour").SetFormal("+1920-08-03"));
Fact death = new()
{
KnownType = FactType.Death,
Date = new DateInfo().SetOriginal("Republic of China year 1920 year 7th mo. 12th day 11-13 hour").SetFormal("+1920-08-03")
};

//the burial.
Fact burial = new Fact()
.SetType(FactType.Burial)
.SetPlace(new PlaceReference().SetOriginal("Lin Yee Chung Cemetery, Honolulu, Oahu, Hawaii"));
Fact burial = new()
{
KnownType = FactType.Burial,
Place = new PlaceReference().SetOriginal("Lin Yee Chung Cemetery, Honolulu, Oahu, Hawaii")
};

//the principal person
Person aloiau = (Person)new Person().SetName("WONG Aloiau").SetGender(GenderType.Male).SetFact(birth).SetFact(death).SetFact(burial).SetExtracted(true).SetSource(translationDescription).SetId("P-1");
Expand Down Expand Up @@ -711,31 +725,23 @@ private static Person CreateGeorge(PlaceDescription birthPlace, PlaceDescription
Person person = new();
person.SetGender(new Gender(GenderType.Male));

Fact fact = new();
fact.SetId("123");
fact.SetType(FactType.Birth);

fact.SetDate(new DateInfo());
fact.Date.SetOriginal("February 22, 1732");
fact.Date.SetFormal("+1732-02-22");

fact.SetPlace(new PlaceReference());
fact.Place.SetOriginal(birthPlace.Names[0].Value.ToLower());
fact.Place.DescriptionRef = "#" + birthPlace.Id;
Fact fact = new()
{
Id = "123",
KnownType = FactType.Birth,
Date = new DateInfo().SetOriginal("February 22, 1732").SetFormal("+1732-02-22"),
Place = new PlaceReference().SetOriginal(birthPlace.Names[0].Value.ToLower()).SetDescription(birthPlace)
};

person.AddFact(fact);

fact = new Fact();
fact.SetId("456");
fact.SetType(FactType.Death);

fact.SetDate(new DateInfo());
fact.Date.SetOriginal("December 14, 1799");
fact.Date.SetFormal("+1799-12-14T22:00:00");

fact.SetPlace(new PlaceReference());
fact.Place.SetOriginal(deathPlace.Names[0].Value.ToLower());
fact.Place.DescriptionRef = "#" + deathPlace.Id;
fact = new()
{
Id = "456",
KnownType = FactType.Death,
Date = new DateInfo().SetOriginal("December 14, 1799").SetFormal("+1799-12-14T22:00:00"),
Place = new PlaceReference().SetOriginal(deathPlace.Names[0].Value.ToLower()).SetDescription(deathPlace)
};

person.AddFact(fact);

Expand Down Expand Up @@ -768,31 +774,23 @@ private static Person CreateMartha(PlaceDescription birthPlace, PlaceDescription
Person person = new();
person.SetGender(new Gender(GenderType.Male));

Fact fact = new();
fact.SetId("321");
fact.SetType(FactType.Birth);

fact.SetDate(new DateInfo());
fact.Date.SetOriginal("June 2, 1731");
fact.Date.SetFormal("+1731-06-02");

fact.SetPlace(new PlaceReference());
fact.Place.SetOriginal(birthPlace.Names[0].Value.ToLower());
fact.Place.DescriptionRef = "#" + birthPlace.Id;
Fact fact = new()
{
Id = "321",
KnownType = FactType.Birth,
Date = new DateInfo().SetOriginal("June 2, 1731").SetFormal("+1731-06-02"),
Place = new PlaceReference().SetOriginal(birthPlace.Names[0].Value.ToLower()).SetDescription(birthPlace)
};

person.AddFact(fact);

fact = new Fact();
fact.SetId("654");
fact.SetType(FactType.Death);

fact.SetDate(new DateInfo());
fact.Date.SetOriginal("May 22, 1802");
fact.Date.SetFormal("+1802-05-22");

fact.SetPlace(new PlaceReference());
fact.Place.SetOriginal(deathPlace.Names[0].Value.ToLower());
fact.Place.DescriptionRef = "#" + deathPlace.Id;
fact = new()
{
Id = "654",
KnownType = FactType.Death,
Date = new DateInfo().SetOriginal("May 22, 1802").SetFormal("+1802-05-22"),
Place = new PlaceReference().SetOriginal(deathPlace.Names[0].Value.ToLower()).SetDescription(deathPlace)
};

person.AddFact(fact);

Expand Down
25 changes: 12 additions & 13 deletions Gedcomx.Model.Test/OnlineAccountTest.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
using System.Xml.Serialization;

using Gx.Agent;

using Newtonsoft.Json;

using NUnit.Framework;

namespace Gedcomx.Model.Test
{
/// <summary>
/// Test calss for <see cref="Gx.Agent.OnlineAccount"/>
/// Test calss for <see cref="OnlineAccount"/>
/// </summary>
[TestFixture]
public class OnlineAccountTest
{
[Test]
public void OnlineAccountEmpty()
{
var sut = new Gx.Agent.OnlineAccount();
var sut = new OnlineAccount();

VerifyXmlSerialization(sut);
VerifyJsonSerialization(sut);
Expand All @@ -24,9 +26,11 @@ public void OnlineAccountEmpty()
[Test]
public void OnlineAccountFilled()
{
var sut = new Gx.Agent.OnlineAccount
var sut = new OnlineAccount
{
// ExtensibleData
Id = "O-1",
// OnlineAccount
AccountName = "Peter Pan",
ServiceHomepage = new Gx.Common.ResourceReference()
};
Expand All @@ -35,30 +39,25 @@ public void OnlineAccountFilled()
VerifyJsonSerialization(sut);
}

private static void VerifyXmlSerialization(Gx.Agent.OnlineAccount sut)
private static void VerifyXmlSerialization(OnlineAccount sut)
{
var serializer = new XmlSerializer(typeof(Gx.Agent.OnlineAccount));
var serializer = new XmlSerializer(typeof(OnlineAccount));
using var stream = new MemoryStream();
serializer.Serialize(stream, sut);

stream.Seek(0, SeekOrigin.Begin);
var result = new StreamReader(stream).ReadToEnd();
Assert.That(result, Does.Contain("<OnlineAccount "));
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.Contains("id"), Is.EqualTo(sut.Id != null));
Assert.That(result.Contains("accountName"), Is.EqualTo(sut.AccountName != null));
Assert.That(result.Contains("serviceHomepage"), Is.EqualTo(sut.ServiceHomepage != null));
result.ShouldContain(sut);
}

private static void VerifyJsonSerialization(Gx.Agent.OnlineAccount sut)
private static void VerifyJsonSerialization(OnlineAccount sut)
{
JsonSerializerSettings jsonSettings = new()
{
NullValueHandling = NullValueHandling.Ignore
};

Assert.DoesNotThrow(() => JsonConvert.DeserializeObject<Gx.Agent.OnlineAccount>(JsonConvert.SerializeObject(sut, jsonSettings), jsonSettings));
Assert.DoesNotThrow(() => JsonConvert.DeserializeObject<OnlineAccount>(JsonConvert.SerializeObject(sut, jsonSettings), jsonSettings));
}
}
}
Expand Down
Loading

0 comments on commit 782b5f8

Please sign in to comment.