Ejemplo n.º 1
0
        public void TestRenameUnit()
        {
            string oldUnitName = Unitname;
            string newUnitName = "mockUnitname";

            //store test object in the workspace using old name
            TestObject obj = new TestObject();

            obj.Value = "value";
            TestWorkspace.RegisterType(typeof(TestObject));
            TestWorkspace.Store(oldUnitName, obj);

            //rename unit
            TestWorkspace.RenameUnit(oldUnitName, newUnitName);

            Assert.IsFalse(TestWorkspace.Exists(oldUnitName));
            Assert.IsTrue(TestWorkspace.Exists(newUnitName));

            //check if loading obj using old name returns null
            TestObject oldObj = (TestObject)TestWorkspace.Load(Unitname);

            Assert.IsNull(oldObj);

            //check if we can load object by new name
            TestObject obj2 = (TestObject)TestWorkspace.Load(newUnitName);

            Assert.AreEqual(obj, obj2);
        }
Ejemplo n.º 2
0
        public void TestRenameUnitIfUnitWithNewNameAlreadyExists()
        {
            string oldUnitName = Unitname;
            string newUnitName = "mockUnitname";

            //store test object in the workspace using old name
            TestObject obj = new TestObject();

            obj.Value = "value";
            TestWorkspace.RegisterType(typeof(TestObject));
            TestWorkspace.Store(oldUnitName, obj);

            //store another test object in the workspace using new name
            TestObject anotherObj = new TestObject();

            anotherObj.Value = "different object";
            TestWorkspace.Store(newUnitName, anotherObj);

            //rename the old unitname object to the new unit name - it should override previous unit
            TestWorkspace.RenameUnit(oldUnitName, newUnitName);

            Assert.IsFalse(TestWorkspace.Exists(oldUnitName));
            Assert.IsTrue(TestWorkspace.Exists(newUnitName));

            //check if loading obj using old name returns null
            TestObject oldObj = (TestObject)TestWorkspace.Load(Unitname);

            Assert.IsNull(oldObj);

            //check if we can load object by new name
            TestObject obj2 = (TestObject)TestWorkspace.Load(newUnitName);

            Assert.AreEqual(obj, obj2);
        }
Ejemplo n.º 3
0
        public void LoadTestUnitDoesNotExist()
        {
            //if does not exists in the workspace returns null
            TestObject obj2 = (TestObject)TestWorkspace.Load("FakeName");

            Assert.IsNull(obj2);
        }
Ejemplo n.º 4
0
        public void LoadTestFromXML()
        {
            //set workspace so that it writes units to disc, otherwise files would not be written to disc,
            //so the persistence the units would not be persistent after resetting the workspace
            TestWorkspace.WriteUnitsToDisc = true;

            TestObject obj = new TestObject();

            obj.Value = "value";

            string tmp_unitname = "testobject";

            //string tmpDataPath = Path.Combine(TmpDataDir, TestWorkspace.CurrentGroupId.ToString() + "." + tmp_unitname + ".xml");
            string tmpDataPath = Path.Combine(TmpDataDir, tmp_unitname + ".xml");

            WorkspaceUnit tmpUnit = TestWorkspace.CreateWorkspaceUnit(tmp_unitname);

            tmpUnit.Data = obj;

            // Reset the workspace - this will cause it to realize that
            // the workspace unit exists, even though it's not loaded yet.
            ResetWorkspace();

            TestObject obj2 = (TestObject)TestWorkspace.Load(tmp_unitname);

            Assert.AreEqual(obj, obj2);
        }
Ejemplo n.º 5
0
        public void StoreAndLoadTest()
        {
            TestObject obj = new TestObject();

            obj.Value = "value";
            TestWorkspace.RegisterType(typeof(TestObject));
            TestWorkspace.Store(Unitname, obj);

            TestObject obj2 = (TestObject)TestWorkspace.Load(Unitname);

            Assert.AreEqual(obj, obj2);
        }
Ejemplo n.º 6
0
        public void TestRenameUnitIfUnitWithNewNameAlreadyExistsWriteCacheToDisc()
        {
            AppContext.WorkspaceInstance.WriteUnitsToDisc = true;

            string oldUnitName = Unitname;
            string newUnitName = "mockUnitname";

            string cacheOldNameFile = System.IO.Path.Combine(AppContext.CacheDirectory, oldUnitName + ".cache");
            string cacheNewNameFile = System.IO.Path.Combine(AppContext.CacheDirectory, newUnitName + ".cache");

            //store test object in the workspace using old name
            TestObject obj = new TestObject();

            obj.Value = "value";
            TestWorkspace.RegisterType(typeof(TestObject));
            TestWorkspace.Store(oldUnitName, obj);

            //store another test object in the workspace using new name
            TestObject anotherObj = new TestObject();

            anotherObj.Value = "different object";
            TestWorkspace.Store(newUnitName, anotherObj);

            //check if the cache file exists
            Assert.IsTrue(System.IO.File.Exists(cacheOldNameFile));
            Assert.IsTrue(System.IO.File.Exists(cacheNewNameFile));

            //rename the old unitname object to the new unit name - it should override previous unit
            TestWorkspace.RenameUnit(oldUnitName, newUnitName);

            Assert.IsFalse(TestWorkspace.Exists(oldUnitName));
            Assert.IsTrue(TestWorkspace.Exists(newUnitName));

            //check if old file does not exist anymore, and new exists
            Assert.IsFalse(System.IO.File.Exists(cacheOldNameFile));
            Assert.IsTrue(System.IO.File.Exists(cacheNewNameFile));

            //check if loading obj using old name returns null
            TestObject oldObj = (TestObject)TestWorkspace.Load(Unitname);

            Assert.IsNull(oldObj);

            //check if we can load object by new name
            TestObject obj2 = (TestObject)TestWorkspace.Load(newUnitName);

            Assert.AreEqual(obj, obj2);
        }
Ejemplo n.º 7
0
        public void TestCopyUnit()
        {
            string fromUnitName = Unitname;
            string toUnitName   = "mockUnitname";

            //store test object in the workspace using old name
            TestObject obj = new TestObject();

            obj.Value = "value";
            TestWorkspace.RegisterType(typeof(TestObject));
            TestWorkspace.Store(fromUnitName, obj);

            //copy unit
            TestWorkspace.CopyUnit(fromUnitName, toUnitName);

            //both units should exists
            Assert.IsTrue(TestWorkspace.Exists(fromUnitName));
            Assert.IsTrue(TestWorkspace.Exists(toUnitName));

            //load old object
            TestObject oldObj = (TestObject)TestWorkspace.Load(Unitname);

            Assert.IsNotNull(oldObj);
            Assert.AreEqual(obj, oldObj);

            //check if we can load object by new name
            TestObject obj2 = (TestObject)TestWorkspace.Load(toUnitName);

            Assert.AreEqual(obj, obj2);

            //change one object, store it and test again
            oldObj.Value = "another value";
            TestWorkspace.Store(fromUnitName, oldObj);

            //check if new object has not been affected
            obj2 = (TestObject)TestWorkspace.Load(toUnitName);
            Assert.AreEqual(obj, obj2); //it should still be equal to original object
        }
Ejemplo n.º 8
0
 public void LoadTestEmptyUnitname()
 {
     TestWorkspace.Load("");
 }
Ejemplo n.º 9
0
 public void LoadTestNullUnitname()
 {
     TestWorkspace.Load(null);
 }