Ejemplo n.º 1
0
        public void AddRemoveLocalizedStringTest()
        {
            IModel m = GetModel();

            m.Clear();

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

            t1.AddProperty(TestOntology.uniqueStringTest, "Hallo Welt", "de");
            t1.Commit();

            var t1ref  = m.GetResource <MappingTestClass>(t1Uri);
            var values = t1ref.ListValues(TestOntology.uniqueStringTest);

            Assert.IsTrue(values.OfType <Tuple <string, string> >().Any(t => t.Item1 == "Hallo Welt" && t.Item2 == "de"));

            t1.RemoveProperty(TestOntology.uniqueStringTest, "Hallo Welt", "de");
            t1.Commit();

            t1ref  = m.GetResource <MappingTestClass>(t1Uri);
            values = t1ref.ListValues(TestOntology.uniqueStringTest);

            Assert.AreEqual(0, values.Count());
        }
Ejemplo n.º 2
0
        public void ListValuesTest()
        {
            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();

            t1.stringTest.Add("Hi");
            t1.stringTest.Add("Blub");
            t1.Commit();

            var x = t1.ListValues(TestOntology.stringTest);

            MappingTestClass actual = m.GetResource <MappingTestClass>(t1.Uri);
            var x2 = actual.ListValues(TestOntology.stringTest);

            var res1 = x.ToList();
            var res2 = x2.ToList();

            Assert.AreEqual(res1.Count, res2.Count);
            Assert.IsTrue(res2.Contains(res1[0]));
            Assert.IsTrue(res2.Contains(res1[1]));
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        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());
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        public void RollbackTest()
        {
            IModel           m     = GetModel();
            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();

            t1.uniqueStringTest = "HelloWorld!";

            t1.Rollback();


            Assert.AreEqual(strValue, t1.uniqueStringTest);

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

            newRef.stringTest.Add("Hi");
            newRef.stringTest.Add("Blub");
            newRef.Commit();

            t1.Rollback();


            Assert.AreEqual(2, t1.stringTest.Count);
            Assert.IsTrue(t1.stringTest.Contains("Hi"));
            Assert.IsTrue(t1.stringTest.Contains("Blub"));


            Uri t2Uri           = new Uri("semio:test:testInstance2");
            MappingTestClass2 p = m.CreateResource <MappingTestClass2>(t2Uri);

            p.uniqueStringTest = "blub";
            p.Commit();

            newRef = m.GetResource <MappingTestClass>(t1Uri);
            newRef.resourceTest.Add(p);
            newRef.Commit();

            t1.Rollback();


            Assert.IsTrue(t1.resourceTest.Count == 1);
            Assert.IsTrue(t1.resourceTest.Contains(p));
        }
Ejemplo n.º 8
0
        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();
        }
Ejemplo n.º 9
0
        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());
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        public void LazyLoadResourceTest()
        {
            MappingDiscovery.RegisterCallingAssembly();
            IModel model = GetModel();

            model.Clear();

            Uri testRes1         = new Uri("semio:test:testInstance");
            Uri testRes2         = new Uri("semio:test:testInstance2");
            MappingTestClass  t1 = model.CreateResource <MappingTestClass>(testRes1);
            MappingTestClass2 t2 = model.CreateResource <MappingTestClass2>(new Uri("semio:test:testInstance2"));

            t1.uniqueResourceTest = t2;
            // TODO: Debug messsage, because t2 was not commited
            t1.Commit();

            MappingTestClass p1 = model.GetResource <MappingTestClass>(testRes1);
            //Assert.AreEqual(null, p1.uniqueResourceTest);

            var v = p1.ListValues(TestOntology.uniqueResourceTest);

            Assert.AreEqual(t2.Uri.OriginalString, (v.First() as IResource).Uri.OriginalString);

            model.DeleteResource(t1);

            model.DeleteResource(t2);

            t1 = model.CreateResource <MappingTestClass>(testRes1);

            t2 = model.CreateResource <MappingTestClass2>(new Uri("semio:test:testInstance2"));
            t2.Commit();

            t1.uniqueResourceTest = t2;
            t1.Commit();

            IResource tr1 = model.GetResource(testRes1, t1.GetType()) as Resource;

            Assert.AreEqual(typeof(MappingTestClass), tr1.GetType());
            MappingTestClass2 p2 = model.GetResource <MappingTestClass2>(testRes2);

            Assert.AreEqual(t2, p1.uniqueResourceTest);



            model.Clear();
        }
Ejemplo n.º 12
0
        public void RollbackTest()
        {
            IModel m = GetModel();

            Uri u0 = new Uri("urn:id:0");
            MappingTestClass r0 = m.CreateResource <MappingTestClass>(u0);

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

            r0.uniqueStringTest = strValue;
            r0.Commit();
            r0.uniqueStringTest = "HelloWorld!";
            r0.Rollback();

            Assert.AreEqual(strValue, r0.uniqueStringTest);

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

            r0ref.stringTest.Add("Hi");
            r0ref.stringTest.Add("Blub");
            r0ref.Commit();

            r0.Rollback();

            Assert.AreEqual(2, r0.stringTest.Count);
            Assert.IsTrue(r0.stringTest.Contains("Hi"));
            Assert.IsTrue(r0.stringTest.Contains("Blub"));

            Uri u1 = new Uri("urn:id:1");
            MappingTestClass2 r1 = m.CreateResource <MappingTestClass2>(u1);

            r1.uniqueStringTest = "blub";
            r1.Commit();

            r0ref = m.GetResource <MappingTestClass>(u0);
            r0ref.resourceTest.Add(r1);
            r0ref.Commit();

            r0.Rollback();

            Assert.IsTrue(r0.resourceTest.Count == 1);
            Assert.IsTrue(r0.resourceTest.Contains(r1));
        }
Ejemplo n.º 13
0
        public void LazyLoadResourceTest()
        {
            IModel      model      = Model;
            IModelGroup modelGroup = Store.CreateModelGroup(Model.Uri, Model2.Uri);

            model.Clear();

            Uri testRes1         = new Uri("semio:test:testInstance");
            Uri testRes2         = new Uri("semio:test:testInstance2");
            MappingTestClass  t1 = model.CreateResource <MappingTestClass>(testRes1);
            MappingTestClass2 t2 = model.CreateResource <MappingTestClass2>(new Uri("semio:test:testInstance2"));

            t1.uniqueResourceTest = t2;
            // TODO: Debug messsage, because t2 was not commited
            t1.Commit();

            MappingTestClass p1 = modelGroup.GetResource <MappingTestClass>(testRes1);
            //Assert.AreEqual(null, p1.uniqueResourceTest);

            var v = p1.ListValues(TestOntology.uniqueResourceTest);

            Assert.AreEqual(t2.Uri.OriginalString, (v.First() as IResource).Uri.OriginalString);

            model.DeleteResource(t1);

            model.DeleteResource(t2);

            t1 = model.CreateResource <MappingTestClass>(testRes1);

            t2 = model.CreateResource <MappingTestClass2>(new Uri("semio:test:testInstance2"));
            t2.Commit();

            t1.uniqueResourceTest = t2;
            t1.Commit();

            var tt1 = modelGroup.GetResource <MappingTestClass>(testRes1);

            Assert.AreEqual(t2, tt1.uniqueResourceTest);

            IResource tr1 = modelGroup.GetResource(testRes1);

            Assert.AreEqual(typeof(MappingTestClass), tr1.GetType());
        }
Ejemplo n.º 14
0
        public void AddRemoveLocalizedStringTest()
        {
            IModel m = GetModel();

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

            t1.AddProperty(TestOntology.uniqueStringTest, "Hallo Welt", "de");
            t1.Commit();

            var tt = m.GetResource <MappingTestClass>(t1Uri);
        }
Ejemplo n.º 15
0
        public void TimeZoneTest()
        {
            IModel m = GetModel();

            m.Clear();

            Uri      t1Uri = new Uri("semio:test:testInstance1");
            DateTime t     = new DateTime();

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

            MappingTestClass t1 = m.CreateResource <MappingTestClass>(t1Uri);

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

            MappingTestClass t_actual = m.GetResource <MappingTestClass>(t1Uri);
        }
Ejemplo n.º 16
0
        public void MappedResourceValueTest()
        {
            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 = m.CreateResource <MappingTestClass2>(testClass2Uri);

            t2.uniqueStringTest = "TestString";
            t2.Commit();

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

            Assert.AreEqual("TestString", t_actual.uniqueResourceTest.uniqueStringTest);
        }
Ejemplo n.º 17
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();
        }
Ejemplo n.º 18
0
        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();
        }