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()); }
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 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 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(); }