Пример #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 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);
        }
Пример #4
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);
        }
Пример #5
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
        }
Пример #6
0
 private void ResetWorkspace()
 {
     TestWorkspace = AppContext.WorkspaceInstance;
     TestWorkspace.Reset();
     TestWorkspace.RegisterType(typeof(TestObject));
 }