Пример #1
0
        public void ModelNameTest()
        {
            Uri    modelUri  = new Uri("http://www.example.com");
            Uri    modelUri2 = new Uri("http://www.example.com/");
            IModel m1        = Store.GetModel(modelUri);

            m1.Clear();
            IModel m2 = Store.GetModel(modelUri2);

            Assert.IsTrue(m1.IsEmpty);
            Assert.IsTrue(m2.IsEmpty);

            PersonContact c = m1.CreateResource <PersonContact>(new Uri("http://www.example.com/testResource"));

            c.NameFamily = "Doe";
            c.Commit();

            Assert.IsFalse(m1.IsEmpty);
            Assert.IsFalse(m2.IsEmpty);

            m1.Clear();

            Assert.IsTrue(m1.IsEmpty);
            Assert.IsTrue(m2.IsEmpty);
        }
Пример #2
0
        Contact CreateContact(IModel m, string nameGiven, List <string> nameAdditional, string nameFamily, DateTime birthDate, string emailAddress, string country, string street, string pocode, string city)
        {
            Uri           contactUri = new Uri("semio:" + nameGiven + ":" + Guid.NewGuid().ToString());
            PersonContact c          = m.CreateResource <PersonContact>(contactUri);
            StringBuilder b          = new StringBuilder();

            foreach (string n in nameAdditional)
            {
                b.Append(n);
                b.Append(" ");
                c.NameAdditional.Add(n);
            }
            if (b.Length > 1)
            {
                b.Remove(b.Length - 1, 1);
            }
            c.Fullname   = string.Format("{0} {1} {2}", nameGiven, b, nameFamily);
            c.NameGiven  = nameGiven;
            c.NameFamily = nameFamily;
            c.BirthDate  = birthDate;
            c.EmailAddresses.Add(CreateEmailAddress(m, emailAddress));
            c.PostalAddresses.Add(CreatePostalAddress(m, country, street, pocode, city));

            c.Commit();
            return(c);
        }
Пример #3
0
        public void TestStringSerializeResourceWithMapping()
        {
            PersonContact contact = new PersonContact(new Uri("http://example.com/ex"));

            contact.NameGiven = "Peter";
            var res      = SparqlSerializer.SerializeResource(contact);
            var expected = "<http://example.com/ex> <http://www.semanticdesktop.org/ontologies/2007/03/22/nco#nameGiven> 'Peter'; <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.semanticdesktop.org/ontologies/2007/03/22/nco#PersonContact>. ";

            Assert.AreEqual(expected, res);

            contact.Language = "DE";
            res = SparqlSerializer.SerializeResource(contact);
            Assert.AreEqual(expected, res);
        }
Пример #4
0
 public void TestAddMultipleResources()
 {
     Assert.Inconclusive("Reevaluate with more recent version of virtuoso client library.");
     Model.Clear();
     for (int j = 1; j < 7; j++)
     {
         for (int i = 1; i < 1000; i++)
         {
             using (PersonContact pers = Model.CreateResource <PersonContact>())
             {
                 pers.Fullname = string.Format("Name {0}", i * j);
                 pers.Commit();
             }
         }
     }
 }
Пример #5
0
        public void GetTypedResourcesTest()
        {
            Uri     uriResource = new Uri("http://example.org/Peter");
            Contact contact     = Model.CreateResource <Contact>(uriResource);

            contact.Fullname = "Peter";
            contact.Commit();

            uriResource = new Uri("http://example.org/Hans");
            Contact contact2 = Model.CreateResource <Contact>(uriResource);

            contact2.Fullname = "Hans";
            contact2.Commit();

            var res = Model.GetResources <Contact>();

            Assert.AreEqual(2, res.Count());
            Assert.IsTrue(res.Contains(contact));
            Assert.IsTrue(res.Contains(contact2));


            Model.Clear();

            PersonContact personContact = Model.CreateResource <PersonContact>(uriResource);

            personContact.Fullname = "Peter";
            personContact.Commit();

            res = Model.GetResources <Contact>();
            Assert.AreEqual(0, res.Count());

            res = Model.GetResources <Contact>(true);
            Assert.AreEqual(1, res.Count());

            var x = Model.GetResource(uriResource);

            Assert.AreEqual(typeof(PersonContact), x.GetType());
        }
Пример #6
0
        public void TestStringSerializeResource()
        {
            Resource r = new Resource("http://example.com/ex");

            r.AddProperty(Ontologies.dc.title, "MyResource");

            string res      = SparqlSerializer.SerializeResource(r);
            string expected = "<http://example.com/ex> <http://purl.org/dc/elements/1.1/title> 'MyResource'. ";

            Assert.AreEqual(expected, res);


            PersonContact contact = new PersonContact(new Uri("http://example.com/ex"));

            contact.NameGiven = "Peter";
            res      = SparqlSerializer.SerializeResource(contact);
            expected = "<http://example.com/ex> <http://www.semanticdesktop.org/ontologies/2007/03/22/nco#nameGiven> 'Peter'; <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.semanticdesktop.org/ontologies/2007/03/22/nco#PersonContact>. ";
            Assert.AreEqual(expected, res);

            contact.Language = "DE";
            res = SparqlSerializer.SerializeResource(contact);
            Assert.AreEqual(expected, res);
        }