Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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);
        }