public void AddRemoveUriTest() { IModel model = GetModel(); if (!model.IsEmpty) { model.Clear(); } Uri uri1 = new Uri("urn:1"); Uri uri2 = new Uri("file:///a.bc"); Uri uri3 = new Uri("file:///x.yz"); // 1. Create a new instance of the test class and commit it to the model. CilgMappingTestClass test1 = model.CreateResource <CilgMappingTestClass>(uri1); test1.uriProperty = new Resource(uri2); test1.Commit(); // 2. Retrieve a new copy of the instance and validate the mapped URI property. test1 = model.GetResource <CilgMappingTestClass>(uri1); Assert.NotNull(test1.uriProperty); Assert.AreEqual(test1.uriProperty.Uri, uri2); // 3. Change the property and commit the resource. test1.uriProperty = new Resource(uri3); test1.Commit(); // 4. Retrieve a new copy of the instance and validate the changed URI property. test1 = model.GetResource <CilgMappingTestClass>(uri1); Assert.NotNull(test1.uriProperty); Assert.AreEqual(test1.uriProperty.Uri, uri3); }
public void AddRemoveIntegerTest() { IModel m = GetModel(); m.Clear(); Uri t1Uri = new Uri("semio:test:testInstance1"); CilgMappingTestClass t1 = m.CreateResource <CilgMappingTestClass>(t1Uri); // Add value using the mapping interface int value = 1; t1.uniqueIntTest = value; t1.Commit(); CilgMappingTestClass t_actual = m.GetResource <CilgMappingTestClass>(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 <CilgMappingTestClass>(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 AddRemoveIntegerListTest() { IModel m = GetModel(); m.Clear(); Uri t1Uri = new Uri("semio:test:testInstance1"); CilgMappingTestClass t1 = m.CreateResource <CilgMappingTestClass>(t1Uri); // Add value using the mapping interface int value = 2; t1.intTest.Add(value); t1.Commit(); CilgMappingTestClass t_actual = m.GetResource <CilgMappingTestClass>(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 <CilgMappingTestClass>(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 <CilgMappingTestClass>(t1Uri); // Test if removed Assert.AreEqual(1, t_actual.intTest.Count()); // Test if ListProperties works l = t_actual.ListProperties().ToList(); 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 <CilgMappingTestClass>(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(); }