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 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 AddRemoveStringListTest() { 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 = "(╯°□°)╯︵ ┻━┻"; t1.stringTest.Add(strValue); t1.Commit(); MappingTestClass t_actual = m.GetResource <MappingTestClass>(t1Uri); // Test if value was stored Assert.AreEqual(1, t_actual.stringTest.Count()); Assert.AreEqual(strValue, t_actual.stringTest[0]); // Test if property is present var l = t_actual.ListProperties(); Assert.True(l.Contains(TestOntology.stringTest)); Assert.AreEqual(2, l.Count()); var x = t_actual.HasProperty(TestOntology.stringTest); Assert.IsTrue(x); x = t_actual.HasProperty(TestOntology.stringTest, strValue); Assert.IsTrue(x); // Test if ListValues works Assert.AreEqual(typeof(string), t_actual.ListValues(TestOntology.stringTest).First().GetType()); Assert.AreEqual(strValue, t_actual.ListValues(TestOntology.stringTest).First()); // Remove value from mapped list t1.stringTest.Remove(strValue); 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.stringTest)); x = t_actual.HasProperty(TestOntology.stringTest); Assert.IsFalse(x); x = t_actual.HasProperty(TestOntology.stringTest, strValue); Assert.IsFalse(x); // Test if ListValues works Assert.AreEqual(0, t_actual.ListValues(TestOntology.stringTest).Count()); m.Clear(); }
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(); }