Exemplo n.º 1
0
        public T Deserialize <T>(IRestResponse response)
        {
            Type type = typeof(T);

            if (type == typeof(TemplateResponseModel))
            {
                TemplateResponseModel model = new TemplateResponseModel();
                model.Content = HttpUtility.HtmlDecode(response.Content);

                if (model.Content.StartsWith("<pre>"))
                {
                    if (!model.Content.StartsWith("<pre><html>"))
                    {
                        string[] resultRows = model.Content.Split('\n');
                        resultRows = resultRows.Skip(1).Take(resultRows.Length - 2).ToArray();
                        foreach (string row in resultRows)
                        {
                            model.Results.Add(row.Split('\t'));
                        }
                    }
                }

                return((T)(object)model);
            }
            else
            {
                return((T)Activator.CreateInstance(type));
            }
        }
        public void TemplateEndpointIntegrationTest_GetTemplate_Insert_Triple_TemplateEntryMissing()
        {
            //assemble
            string templateName = "Insert_Triple_(Fuseki)";

            //act
            TemplateResponseModel response = TemplateEndpoint.GetTemplate(templateName, "a", "b");

            //assert
            Assert.IsNotNull(response);
            Assert.AreEqual("Error: Template entry 'Object' is missing", response.Content);
            Assert.AreEqual(0, response.Results.Count);
        }
        public void TemplateEndpointIntegrationTest_PostTemplate_Get_Resources()
        {
            //assemble
            string templateName = "Get_Resources";

            //act
            TemplateResponseModel response = TemplateEndpoint.PostTemplate(templateName);

            //assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Results.Count > 0);
            Assert.AreEqual(1, response.Results[0].Length);
        }
        public void TemplateEndpointIntegrationTest_PostTemplate_Raw_SPARQL()
        {
            //assemble
            string templateName = "Raw_SPARQL";

            //act
            TemplateResponseModel response = TemplateEndpoint.PostTemplate(templateName, "SELECT DISTINCT * WHERE { ?s ?p ?o } LIMIT 20");

            //assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Results.Count > 0);
            Assert.IsTrue(response.Results.Count <= 20);
            Assert.AreEqual(3, response.Results[0].Length);
        }
        public void TemplateEndpointIntegrationTest_PostTemplate_Insert_Triple_Success()
        {
            //assemble
            string templateName = "Insert_Triple_(Fuseki)";

            //act
            TemplateResponseModel response = TemplateEndpoint.PostTemplate(
                templateName,
                "https://github.com/niklr/RdfstoreNet/subjects/a",
                "https://github.com/niklr/RdfstoreNet/predicates/b",
                "https://github.com/niklr/RdfstoreNet/objects/c");

            //assert
            Assert.IsNotNull(response);
        }
        public void TemplateEndpointIntegrationTest_PostTemplate_Insert_Triple_TemplateEntryMissing()
        {
            //assemble
            string templateName = "Insert_Triple_(Fuseki)";

            //act
            TemplateResponseModel response = TemplateEndpoint.PostTemplate(
                templateName,
                "https://github.com/niklr/RdfstoreNet/subjects/a",
                "https://github.com/niklr/RdfstoreNet/predicates/b");

            //assert
            Assert.IsNotNull(response);
            Assert.AreEqual("Error: Template entry 'Object' is missing", response.Content);
            Assert.AreEqual(0, response.Results.Count);
        }