Beispiel #1
0
        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)));
        }
Beispiel #2
0
        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 RedirectableRestRequest()
                                   .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 TestReadOrdinancePolicyInFrench()
        {
            var request  = new RedirectableRestRequest("/platform/ordinances/policy", Method.GET).Accept("text/html").AcceptLanguage("fr");
            var client   = new FilterableRestClient("https://sandbox.familysearch.org");
            var response = client.Execute(request);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNullOrEmpty(response.Content);
        }
Beispiel #4
0
        public void TestRedirectToUri()
        {
            IRestRequest request = new RedirectableRestRequest()
                                   .Accept(MediaTypes.APPLICATION_JSON_TYPE)
                                   .Build("https://sandbox.familysearch.org/platform/redirect?uri=https://familysearch.org/some/path?p1%3Dp1-value%26p2%3Dp2-value", Method.GET);
            var response = tree.Client.Execute(request);

            Assert.IsNotNull(response);
            Assert.AreEqual(HttpStatusCode.TemporaryRedirect, response.StatusCode);
        }
Beispiel #5
0
        public void TestDeleteAccessToken()
        {
            var collection = new CollectionState(new Uri(SANDBOX_URI));

            collection.AuthenticateViaOAuth2Password(Resources.TestUserName, Resources.TestPassword, Resources.TestClientId);
            Assert.IsTrue(collection.IsAuthenticated);
            Link         link    = collection.GetLink(Rel.OAUTH2_TOKEN);
            IRestRequest request = new RedirectableRestRequest()
                                   .Accept(MediaTypes.APPLICATION_JSON_TYPE)
                                   .Build(link.Href + "?access_token=" + collection.CurrentAccessToken, Method.DELETE);
            IRestResponse response = collection.Client.Handle(request);

            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
        }
Beispiel #6
0
        public void TestRedirectToPerson()
        {
            var person = tree.AddPerson(TestBacking.GetCreateMalePerson());

            cleanup.Add(person);
            var          id      = person.Response.Headers.Get("X-ENTITY-ID").Single().Value.ToString();
            IRestRequest request = new RedirectableRestRequest()
                                   .Accept(MediaTypes.APPLICATION_JSON_TYPE)
                                   .Build("https://sandbox.familysearch.org/platform/redirect?person=" + id, Method.GET);
            var response = tree.Client.Execute(request);

            Assert.IsNotNull(response);
            Assert.AreEqual(HttpStatusCode.TemporaryRedirect, response.StatusCode);
        }
Beispiel #7
0
        public void TestRedirectToSourceLinker()
        {
            var person = (FamilyTreePersonState)tree.AddPerson(TestBacking.GetCreateMalePerson()).Get();

            cleanup.Add(person);
            var          uri     = String.Format("https://sandbox.familysearch.org/platform/redirect?context=sourcelinker&person={0}&hintId={1}", person.Person.Id, person.Person.Identifiers[0].Value);
            IRestRequest request = new RedirectableRestRequest()
                                   .Accept(MediaTypes.APPLICATION_JSON_TYPE)
                                   .Build(uri, Method.GET);
            var response = tree.Client.Execute(request);

            Assert.IsNotNull(response);
            Assert.AreEqual(HttpStatusCode.TemporaryRedirect, response.StatusCode);
        }
Beispiel #8
0
        public void TestObtainAccessTokenBadParameters()
        {
            var  collection = new CollectionState(new Uri(SANDBOX_URI));
            Link tokenLink  = collection.GetLink(Rel.OAUTH2_TOKEN);
            IDictionary <String, String> formData = new Dictionary <String, String>();

            formData.Add("grant_type", "authorization_code");
            formData.Add("code", "tGzv3JOkF0XG5Qx2TlKWIA");
            formData.Add("client_id", "WCQY-7J1Q-GKVV-7DNM-SQ5M-9Q5H-JX3H-CMJK");
            IRestRequest request = new RedirectableRestRequest()
                                   .Accept(MediaTypes.APPLICATION_JSON_TYPE)
                                   .ContentType(MediaTypes.APPLICATION_FORM_URLENCODED_TYPE)
                                   .SetEntity(formData)
                                   .Build(tokenLink.Href, Method.POST);
            IRestResponse response = collection.Client.Handle(request);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Beispiel #9
0
        public void TestInitiateAuthorizationGet()
        {
            var  collection = new CollectionState(new Uri(SANDBOX_URI));
            Link tokenLink  = collection.GetLink(Rel.OAUTH2_AUTHORIZE);
            IDictionary <String, String> formData = new Dictionary <String, String>();

            formData.Add("response_type", "code");
            formData.Add("client_id", "ABCD-EFGH-JKLM-NOPQ-RSTU-VWXY-0123-4567");
            formData.Add("redirect_uri", "https://familysearch.org/developers/sandbox-oauth2-redirect");
            IRestRequest request = new RedirectableRestRequest()
                                   .SetEntity(formData)
                                   .Build(tokenLink.Href, Method.GET);
            IRestResponse response = collection.Client.Handle(request);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            var cq = new CQ(response.Content);

            Assert.AreEqual(1, cq.Select("input#userName").Length);
            Assert.AreEqual(1, cq.Select("input#password").Length);
        }
Beispiel #10
0
        public void TestInitiateAuthorizationInvalidParameter()
        {
            var  collection = new CollectionState(new Uri(SANDBOX_URI));
            Link tokenLink  = collection.GetLink(Rel.OAUTH2_AUTHORIZE);
            IDictionary <String, String> formData = new Dictionary <String, String>();

            formData.Add("response_type", "authorize_me");
            formData.Add("client_id", "ABCD-EFGH-JKLM-NOPQ-RSTU-VWXY-0123-4567");
            formData.Add("redirect_uri", "https://familysearch.org/developers/sandbox-oauth2-redirect");
            IRestRequest request = new RedirectableRestRequest()
                                   .ContentType(MediaTypes.APPLICATION_FORM_URLENCODED_TYPE)
                                   .SetEntity(formData)
                                   .Build(tokenLink.Href, Method.POST);
            IRestResponse response = collection.Client.Handle(request);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            //var cq = new CQ(response.Content);
            //Assert.AreEqual(1, cq.Select("p#error").Length);
            Assert.True(response.Content.Contains("Error"));             // An error should occur.
        }
Beispiel #11
0
        /// <summary>
        /// Returns a new person state by invoking the specified URI using the specified client and forcing the specific HTTP verb.
        /// </summary>
        /// <param name="discoveryUri">The URI where the target resides.</param>
        /// <param name="client">The REST API client to use for API calls.</param>
        /// <param name="method">The HTTP verb to use for invoking the discovery URI.</param>
        /// <returns>
        /// A <see cref="PersonState"/> instance containing the REST API response.
        /// </returns>
        public PersonState NewPersonState(Uri discoveryUri, IFilterableRestClient client, Method method)
        {
            IRestRequest request = new RedirectableRestRequest().Accept(MediaTypes.GEDCOMX_JSON_MEDIA_TYPE).Build(discoveryUri, method);

            return(NewPersonState(request, client.Handle(request), client, null));
        }