public void TestReadPersonAncestry() { var grandfather = tree.AddPerson(TestBacking.GetCreateMalePerson()); cleanup.Add(grandfather); var father = tree.AddPerson(TestBacking.GetCreateMalePerson()); cleanup.Add(father); var son = (FamilyTreePersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(son); var rel1 = tree.AddChildAndParentsRelationship(TestBacking.GetCreateChildAndParentsRelationship(grandfather, null, father)); cleanup.Add(rel1); var rel2 = tree.AddChildAndParentsRelationship(TestBacking.GetCreateChildAndParentsRelationship(father, null, son)); cleanup.Add(rel2); son = tree.ReadPersonById(son.Person.Id); var state = son.ReadAncestry(); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.OK, state.Response.StatusCode); Assert.IsNotNull(state.Tree); Assert.IsNotNull(state.Tree.Root); Assert.IsNotNull(state.Tree.Root.Person); Assert.IsNotNull(state.Tree.Root.Father); Assert.IsNotNull(state.Tree.Root.Father.Person); Assert.IsNotNull(state.Tree.Root.Father.Father); Assert.IsNotNull(state.Tree.Root.Father.Father.Person); Assert.AreEqual(grandfather.GetSelfUri(), state.Tree.Root.Father.Father.Person.GetLink("self").Href); Assert.AreEqual(father.GetSelfUri(), state.Tree.Root.Father.Person.GetLink("self").Href); Assert.AreEqual(son.GetSelfUri(), state.Tree.Root.Person.GetLink("self").Href); }
public void TestReadPersonDescendancyWithSpecifiedSpouse() { var father = (FamilyTreePersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(father); var mother = tree.AddPerson(TestBacking.GetCreateFemalePerson()); cleanup.Add(mother); var son = tree.AddPerson(TestBacking.GetCreateMalePerson()); cleanup.Add(son); var rel1 = father.AddSpouse(mother).AddFact(TestBacking.GetMarriageFact()); cleanup.Add(rel1); var rel2 = tree.AddChildAndParentsRelationship(TestBacking.GetCreateChildAndParentsRelationship(father, mother, son)); cleanup.Add(rel2); var state = father.ReadDescendancy(FamilySearchOptions.SpouseId(mother.Headers.Get("X-ENTITY-ID").Single().Value.ToString())); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.OK, state.Response.StatusCode); Assert.IsNotNull(state.Tree); Assert.IsNotNull(state.Tree.Root); Assert.IsNotNull(state.Tree.Root.Person); Assert.IsNotNull(state.Tree.Root.Spouse); Assert.IsNotNull(state.Tree.Root.Children); Assert.AreEqual(1, state.Tree.Root.Children.Count); Assert.IsNotNull(state.Tree.Root.Children[0].Person); Assert.AreEqual(father.Person.Id, state.Tree.Root.Person.Id); Assert.AreEqual(mother.Headers.Get("X-ENTITY-ID").Single().Value.ToString(), state.Tree.Root.Spouse.Id); Assert.AreEqual(son.Headers.Get("X-ENTITY-ID").Single().Value.ToString(), state.Tree.Root.Children[0].Person.Id); }
public void TestReadPersonWithMultiplePendingModificationsActivated() { // Make a separate copy from the main tree used in other tests var tempTree = new FamilySearchFamilyTree(true); var features = new List <Feature>(); tempTree.AuthenticateViaOAuth2Password(Resources.TestUserName, Resources.TestPassword, Resources.TestClientId); // Get all the features that are pending IRestRequest request = new RedirectableRestRequest() .Accept(MediaTypes.APPLICATION_JSON_TYPE) .Build("https://sandbox.familysearch.org/platform/pending-modifications", Method.GET); IRestResponse response = tempTree.Client.Handle(request); // Get each pending feature features.AddRange(response.ToIRestResponse <FamilySearchPlatform>().Data.Features); // Add every pending feature to the tree's current client tempTree.Client.AddFilter(new ExperimentsFilter(features.Select(x => x.Name).ToArray())); var state = tempTree.AddPerson(TestBacking.GetCreateMalePerson()); cleanup.Add(state); // Ensure a response came back Assert.IsNotNull(state); var requestedFeatures = String.Join(",", state.Request.GetHeaders().Get("X-FS-Feature-Tag").Select(x => x.Value.ToString())); // Ensure each requested feature was found in the request headers Assert.IsTrue(features.TrueForAll(x => requestedFeatures.Contains(x.Name))); }
public void TestDeleteMemoryPersona() { var converter = new ImageConverter(); var bytes = (Byte[])converter.ConvertTo(TestBacking.GetCreatePhoto(), typeof(Byte[])); var dataSource = new BasicDataSource(Guid.NewGuid().ToString("n") + ".jpg", "image/jpeg", bytes); var description = new SourceDescription().SetTitle("PersonImage").SetCitation("Citation for PersonImage").SetDescription("Description"); var image = (SourceDescriptionState)tree.AddArtifact(description, dataSource).Get(); cleanup.Add(image); var person = (FamilyTreePersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(person); var persona = (PersonState)image.AddPersona(new Person().SetName("John Smith")).Get(); person.AddPersonaReference(persona); // Confirm it is there. var personas = tree.ReadPerson(new Uri(person.GetSelfUri())); Assert.Greater(personas.Person.Evidence.Count, 0); var state = personas.DeletePersonaReference(personas.GetPersonaReference()); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.NoContent, state.Response.StatusCode); }
public void TestDeletePreferredParentRelationship() { var father = tree.AddPerson(TestBacking.GetCreateMalePerson()); cleanup.Add(father); var mother = tree.AddPerson(TestBacking.GetCreateFemalePerson()); cleanup.Add(mother); var son = (FamilyTreePersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(son); var chapr = tree.AddChildAndParentsRelationship(TestBacking.GetCreateChildAndParentsRelationship(father, mother, son)); cleanup.Add(chapr); var me = tree.ReadCurrentUser(); // Ensure the target relationship exists var relationship = ((FamilyTreePersonParentsState)son.ReadParents()).ChildAndParentsRelationships.First(); var state = son.ReadChildAndParentsRelationship(relationship); tree.UpdatePreferredParentRelationship(me.User.TreeUserId, son.Person.Id, state); var state2 = tree.DeletePreferredParentRelationship(me.User.TreeUserId, son.Person.Id); Assert.AreEqual(HttpStatusCode.NoContent, state2.Response.StatusCode); Assert.IsNotNull(state2.Headers.Get("Content-Location").Single()); }
public void TestUploadPhotoForPerson() { var person = (FamilyTreePersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(person); var converter = new ImageConverter(); var bytes = (Byte[])converter.ConvertTo(TestBacking.GetCreatePhoto(), typeof(Byte[])); var dataSource = new BasicDataSource(Guid.NewGuid().ToString("n") + ".jpg", "image/jpeg", bytes); var state = person.AddArtifact(new SourceDescription() { Titles = new List <TextValue>() { new TextValue("PersonImage") }, Citations = new List <SourceCitation>() { new SourceCitation() { Value = "Citation for PersonImage" } } }, dataSource); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.Created, state.Response.StatusCode); state.Delete(); }
public void TestDeleteSourceDescription() { var state = tree.AddSourceDescription(TestBacking.GetCreateSourceDescription()).Delete(); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.NoContent, state.Response.StatusCode); }
public void TestReadMergedPerson() { var person1 = (FamilyTreePersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(person1); var person2 = (FamilyTreePersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(person2); var merge = person1.ReadMergeAnalysis(person2); var m = new Merge(); m.ResourcesToCopy = new List <ResourceReference>(); m.ResourcesToDelete = new List <ResourceReference>(); m.ResourcesToCopy.AddRange(merge.Analysis.DuplicateResources); m.ResourcesToCopy.AddRange(merge.Analysis.ConflictingResources.Select(x => x.DuplicateResource)); merge.DoMerge(m); // Person2 was merged with Person1 var state = tree.ReadPersonById(person2.Person.Id); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.MovedPermanently, state.Response.StatusCode); var link1 = person1.GetSelfUri(); Assert.IsNotNullOrEmpty(link1); var link2 = state.GetSelfUri(); Assert.IsNotNullOrEmpty(link2); Assert.AreEqual(link1, link2); }
public void TestFileWriting() { string fileName; using (var ms = new MemoryStream()) { var file = new GedcomxOutputStream(ms, new DefaultXmlSerialization()); var gx = new Gx.Gedcomx(); gx.Persons = new List <Gx.Conclusion.Person>(); gx.Persons.Add(TestBacking.GetCreateMalePerson()); file.AddResource(gx); file.Dispose(); fileName = Path.GetTempFileName(); var output = System.IO.File.OpenWrite(fileName); var bytes = ms.ToArray(); output.Write(bytes, 0, bytes.Length); output.Flush(); output.Close(); output.Dispose(); } // Verify basic reading of the zip file created above using (var zip = ZipFile.OpenRead(fileName)) { Assert.AreEqual(2, zip.Entries.Count); } }
public void TestFileReading() { var file = TestBacking.WriteBytesToDisk(Resources.SampleGEDX); var fi = new FileInfo(file); using (GedcomxFile test = new GedcomxFile(fi)) { Assert.AreEqual(4, test.Entries.Count()); var gedxEntry = test.Entries.Where(x => x.ZipEntry.FullName == "tree.xml").Single(); var imageEntry1 = test.Entries.Where(x => x.ZipEntry.FullName == "person1.png").Single(); var imageEntry2 = test.Entries.Where(x => x.ZipEntry.FullName == "person2.png").Single(); Assert.AreEqual("application/x-gedcomx-v1+xml", gedxEntry.GetAttribute("Content-Type")); Assert.AreEqual("image/png", imageEntry1.GetAttribute("Content-Type")); Assert.AreEqual("image/png", imageEntry2.GetAttribute("Content-Type")); var gedx = test.ReadResource <Gx.Gedcomx>(gedxEntry); var image1 = test.GetResourceStream(imageEntry1); var image2 = test.GetResourceStream(imageEntry2); Assert.AreEqual(4, gedx.Persons.Count); Assert.AreEqual(4, gedx.Relationships.Count); Assert.DoesNotThrow(() => new Bitmap(image1)); Assert.DoesNotThrow(() => new Bitmap(image2)); } }
public void TestUpdatePersonSourceReference() { var state = (PersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(state); var sr = TestBacking.GetPersonSourceReference(); sr.Tags = new List <Tag>(); sr.Tags.Add(new Tag(ChangeObjectType.Name)); state.AddSourceReference(sr); var state3 = tree.ReadPerson(new Uri(state.GetSelfUri())); var tag = state3.Person.Sources[0].Tags.First(); state3.Person.Sources[0].Tags.Remove(tag); cleanup.Add(state3); var state2 = state.UpdateSourceReferences(state3.Person); cleanup.Add(state2); Assert.DoesNotThrow(() => state2.IfSuccessful()); Assert.AreEqual(HttpStatusCode.NoContent, state2.Response.StatusCode); state3.Person.Sources[0].Tags.Add(tag); state2 = state.UpdateSourceReferences(state3.Person); Assert.DoesNotThrow(() => state2.IfSuccessful()); Assert.AreEqual(HttpStatusCode.NoContent, state2.Response.StatusCode); }
public void TestDeletePreferredSpouseRelationship() { var p = (PersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(p); var s1 = tree.AddPerson(TestBacking.GetCreateFemalePerson()); cleanup.Add(s1); var s2 = tree.AddPerson(TestBacking.GetCreateFemalePerson()); cleanup.Add(s2); p.AddSpouse(s1); p.AddSpouse(s2); var me = tree.ReadCurrentUser(); var person = tree.ReadPersonById(p.Person.Id); // Ensure the target relationship exists person.LoadSpouseRelationships(); var state = (IPreferredRelationshipState)person.ReadRelationship(person.Entity.Relationships[0]); tree.UpdatePreferredSpouseRelationship(me.User.TreeUserId, p.Person.Id, state); var state2 = tree.DeletePreferredSpouseRelationship(me.User.TreeUserId, p.Person.Id); Assert.AreEqual(HttpStatusCode.NoContent, state2.Response.StatusCode); Assert.IsNotNull(state2.Headers.Get("Content-Location").Single()); }
public void TestUploadMultiplePhotoMemories() { var converter = new ImageConverter(); var bytes1 = (Byte[])converter.ConvertTo(TestBacking.GetCreatePhoto(), typeof(Byte[])); var bytes2 = (Byte[])converter.ConvertTo(TestBacking.GetCreatePhoto(), typeof(Byte[])); var dataSource1 = new BasicDataSource(Guid.NewGuid().ToString("n") + ".jpg", "image/jpeg", bytes1); var dataSource2 = new BasicDataSource(Guid.NewGuid().ToString("n") + ".jpg", "image/jpeg", bytes2); var description = new SourceDescription().SetTitle(new TextValue().SetValue("PersonImage")).SetCitation("Citation for PersonImage"); var artifacts = new List <IDataSource>(); artifacts.Add(dataSource1); artifacts.Add(dataSource2); IRestRequest request = new RestRequest() .AddHeader("Authorization", "Bearer " + tree.CurrentAccessToken) .Accept(MediaTypes.GEDCOMX_JSON_MEDIA_TYPE) .ContentType(MediaTypes.MULTIPART_FORM_DATA_TYPE) .Build("https://sandbox.familysearch.org/platform/memories/memories", Method.POST); foreach (var artifact in artifacts) { String mediaType = artifact.ContentType; foreach (TextValue value in description.Titles) { request.AddFile("title", Encoding.UTF8.GetBytes(value.Value), null, MediaTypes.TEXT_PLAIN_TYPE); } foreach (SourceCitation citation in description.Citations) { request.AddFile("citation", Encoding.UTF8.GetBytes(citation.Value), null, MediaTypes.TEXT_PLAIN_TYPE); } if (artifact.Name != null) { request.Files.Add(new FileParameter() { Name = "artifact", FileName = artifact.Name, ContentType = artifact.ContentType, Writer = new Action <Stream>(s => { artifact.InputStream.Seek(0, SeekOrigin.Begin); using (var ms = new MemoryStream(artifact.InputStream.ReadAsBytes())) using (var reader = new StreamReader(ms)) { reader.BaseStream.CopyTo(s); } }) }); } } var state = tree.Client.Handle(request); Assert.IsNotNull(state); Assert.AreEqual(HttpStatusCode.Created, state.StatusCode); }
public void TestDeletePerson() { // Assume the ability to add a person is working var state = tree.AddPerson(TestBacking.GetCreateMalePerson()); var state2 = (PersonState)state.Delete(); Assert.DoesNotThrow(() => state2.IfSuccessful()); Assert.AreEqual(HttpStatusCode.NoContent, state2.Response.StatusCode); }
public void TestCreateSourceDescription() { var state = tree.AddSourceDescription(TestBacking.GetCreateSourceDescription()); cleanup.Add(state); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.Created, state.Response.StatusCode); }
public void TestReadPersonChangeSummary() { var person = (FamilyTreePersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(person); var state = person.ReadChangeHistory(); Assert.DoesNotThrow(() => state.IfSuccessful()); }
public void TestCreateNote() { var state = (PersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()); cleanup.Add(state); var note = TestBacking.GetCreateNote(); var state2 = state.AddNote(note); Assert.DoesNotThrow(() => state2.IfSuccessful()); }
public void TestUpdateSourceDescription() { var description = (SourceDescriptionState)tree.AddSourceDescription(TestBacking.GetCreateSourceDescription()).Get(); cleanup.Add(description); var state = description.Update(description.SourceDescription); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.NoContent, state.Response.StatusCode); }
public void TestReadSourceDescription() { var state = (SourceDescriptionState)tree.AddSourceDescription(TestBacking.GetCreateSourceDescription()).Get(); cleanup.Add(state); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.OK, state.Response.StatusCode); Assert.IsNotNull(state.SourceDescription); }
public void TestDeleteSourceDescriptionsFromAUserDefinedCollection() { var description = collection.AddSourceDescription(TestBacking.GetCreateSourceDescription()); cleanup.Add(description); var state = description.Delete(); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.NoContent, state.Response.StatusCode); }
public void TestCreatePersonLifeSketch() { var person = (FamilyTreePersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(person); var state = (FamilyTreePersonState)person.Post(TestBacking.GetCreatePersonLifeSketch(person.Person.Id)); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.NoContent, state.Response.StatusCode); }
public void TestHeadPerson() { var state = tree.AddPerson(TestBacking.GetCreateMalePerson()); cleanup.Add(state); var state2 = (PersonState)state.Head(); Assert.DoesNotThrow(() => state2.IfSuccessful()); Assert.AreEqual(HttpStatusCode.OK, state2.Response.StatusCode); }
public void TestReadUser() { var person = (FamilyTreePersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(person); var state = person.ReadContributor(person.GetName()); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.OK, state.Response.StatusCode); }
public void TestUpdatePersonConclusion() { var state = (PersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(state); state.Person.Facts.Add(TestBacking.GetBirthFact()); var state2 = state.UpdateConclusions(state.Person); Assert.DoesNotThrow(() => state2.IfSuccessful()); }
public void TestDeleteMemory() { var converter = new ImageConverter(); var bytes = (Byte[])converter.ConvertTo(TestBacking.GetCreatePhoto(), typeof(Byte[])); var dataSource = new BasicDataSource(Guid.NewGuid().ToString("n") + ".jpg", "image/jpeg", bytes); var image = (SourceDescriptionState)tree.AddArtifact(new SourceDescription().SetTitle("PersonImage").SetCitation("Citation for PersonImage"), dataSource).Get(); var state = image.Delete(); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.NoContent, state.Response.StatusCode); }
public void TestReadPersonPossibleDuplicates() { var person = (FamilyTreePersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(person); var state = person.ReadMatches(); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.AreEqual(HttpStatusCode.OK, state.Response.StatusCode); Assert.Greater(state.Results.Entries.Count, 0); }
public void TestReadPerson() { var person = tree.AddPerson(TestBacking.GetCreateMalePerson()); cleanup.Add(person); var state = tree.ReadPerson(new Uri(person.GetSelfUri())); Assert.DoesNotThrow(() => state.IfSuccessful()); Assert.IsNotNull(state.Person); Assert.IsNotNullOrEmpty(state.Person.Id); }
public void TestReadNotModifiedPerson() { var state = (PersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(state); var cache = new CacheDirectives(state); var state2 = tree.ReadPerson(new Uri(state.GetSelfUri()), cache); Assert.DoesNotThrow(() => state2.IfSuccessful()); Assert.AreEqual(HttpStatusCode.NotModified, state2.Response.StatusCode); }
public void TestCreatePersonConclusion() { var state = (PersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get(); cleanup.Add(state); Person conclusion = TestBacking.GetCreatePersonConclusion(state.Person.Id); var state2 = state.UpdateConclusions(conclusion); Assert.IsNotNull(state2); Assert.DoesNotThrow(() => state2.IfSuccessful()); }
public void TestCreatePerson() { var result = tree.AddPerson(TestBacking.GetCreateMalePerson()); cleanup.Add(result); Assert.DoesNotThrow(() => result.IfSuccessful()); var person = (PersonState)result.Get(); Assert.IsNotNull(person.Person); Assert.IsNotNullOrEmpty(person.Person.Id); }