public void StoreAndLoadTest() { TestObject obj = new TestObject(); obj.Value = "value"; TestWorkspaceWrapper.Store(Unitname, obj); TestObject obj2 = (TestObject)TestWorkspaceWrapper.Load(Unitname); Assert.AreEqual(obj, obj2); int test = 5; TestWorkspaceWrapper.Store(Unitname2, test); int test2 = (int)TestWorkspaceWrapper.Load(Unitname2); Assert.AreEqual(test, test2); test2++; TestWorkspaceWrapper.Store(Unitname2, test2); int test3 = (int)TestWorkspaceWrapper.Load(Unitname2); Assert.AreEqual(test2, test3); }
public void NestedWorkspaceWrapperSetupAndTearDownTest() { string experimentNamespace = "experiment_namespace"; ExperimentWorkspaceWrapper experimentWorkspaceWrapper = new ExperimentWorkspaceWrapper(AppContext.WorkspaceInstance, experimentNamespace); // let store some objects in the workspace using experiment wrapper // note that experiment wrapper does not have any restriction and can store anything in workspace - it has direct access to Workspace string unitname1 = "testunitname1"; string unitname2 = "testunitname2"; TestObject object1 = new TestObject(); object1.Value = "some value"; Assert.IsFalse(AppContext.WorkspaceInstance.Exists(unitname1)); Assert.IsFalse(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + unitname1)); experimentWorkspaceWrapper.Store(unitname1, object1); Assert.IsFalse(AppContext.WorkspaceInstance.Exists(unitname1)); Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + unitname1)); int testInt = 5; Assert.IsFalse(AppContext.WorkspaceInstance.Exists(unitname2)); Assert.IsFalse(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + unitname2)); experimentWorkspaceWrapper.Store(unitname2, testInt); Assert.IsFalse(AppContext.WorkspaceInstance.Exists(unitname2)); Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + unitname2)); //prepare io spec for first nested workspace IOSpec mockIoSpec1 = new IOSpec(); string nest1unitname1 = "nest1unitname1"; //input nest1unitname1 from unitname1 string nest1unitname2 = "nest1unitname2"; //input nest1unitname2 from unitname2 mockIoSpec1.Input.Add(nest1unitname1, new IOItem(new IOItemDefinition(nest1unitname1, typeof(TestObject).FullName, "mockdescription", TraceLabSDK.IOSpecType.Input), unitname1)); mockIoSpec1.Input.Add(nest1unitname2, new IOItem(new IOItemDefinition(nest1unitname2, typeof(int).FullName, "mockdescription", TraceLabSDK.IOSpecType.Input), unitname2)); string nestedWorkspace1Namespace = "nested_workspace1"; NestedWorkspaceWrapper nestedWorkspace1 = new NestedWorkspaceWrapper(mockIoSpec1, experimentWorkspaceWrapper, nestedWorkspace1Namespace); //prepare io spec for 2nd nested workspace IOSpec mockIoSpec2 = new IOSpec(); string nest2unitname1 = "nest2unitname1"; //input nest2unitname1 from nest1unitname1 string nest2unitname2 = "nest2unitname2"; //input nest2unitname2 from nest1unitname2 //output matters only in teardown string unitname3 = "unitname3"; string unitname3_OutputAS = "nest2unitname3"; string localScopeUnitname = "localScope"; mockIoSpec2.Input.Add(nest2unitname1, new IOItem(new IOItemDefinition(nest2unitname1, typeof(TestObject).FullName, "mockdescription", TraceLabSDK.IOSpecType.Input), nest1unitname1)); mockIoSpec2.Input.Add(nest2unitname2, new IOItem(new IOItemDefinition(nest2unitname2, typeof(int).FullName, "mockdescription", TraceLabSDK.IOSpecType.Input), nest1unitname2)); mockIoSpec2.Output.Add(unitname3, new IOItem(new IOItemDefinition(unitname3, typeof(int).FullName, "mockdescription", TraceLabSDK.IOSpecType.Output), unitname3_OutputAS)); string nestedWorkspace2Namespace = "nested_workspace2"; NestedWorkspaceWrapper nestedWorkspace2 = new NestedWorkspaceWrapper(mockIoSpec2, nestedWorkspace1, nestedWorkspace2Namespace); IOSpec mockIoSpec3 = new IOSpec(); mockIoSpec3.Output.Add(unitname3, new IOItem(new IOItemDefinition(unitname3, typeof(int).FullName, "mockdescription", TraceLabSDK.IOSpecType.Output), unitname3)); mockIoSpec3.Output.Add(localScopeUnitname, new IOItem(new IOItemDefinition(localScopeUnitname, typeof(int).FullName, "mockdescription", TraceLabSDK.IOSpecType.Output), localScopeUnitname)); WorkspaceWrapper workspaceWrapper = new WorkspaceWrapper(mockIoSpec3, nestedWorkspace2); // call in order // 1. setup nested workspace 1 // 2. setup nested workspace 2 // 3. store a object with unitname3 using workspace wrapper, that is output to the higher level scope // 4. store another object, that is NOT output to higher level scope and should be discarded in teardown // 4. tear down workspace 2 // 5. tear down workspace 1 nestedWorkspace1.Setup(); Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + unitname1)); //it actually should stay in experiment scope Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + unitname2)); Assert.IsTrue(experimentWorkspaceWrapper.Exists(unitname1)); Assert.IsTrue(experimentWorkspaceWrapper.Exists(unitname2)); Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nest1unitname1)); Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nest1unitname2)); Assert.IsTrue(nestedWorkspace1.Exists(nest1unitname1)); Assert.IsTrue(nestedWorkspace1.Exists(nest1unitname2)); nestedWorkspace2.Setup(); Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nest1unitname1)); Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nest1unitname2)); Assert.IsTrue(nestedWorkspace1.Exists(nest1unitname1)); Assert.IsTrue(nestedWorkspace1.Exists(nest1unitname2)); Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nestedWorkspace2Namespace + DOT + nest2unitname1)); Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nestedWorkspace2Namespace + DOT + nest2unitname2)); Assert.IsTrue(nestedWorkspace2.Exists(nest2unitname1)); Assert.IsTrue(nestedWorkspace2.Exists(nest2unitname2)); //store unit 3 int unit3 = 10; workspaceWrapper.Store(unitname3, unit3); //it should store it with namespace Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nestedWorkspace2Namespace + DOT + unitname3)); //store localscope variable int localScopeUnit = 25; workspaceWrapper.Store(localScopeUnitname, localScopeUnit); //it should store it with namespace Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nestedWorkspace2Namespace + DOT + localScopeUnitname)); nestedWorkspace2.TearDown(); Assert.IsFalse(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nestedWorkspace2Namespace + DOT + nest2unitname1)); Assert.IsFalse(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nestedWorkspace2Namespace + DOT + nest2unitname2)); Assert.IsFalse(nestedWorkspace2.Exists(nest2unitname1)); Assert.IsFalse(nestedWorkspace2.Exists(nest2unitname2)); Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nest1unitname1)); Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nest1unitname2)); Assert.IsTrue(nestedWorkspace1.Exists(nest1unitname1)); Assert.IsTrue(nestedWorkspace1.Exists(nest1unitname2)); //unitname 3 should be tear down and renamed to unitnameOutpusAs with proper namespace Assert.IsFalse(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nestedWorkspace2Namespace + DOT + unitname3)); Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + unitname3_OutputAS)); //local scope should also be cleared, although it was not output to higher level scope Assert.IsFalse(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nestedWorkspace2Namespace + DOT + localScopeUnitname)); nestedWorkspace1.TearDown(); Assert.IsFalse(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nest1unitname1)); Assert.IsFalse(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + nestedWorkspace1Namespace + DOT + nest1unitname2)); Assert.IsFalse(nestedWorkspace1.Exists(nest1unitname1)); Assert.IsFalse(nestedWorkspace1.Exists(nest1unitname2)); Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + unitname1)); Assert.IsTrue(AppContext.WorkspaceInstance.Exists(experimentNamespace + DOT + unitname2)); Assert.IsTrue(experimentWorkspaceWrapper.Exists(unitname1)); Assert.IsTrue(experimentWorkspaceWrapper.Exists(unitname2)); }
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); }
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 }
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); }
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); }
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); }
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); }