public void AddRemoveDateTimeTest()
        {
            IModel m = GetModel();

            m.Clear();
            Uri t1Uri           = new Uri("semio:test:testInstance1");
            MappingTestClass t1 = m.CreateResource <MappingTestClass>(t1Uri);


            // Add value using the mapping interface
            DateTime Value = new DateTime(2012, 8, 15, 12, 3, 55, DateTimeKind.Local);

            t1.uniqueDateTimeTest = Value;
            t1.Commit();

            MappingTestClass t_actual = m.GetResource <MappingTestClass>(t1Uri);

            // Test if value was stored
            Assert.AreEqual(Value.ToUniversalTime(), t_actual.uniqueDateTimeTest.ToUniversalTime());


            // Test if property is present
            var l = t_actual.ListProperties();

            Assert.True(l.Contains(TestOntology.uniqueDatetimeTest));
            Assert.AreEqual(2, l.Count());

            // Test if ListValues works
            Assert.AreEqual(typeof(DateTime), t_actual.ListValues(TestOntology.uniqueDatetimeTest).First().GetType());
            DateTime time = (DateTime)t_actual.ListValues(TestOntology.uniqueDatetimeTest).First();

            Assert.AreEqual(Value.ToUniversalTime(), time.ToUniversalTime());

            // Remove with RemoveProperty
            t1.RemoveProperty(TestOntology.uniqueDatetimeTest, Value);
            t1.Commit();

            t_actual = m.GetResource <MappingTestClass>(t1Uri);

            // Test if ListProperties works
            l = t_actual.ListProperties();
            Assert.False(l.Contains(TestOntology.uniqueBoolTest));

            // Test if ListValues works
            Assert.AreEqual(0, t_actual.ListValues(TestOntology.uniqueDatetimeTest).Count());


            DateTime t = new DateTime();

            Assert.IsTrue(DateTime.TryParse("2013-01-21T16:27:23.000Z", out t));

            t1.uniqueDateTimeTest = t;
            t1.Commit();

            t_actual = m.GetResource <MappingTestClass>(t1Uri);
            Assert.AreEqual(t1.uniqueDateTimeTest.ToUniversalTime(), t_actual.uniqueDateTimeTest.ToUniversalTime());

            m.Clear();
        }
        public void AddRemoveStringTest()
        {
            IModel m = GetModel();

            m.Clear();
            Uri t1Uri           = new Uri("semio:test:testInstance1");
            MappingTestClass t1 = m.CreateResource <MappingTestClass>(t1Uri);


            // Add value using the mapping interface
            string strValue = "Hallo Welt!";

            t1.uniqueStringTest = strValue;
            t1.Commit();

            MappingTestClass t_actual = m.GetResource <MappingTestClass>(t1Uri);

            // Test if value was stored
            Assert.AreEqual(strValue, t_actual.uniqueStringTest);


            // Test if property is present
            var l = t_actual.ListProperties();

            Assert.True(l.Contains(TestOntology.uniqueStringTest));
            Assert.AreEqual(2, l.Count());

            var x = t_actual.HasProperty(TestOntology.uniqueStringTest);

            Assert.IsTrue(x);

            x = t_actual.HasProperty(TestOntology.uniqueStringTest, strValue);
            Assert.IsTrue(x);

            // Test if ListValues works
            Assert.AreEqual(typeof(string), t_actual.ListValues(TestOntology.uniqueStringTest).First().GetType());
            Assert.AreEqual(strValue, t1.ListValues(TestOntology.uniqueStringTest).First());

            // Remove with RemoveProperty
            t1.RemoveProperty(TestOntology.uniqueStringTest, strValue);
            t1.Commit();
            t_actual = m.GetResource <MappingTestClass>(t1Uri);

            // Test if ListProperties works
            l = t_actual.ListProperties();
            Assert.False(l.Contains(TestOntology.uniqueStringTest));

            x = t_actual.HasProperty(TestOntology.uniqueStringTest);
            Assert.IsFalse(x);

            x = t_actual.HasProperty(TestOntology.uniqueStringTest, strValue);
            Assert.IsFalse(x);

            // Test if ListValues works
            Assert.AreEqual(0, t_actual.ListValues(TestOntology.uniqueStringTest).Count());
            m.Clear();
        }
        public void AddRemoveResourceTest()
        {
            IModel m = GetModel();

            m.Clear();
            Uri t1Uri           = new Uri("semio:test:testInstance1");
            MappingTestClass t1 = m.CreateResource <MappingTestClass>(t1Uri);

            Uri testClass2Uri    = new Uri("semio:test:testInstance2");
            MappingTestClass2 t2 = new MappingTestClass2(testClass2Uri);

            t1.uniqueResourceTest = t2;
            t1.Commit();
            MappingTestClass t_actual = m.GetResource <MappingTestClass>(t1Uri);


            Assert.AreEqual(t2, t_actual.uniqueResourceTest);

            var l = t_actual.ListProperties().ToList();

            Assert.Contains(TestOntology.uniqueResourceTest, l);
            Assert.AreEqual(2, l.Count());

            var x = t_actual.HasProperty(TestOntology.uniqueResourceTest);

            Assert.IsTrue(x);

            x = t_actual.HasProperty(TestOntology.uniqueResourceTest, t2);
            Assert.IsTrue(x);

            t_actual = m.GetResource <MappingTestClass>(t1Uri);
            var values = t_actual.ListValues().ToList();

            Assert.Contains(new Tuple <Property, object>(TestOntology.uniqueResourceTest, t2), values);


            Assert.IsTrue(typeof(Resource).IsAssignableFrom(t_actual.ListValues(TestOntology.uniqueResourceTest).First().GetType()));
            //Assert.AreEqual(t2, t_actual.ListValues(TestOntology.uniqeResourceTest).First());

            t1.RemoveProperty(TestOntology.uniqueResourceTest, t2);
            t1.Commit();
            t_actual = m.GetResource <MappingTestClass>(t1Uri);


            l = t_actual.ListProperties().ToList();
            Assert.False(l.Contains(TestOntology.uniqueResourceTest));

            x = t_actual.HasProperty(TestOntology.uniqueResourceTest);
            Assert.IsFalse(x);

            x = t_actual.HasProperty(TestOntology.uniqueResourceTest, t2);
            Assert.IsFalse(x);

            // Test if ListValues works
            Assert.AreEqual(0, t_actual.ListValues(TestOntology.uniqueResourceTest).Count());
        }
        public void AddRemoveBoolListTest()
        {
            IModel m = GetModel();

            m.Clear();
            Uri t1Uri           = new Uri("semio:test:testInstance1");
            MappingTestClass t1 = m.CreateResource <MappingTestClass>(t1Uri);


            // Add value using the mapping interface
            bool value = true;

            t1.boolTest.Add(value);

            t1.Commit();
            MappingTestClass t_actual = m.GetResource <MappingTestClass>(t1Uri);

            // Test if value was stored
            Assert.AreEqual(1, t_actual.boolTest.Count());
            Assert.AreEqual(value, t_actual.boolTest[0]);


            // Test if property is present
            var l = t_actual.ListProperties();

            Assert.True(l.Contains(TestOntology.boolTest));
            Assert.AreEqual(2, l.Count());

            // Test if ListValues works
            Assert.AreEqual(typeof(bool), t_actual.ListValues(TestOntology.boolTest).First().GetType());
            Assert.AreEqual(value, t_actual.ListValues(TestOntology.boolTest).First());

            // Remove value from mapped list
            t1.boolTest.Remove(value);
            t1.Commit();
            t_actual = m.GetResource <MappingTestClass>(t1Uri);

            // Test if removed
            Assert.AreEqual(0, t_actual.boolTest.Count());

            // Test if ListProperties works
            l = t_actual.ListProperties();
            Assert.False(l.Contains(TestOntology.boolTest));

            // Test if ListValues works
            Assert.AreEqual(0, t_actual.ListValues(TestOntology.boolTest).Count());

            m.Clear();
        }
        public void AddRemoveIntegerTest()
        {
            IModel m = GetModel();

            m.Clear();

            Uri t1Uri           = new Uri("semio:test:testInstance1");
            MappingTestClass t1 = m.CreateResource <MappingTestClass>(t1Uri);

            // Add value using the mapping interface
            int value = 1;

            t1.uniqueIntTest = value;

            t1.Commit();

            MappingTestClass t_actual = m.GetResource <MappingTestClass>(t1Uri);

            // Test if value was stored
            Assert.AreEqual(value, t_actual.uniqueIntTest);


            // Test if property is present
            IEnumerable <Property> l = t_actual.ListProperties();

            Assert.True(l.Contains(TestOntology.uniqueIntTest));
            Assert.AreEqual(2, l.Count());

            // Test if ListValues works
            Assert.AreEqual(typeof(int), t_actual.ListValues(TestOntology.uniqueIntTest).First().GetType());
            Assert.AreEqual(value, t_actual.ListValues(TestOntology.uniqueIntTest).First());

            // Remove with RemoveProperty
            t1.RemoveProperty(TestOntology.uniqueIntTest, value);
            t1.Commit();

            t_actual = m.GetResource <MappingTestClass>(t1Uri);

            // Test if ListProperties works
            l = t_actual.ListProperties();
            Assert.False(l.Contains(TestOntology.uniqueIntTest));

            // Test if ListValues works
            Assert.AreEqual(0, t_actual.ListValues(TestOntology.uniqueIntTest).Count());

            m.Clear();
        }
        public void AddRemoveResourceListTest()
        {
            IModel m = GetModel();

            m.Clear();
            Uri t1Uri           = new Uri("semio:test:testInstance1");
            MappingTestClass t1 = m.CreateResource <MappingTestClass>(t1Uri);


            // Add value using the mapping interface
            MappingTestClass2 t2 = new MappingTestClass2(new Uri("semio:test:testInstance2"));

            t1.resourceTest.Add(t2);
            t1.Commit();
            MappingTestClass t_actual = m.GetResource <MappingTestClass>(t1Uri);

            Assert.AreEqual(1, t_actual.resourceTest.Count);
            Assert.AreEqual(t2, t_actual.resourceTest[0]);

            var l = t_actual.ListProperties();

            Assert.AreEqual(2, l.Count());
            Assert.IsTrue(l.Contains(TestOntology.resourceTest));

            var x = t_actual.HasProperty(TestOntology.resourceTest);

            Assert.IsTrue(x);

            x = t_actual.HasProperty(TestOntology.resourceTest, t2);
            Assert.IsTrue(x);

            var v = t_actual.ListValues(TestOntology.resourceTest);

            Assert.AreEqual(2, l.Count());
            Assert.IsTrue(v.Contains(t2));

            Assert.AreEqual(t2.GetType(), v.First().GetType());

            t1.resourceTest.Remove(t2);
            t1.Commit();
            t_actual = m.GetResource <MappingTestClass>(t1Uri);

            x = t_actual.HasProperty(TestOntology.resourceTest);
            Assert.IsFalse(x);

            x = t_actual.HasProperty(TestOntology.resourceTest, t2);
            Assert.IsFalse(x);


            Assert.AreEqual(0, t_actual.resourceTest.Count);
        }
        public void AddRemoveDateTimeListTest()
        {
            IModel m = GetModel();

            m.Clear();
            Uri t1Uri           = new Uri("semio:test:testInstance1");
            MappingTestClass t1 = m.CreateResource <MappingTestClass>(t1Uri);


            // Add value using the mapping interface
            DateTime value = new DateTime(2012, 8, 15, 12, 3, 55, DateTimeKind.Local);

            t1.dateTimeTest.Add(value);
            t1.Commit();
            MappingTestClass t_actual = m.GetResource <MappingTestClass>(t1Uri);

            // Test if value was stored
            Assert.AreEqual(1, t1.dateTimeTest.Count());
            Assert.AreEqual(value, t1.dateTimeTest[0]);


            // Test if property is present
            var l = t1.ListProperties();

            Assert.True(l.Contains(TestOntology.datetimeTest));
            Assert.AreEqual(2, l.Count());

            // Test if ListValues works
            Assert.AreEqual(typeof(DateTime), t_actual.ListValues(TestOntology.datetimeTest).First().GetType());
            DateTime time = (DateTime)t_actual.ListValues(TestOntology.datetimeTest).First();

            Assert.AreEqual(value.ToUniversalTime(), time.ToUniversalTime());

            // Remove value from mapped list
            t1.dateTimeTest.Remove(value);
            t1.Commit();

            t_actual = m.GetResource <MappingTestClass>(t1Uri);

            // Test if removed
            Assert.AreEqual(0, t_actual.dateTimeTest.Count());

            // Test if ListProperties works
            l = t_actual.ListProperties();
            Assert.False(l.Contains(TestOntology.datetimeTest));

            // Test if ListValues works
            Assert.AreEqual(0, t_actual.ListValues(TestOntology.datetimeTest).Count());
        }
        public void RemoveTypeTest()
        {
            Assert.Inconclusive("This test poses an interesting problem. If we remove the type of a mapped resource, how should we handle that.");
            IModel m = GetModel();

            m.Clear();

            Uri t1Uri           = new Uri("semio:test:testInstance1");
            MappingTestClass t1 = m.CreateResource <MappingTestClass>(t1Uri);

            t1.RemoveProperty(rdf.type, TestOntology.TestClass);

            Assert.False(t1.ListProperties().Contains(rdf.type));


            m.Clear();
        }
        public void AddRemoveIntegerListTest()
        {
            IModel m = GetModel();

            m.Clear();
            Uri t1Uri           = new Uri("semio:test:testInstance1");
            MappingTestClass t1 = m.CreateResource <MappingTestClass>(t1Uri);
            // Add value using the mapping interface
            int value = 2;

            t1.intTest.Add(value);

            t1.Commit();

            MappingTestClass t_actual = m.GetResource <MappingTestClass>(t1Uri);

            // Test if value was stored
            Assert.AreEqual(1, t_actual.intTest.Count());
            Assert.AreEqual(value, t_actual.intTest[0]);

            // Test if property is present
            IEnumerable <Property> l = t_actual.ListProperties();

            Assert.True(l.Contains(TestOntology.intTest));
            Assert.AreEqual(2, l.Count());

            // Test if ListValues works
            Assert.AreEqual(typeof(int), t_actual.ListValues(TestOntology.intTest).First().GetType());
            Assert.AreEqual(value, t_actual.ListValues(TestOntology.intTest).First());

            // Add another value
            int value2 = -18583;

            t1.intTest.Add(value2);
            t1.Commit();
            t_actual = m.GetResource <MappingTestClass>(t1Uri);


            // Test if value was stored
            Assert.AreEqual(2, t_actual.intTest.Count());
            Assert.IsTrue(t_actual.intTest.Contains(value));
            Assert.IsTrue(t_actual.intTest.Contains(value2));

            // Test if property is present
            l = t_actual.ListProperties();
            Assert.True(l.Contains(TestOntology.intTest));
            Assert.AreEqual(2, l.Count());

            // Test if ListValues works
            var res = t_actual.ListValues(TestOntology.intTest).ToList();

            Assert.AreEqual(typeof(int), res[0].GetType());
            Assert.AreEqual(typeof(int), res[1].GetType());
            Assert.IsTrue(res.Contains(value));
            Assert.IsTrue(res.Contains(value2));

            // Remove value from mapped list
            t1.intTest.Remove(value2);
            t1.Commit();
            t_actual = m.GetResource <MappingTestClass>(t1Uri);

            // Test if removed
            Assert.AreEqual(1, t_actual.intTest.Count());

            // Test if ListProperties works
            l = t_actual.ListProperties();
            Assert.True(l.Contains(TestOntology.intTest));

            // Test if first added property is still present
            Assert.AreEqual(typeof(int), t_actual.ListValues(TestOntology.intTest).First().GetType());
            Assert.AreEqual(value, t_actual.ListValues(TestOntology.intTest).First());

            t1.intTest.Remove(value);
            t1.Commit();
            t_actual = m.GetResource <MappingTestClass>(t1Uri);

            l = t_actual.ListProperties();
            Assert.False(l.Contains(TestOntology.intTest));

            // Test if ListValues works
            Assert.AreEqual(0, t_actual.ListValues(TestOntology.intTest).Count());

            m.Clear();
        }
Beispiel #10
0
        public void AddRemoveStringListTest()
        {
            IModel m = GetModel();

            m.Clear();

            string value  = "This is a test!";
            string value2 = "This is a test too!";

            // Add value using the mapping interface
            Uri u0 = new Uri("urn:id:0");
            MappingTestClass r0 = m.CreateResource <MappingTestClass>(u0);

            r0.stringTest.Add(value);
            r0.Commit();

            // Test if value was stored.
            MappingTestClass r1 = m.GetResource <MappingTestClass>(u0);

            Assert.AreEqual(1, r1.stringTest.Count());
            Assert.AreEqual(value, r1.stringTest[0]);

            // Test if HasProperty works.
            Assert.IsTrue(r1.HasProperty(TestOntology.stringTest));
            Assert.IsTrue(r1.HasProperty(TestOntology.stringTest, value));

            // Test if ListValues works.
            Assert.AreEqual(typeof(string), r1.ListValues(TestOntology.stringTest).First().GetType());
            Assert.AreEqual(value, r1.ListValues(TestOntology.stringTest).First());

            // Test if property is present.
            var properties = r1.ListProperties();

            Assert.True(properties.Contains(TestOntology.stringTest));
            Assert.AreEqual(2, properties.Count());

            // Remove value from mapped list.
            r0.stringTest.Remove(value);
            r0.Commit();

            r1 = m.GetResource <MappingTestClass>(u0);

            // Test if removed
            Assert.AreEqual(0, r1.stringTest.Count());

            // Test if ListProperties works
            properties = r1.ListProperties();
            CollectionAssert.DoesNotContain(properties, TestOntology.stringTest);

            // Test if HasProperty works.
            Assert.IsFalse(r1.HasProperty(TestOntology.stringTest));
            Assert.IsFalse(r1.HasProperty(TestOntology.stringTest, value));

            // Test if ListValues works
            Assert.AreEqual(0, r1.ListValues(TestOntology.stringTest).Count());

            // Add value using the mapping interface
            u0 = new Uri("urn:id:0");
            r0 = m.CreateResource <MappingTestClass>(u0);
            r0.stringTest.Add(value);
            r0.stringTest.Add(value2);
            r0.Commit();

            // Test if value was stored.
            r1 = m.GetResource <MappingTestClass>(u0);
            Assert.AreEqual(2, r1.stringTest.Count());
            Assert.Contains(value, r1.stringTest);

            // Test if HasProperty works.
            Assert.IsTrue(r1.HasProperty(TestOntology.stringTest));
            Assert.IsTrue(r1.HasProperty(TestOntology.stringTest, value));

            // Test if ListValues works.
            Assert.AreEqual(typeof(string), r1.ListValues(TestOntology.stringTest).First().GetType());
            Assert.AreEqual(value, r1.ListValues(TestOntology.stringTest).First());

            // Test if property is present.
            properties = r1.ListProperties();
            Assert.True(properties.Contains(TestOntology.stringTest));
            Assert.AreEqual(2, properties.Count());

            // Remove value from mapped list.
            r0.stringTest.Remove(value);
            r0.Commit();

            r1 = m.GetResource <MappingTestClass>(u0);

            // Test if removed
            Assert.AreEqual(0, r1.stringTest.Count());

            // Test if ListProperties works
            properties = r1.ListProperties();
            CollectionAssert.DoesNotContain(properties, TestOntology.stringTest);

            // Test if HasProperty works.
            Assert.IsFalse(r1.HasProperty(TestOntology.stringTest));
            Assert.IsFalse(r1.HasProperty(TestOntology.stringTest, value));

            // Test if ListValues works
            Assert.AreEqual(0, r1.ListValues(TestOntology.stringTest).Count());

            m.Clear();
        }