public void MappingTypeTest() { IModel m = GetModel(); m.Clear(); Uri t1Uri = new Uri("semio:test:testInstance1"); MappingTestClass2 t1 = m.CreateResource <MappingTestClass2>(t1Uri); t1.uniqueStringTest = "testing 1"; t1.Commit(); Uri t2Uri = new Uri("semio:test:testInstance2"); MappingTestClass3 t2 = m.CreateResource <MappingTestClass3>(t2Uri); t2.uniqueStringTest = "testing 2"; t2.Commit(); Uri t3Uri = new Uri("semio:test:testInstance3"); MappingTestClass4 t3 = m.CreateResource <MappingTestClass4>(t3Uri); t3.uniqueStringTest = "testing 3"; t3.Commit(); Resource r1 = m.GetResource <Resource>(t1Uri); Assert.AreEqual(t1, r1); Resource r2 = m.GetResource <Resource>(t2Uri); Assert.AreEqual(t2, r2); Resource r3 = m.GetResource <Resource>(t3Uri); Assert.AreEqual(t3, r3); }
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)); }
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(); }
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)); }
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()); }
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); }