예제 #1
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();
        }