Skip to content

Commit

Permalink
Add Tests to fix FamilySearch#43 and FamilySearch#48.
Browse files Browse the repository at this point in the history
- Person with Subject.
  • Loading branch information
JoergHoffmannatGitHub committed Jan 28, 2023
1 parent 782b5f8 commit 1614117
Show file tree
Hide file tree
Showing 17 changed files with 448 additions and 272 deletions.
43 changes: 23 additions & 20 deletions FamilySearch.Api/Ft/ChildAndParentsRelationshipState.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
using Gx.Fs;
using Gx.Rs.Api;
using RestSharp;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gx.Rs.Api.Util;
using System.Net;

using FamilySearch.Api.Util;

using Gedcomx.Model;
using Gx.Fs.Tree;
using Gx.Conclusion;

using Gx.Common;
using Gx.Source;
using Gx.Conclusion;
using Gx.Fs;
using Gx.Fs.Tree;
using Gx.Links;
using FamilySearch.Api.Util;
using Gx.Rs.Api;
using Gx.Rs.Api.Util;
using Gx.Source;

using RestSharp;

namespace FamilySearch.Api.Ft
{
Expand Down Expand Up @@ -195,7 +198,7 @@ public EvidenceReference EvidenceReference
get
{
ChildAndParentsRelationship relationship = Relationship;
return relationship == null ? null : relationship.Evidence == null ? null : relationship.Evidence.FirstOrDefault();
return relationship == null ? null : relationship.AnyEvidence() ? null : relationship.Evidence.FirstOrDefault();
}
}

Expand All @@ -210,7 +213,7 @@ public SourceReference MediaReference
get
{
ChildAndParentsRelationship relationship = Relationship;
return relationship == null ? null : relationship.Media == null ? null : relationship.Media.FirstOrDefault();
return relationship == null ? null : relationship.AnyMedia() ? null : relationship.Media.FirstOrDefault();
}
}

Expand Down Expand Up @@ -604,14 +607,14 @@ public ChildAndParentsRelationshipState UpdateSourceReferences(SourceReference[]
protected ChildAndParentsRelationshipState UpdateSourceReferences(ChildAndParentsRelationship relationship, params IStateTransitionOption[] options)
{
String target = GetSelfUri() + "/" + Rel.SOURCE_REFERENCES;
//Link conclusionsLink = GetLink(Rel.SOURCE_REFERENCES);
//if (conclusionsLink != null && conclusionsLink.Href != null)
//{
// target = conclusionsLink.Href;
//}

FamilySearchPlatform gx = new FamilySearchPlatform();
//Link conclusionsLink = GetLink(Rel.SOURCE_REFERENCES);
//if (conclusionsLink != null && conclusionsLink.Href != null)
//{
// target = conclusionsLink.Href;
//}


FamilySearchPlatform gx = new FamilySearchPlatform();
gx.ChildAndParentsRelationships = new List<ChildAndParentsRelationship>() { relationship };
IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).SetEntity(gx).Build(target, Method.POST);
return ((FamilyTreeStateFactory)this.stateFactory).NewChildAndParentsRelationshipState(request, Invoke(request, options), this.Client, this.CurrentAccessToken);
Expand Down
132 changes: 110 additions & 22 deletions Gedcomx.Model.Test/GedcomxTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Gx.Agent;
using Gx.Common;
using Gx.Conclusion;
using Gx.Records;
using Gx.Model.Collections;
using Gx.Source;
using Gx.Types;

Expand Down Expand Up @@ -62,13 +62,39 @@ public void EmmaBocockExampleTest()
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");
Person emma = new()
{
Id = "P-1",
Names = { "Emma Bocock" },
Gender = new Gender(GenderType.Female),
Facts = { birth },
Extracted = true,
Sources = { sourceDescription }
};
Person father = new()
{
Id = "P-2",
Names = { "William Bocock" },
Facts = { new Fact() { KnownType = FactType.Occupation, Value = "Toll Collector" } },
Extracted = true,
Sources = { sourceDescription }
};
Person mother = new()
{
Id = "P-3",
Names = { "Sarah Bocock formerly Brough" },
Extracted = true,
Sources = { sourceDescription }
};
Relationship fatherRelationship = new Relationship().SetType(RelationshipType.ParentChild).SetPerson1(father).SetPerson2(emma);
Relationship motherRelationship = new Relationship().SetType(RelationshipType.ParentChild).SetPerson1(mother).SetPerson2(emma);
Document analysis = (Document)new Document().SetText("...Jane Doe's analysis document...").SetId("D-1");
Person emmaConclusion = (Person)new Person().SetEvidence(emma).SetAnalysis(analysis).SetId("C-1");
Person emmaConclusion = new()
{
Id = "C-1",
Evidence = { emma },
Analysis = analysis,
};
Gx.Gedcomx gx = new Gx.Gedcomx()
.SetAgent(contributor)
.SetAgent(repository)
Expand Down Expand Up @@ -174,18 +200,56 @@ public void SamuelHamExampleTest()
};

//the groom
Person sam = (Person)new Person().SetName("Samuel Ham").SetGender(GenderType.Male).SetFact(samsResidence).SetExtracted(true).SetSource(transcriptionDescription).SetId("P-1");
Person sam = new()
{
Id = "P-1",
Names = { "Samuel Ham" },
Facts = { samsResidence },
Extracted = true,
Sources = { transcriptionDescription }
};

//the bride.
Person liz = (Person)new Person().SetName("Elizabeth Spiller").SetGender(GenderType.Female).SetFact(lizsResidence).SetExtracted(true).SetSource(transcriptionDescription).SetId("P-2");
Person liz = new()
{
Id = "P-2",
Names = { "Elizabeth Spiller" },
Facts = { lizsResidence },
Extracted = true,
Sources = { transcriptionDescription }
};

//witnesses
Person witness1 = (Person)new Person().SetName("Jno. Pain").SetExtracted(true).SetSource(transcriptionDescription).SetId("P-3");
Person witness2 = (Person)new Person().SetName("R.G. Halls").SetExtracted(true).SetSource(transcriptionDescription).SetId("P-4");
Person witness3 = (Person)new Person().SetName("Peggy Hammet").SetExtracted(true).SetSource(transcriptionDescription).SetId("P-5");
Person witness1 = new()
{
Id = "P-3",
Names = { "Jno. Pain" },
Extracted = true,
Sources = { transcriptionDescription }
};
Person witness2 = new()
{
Id = "P-4",
Names = { "R.G. Halls" },
Extracted = true,
Sources = { transcriptionDescription }
};
Person witness3 = new()
{
Id = "P-5",
Names = { "Peggy Hammet" },
Extracted = true,
Sources = { transcriptionDescription }
};

//officiator
Person officiator = (Person)new Person().SetName("David Smith Stone").SetExtracted(true).SetSource(transcriptionDescription).SetId("P-6");
Person officiator = new()
{
Id = "P-6",
Names = { "David Smith Stone" },
Extracted = true,
Sources = { transcriptionDescription }
};

//the relationship.
Relationship marriageRelationship = (Relationship)new Relationship().SetType(RelationshipType.Couple).SetPerson1(sam).SetPerson2(liz).SetFact(marriage).SetExtracted(true);
Expand All @@ -207,7 +271,12 @@ public void SamuelHamExampleTest()
Document analysis = (Document)new Document().SetText("...Jane Doe's analysis document...").SetId("D-2");

//Jane Doe's conclusions about a person.
Person samConclusion = (Person)new Person().SetEvidence(sam).SetAnalysis(analysis).SetId("C-1");
Person samConclusion = new()
{
Id = "C-1",
Evidence = { sam },
Analysis = analysis,
};

Gx.Gedcomx gx = new Gx.Gedcomx()
.SetAgent(janeDoe)
Expand Down Expand Up @@ -569,7 +638,7 @@ public void WongAloiauExampleTest()
Id = "S-4",
About = "#" + translation.Id,
Titles = { "Translation of Grave Marker of WONG Aloiau, Lin Yee Chung Cemetery, Honolulu, Oahu, Hawaii" },
Citations= { new SourceCitation().SetValue("WONG Aloiau gravestone, Lin Yee Chung Cemetery, Honolulu, Oahu, Hawaii; visited May 1975 by Jane Doe. Translation by HANYU Pinyin 王大年.") },
Citations = { new SourceCitation().SetValue("WONG Aloiau gravestone, Lin Yee Chung Cemetery, Honolulu, Oahu, Hawaii; visited May 1975 by Jane Doe. Translation by HANYU Pinyin 王大年.") },
Attribution = translationAttribution,
KnownResourceType = ResourceType.DigitalArtifact,
Sources = { new SourceReference().SetDescription(transcriptionDescription) }
Expand Down Expand Up @@ -598,10 +667,24 @@ public void WongAloiauExampleTest()
};

//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");
Person aloiau = new()
{
Id = "P-1",
Names = { "WONG Aloiau" },
Gender = new Gender(GenderType.Male),
Facts = { birth, death, burial },
Extracted = true,
Sources = { translationDescription }
};

//the father of the principal (with an aka name).
Person father = (Person)new Person().SetName("Lo Yau").SetName(new Name().SetType(NameType.AlsoKnownAs).SetNameForm(new NameForm().SetFullText("Young Hong Wong"))).SetExtracted(true).SetSource(translationDescription).SetId("P-2");
Person father = new()
{
Id = "P-2",
Names = { "Lo Yau", new Name() { KnownType = NameType.AlsoKnownAs }.SetNameForm(new NameForm().SetFullText("Young Hong Wong")) },
Extracted = true,
Sources = { translationDescription }
};

//the relationship.
Relationship fatherRelationship = new Relationship().SetType(RelationshipType.ParentChild).SetPerson1(father).SetPerson2(aloiau);
Expand All @@ -610,7 +693,12 @@ public void WongAloiauExampleTest()
Document analysis = (Document)new Document().SetText("...Jane Doe's analysis document...").SetId("D-3");

//Jane Doe's conclusions about a person.
Person aloiauConclusion = (Person)new Person().SetEvidence(aloiau).SetAnalysis(analysis).SetId("C-1");
Person aloiauConclusion = new()
{
Id = "C-1",
Evidence = { aloiau },
Analysis = analysis
};

Gx.Gedcomx gx = new Gx.Gedcomx()
.SetAgent(janeDoe)
Expand Down Expand Up @@ -733,7 +821,7 @@ private static Person CreateGeorge(PlaceDescription birthPlace, PlaceDescription
Place = new PlaceReference().SetOriginal(birthPlace.Names[0].Value.ToLower()).SetDescription(birthPlace)
};

person.AddFact(fact);
person.SetFact(fact);

fact = new()
{
Expand All @@ -743,9 +831,9 @@ private static Person CreateGeorge(PlaceDescription birthPlace, PlaceDescription
Place = new PlaceReference().SetOriginal(deathPlace.Names[0].Value.ToLower()).SetDescription(deathPlace)
};

person.AddFact(fact);
person.SetFact(fact);

List<Name> names = new();
Names names = new();
Name name = new();
NameForm nameForm = new();
nameForm.SetFullText("George Washington");
Expand Down Expand Up @@ -782,7 +870,7 @@ private static Person CreateMartha(PlaceDescription birthPlace, PlaceDescription
Place = new PlaceReference().SetOriginal(birthPlace.Names[0].Value.ToLower()).SetDescription(birthPlace)
};

person.AddFact(fact);
person.SetFact(fact);

fact = new()
{
Expand All @@ -792,9 +880,9 @@ private static Person CreateMartha(PlaceDescription birthPlace, PlaceDescription
Place = new PlaceReference().SetOriginal(deathPlace.Names[0].Value.ToLower()).SetDescription(deathPlace)
};

person.AddFact(fact);
person.SetFact(fact);

List<Name> names = new();
Names names = new();
Name name = new();
NameForm nameForm = new();
nameForm.SetFullText("Martha Dandridge Custis");
Expand Down
90 changes: 90 additions & 0 deletions Gedcomx.Model.Test/PersonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Xml.Serialization;

using Gx.Common;
using Gx.Conclusion;
using Gx.Links;
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="Person"/>
/// </summary>
[TestFixture]
public class PersonTest
{
[Test]
public void PersonEmpty()
{
var sut = new Person();

VerifyXmlSerialization(sut);
VerifyJsonSerialization(sut);
}

[Test]
public void PersonObjectInitialization()
{
var sut = new Person
{
// ExtensibleData
Id = "A-1",
// HypermediaEnabledData
Links = { new Link(), { "rel", new Uri("https://www.familysearch.org/platform/collections/tree") }, { "rel", "template" } },
// Conclusion
KnownConfidence = ConfidenceLevel.Medium,
SortKey = "sortKey",
Lang = "lang",
Attribution = new Attribution(),
Sources = { new SourceDescription { Id = "S-1" }, new SourceReference() },
Analysis = new ResourceReference(),
Notes = { new Note() },
// Subject
Extracted = true,
Evidence = { new EvidenceReference() },
Media = { new SourceReference(), new SourceDescription() { Id = "D-1" } },
Identifiers = { new Identifier() },
// Person
Principal = false,
Private = true,
Living = true,
Gender = new Gender(GenderType.Female),
Names = { "Emma Bocock" },
Facts = { new Fact() },
Fields = { new Field() },
DisplayExtension = new DisplayProperties(),
DiscussionReferences = { new DiscussionReference() }
};

VerifyXmlSerialization(sut);
VerifyJsonSerialization(sut);
}

private static void VerifyXmlSerialization(Person sut)
{
var serializer = new XmlSerializer(typeof(Person));
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(Person sut)
{
JsonSerializerSettings jsonSettings = new()
{
NullValueHandling = NullValueHandling.Ignore
};

Assert.DoesNotThrow(() => JsonConvert.DeserializeObject<Person>(JsonConvert.SerializeObject(sut, jsonSettings), jsonSettings));
}
}
}
Loading

0 comments on commit 1614117

Please sign in to comment.