public void TestMovingModelSystems() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ProjectController; string error = null; controller.DeleteProject("TestProject", ref error); Project project; Assert.IsTrue((project = controller.LoadOrCreate("TestProject", ref error)) != null); using (var session = controller.EditProject(project)) { // create and add our two model systems into the project var testModelSystem = CreateTestModelSystem(runtime); Assert.IsTrue(session.AddModelSystem(testModelSystem, ref error)); Assert.AreEqual(1, project.ModelSystemStructure.Count); Assert.IsTrue(session.AddModelSystem(testModelSystem, ref error)); Assert.AreEqual(2, project.ModelSystemStructure.Count); var oldModelSystems = project.ModelSystemStructure.ToList(); // try invalid moves Assert.IsFalse(session.MoveModelSystem(-1, -1, ref error)); Assert.IsFalse(session.MoveModelSystem(-1, 0, ref error)); Assert.IsFalse(session.MoveModelSystem(0, -1, ref error)); // actually move Assert.IsTrue(session.MoveModelSystem(0, 1, ref error), error); Assert.AreEqual(oldModelSystems[0], project.ModelSystemStructure[1], "The 0th model system is not the same as the move 1th model system!"); Assert.AreEqual(oldModelSystems[1], project.ModelSystemStructure[0], "The 1th model system is not the same as the move 0th model system!"); } }
public void TestRemovingModelSystem() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ProjectController; string error = null; controller.DeleteProject("TestProject", ref error); Project project; Assert.IsTrue((project = controller.LoadOrCreate("TestProject", ref error)) != null); using (var session = controller.EditProject(project)) { var testModelSystem = CreateTestModelSystem(runtime); Assert.IsTrue(session.AddModelSystem(testModelSystem, ref error)); Assert.AreEqual(1, project.ModelSystemStructure.Count); Assert.IsTrue(session.RemoveModelSystem(0, ref error)); Assert.IsTrue(session.AddModelSystem(testModelSystem, ref error)); using (session.EditModelSystem(0)) { Assert.IsFalse(session.RemoveModelSystem(0, ref error)); } // make sure it has a valid index ( under and over ) Assert.IsFalse(session.RemoveModelSystem(-1, ref error)); Assert.IsFalse(session.RemoveModelSystem(1, ref error)); // actually remove it Assert.IsTrue(session.RemoveModelSystem(0, ref error), error); // make sure that you can not remove a model system if it doesn't exist Assert.IsFalse(session.RemoveModelSystem(0, ref error)); } }
public void TestGettingSpecificGenericType() { var runtime = TestXTMFCore.CreateRuntime(); var projectController = runtime.ProjectController; string error = null; projectController.DeleteProject("TestProject", ref error); Project project; Assert.IsTrue((project = projectController.LoadOrCreate("TestProject", ref error)) != null); using (var session = projectController.EditProject(project)) { var testModelSystem = CreateSpecificTestModelSystem(runtime); Assert.IsTrue(session.AddModelSystem(testModelSystem, ref error)); using (var modelSystemSession = session.EditModelSystem(0)) { Assert.IsNotNull(modelSystemSession); var root = modelSystemSession.ModelSystemModel.Root; var collection = root.Children.FirstOrDefault((child) => child.Name == "My Child"); Assert.IsNotNull(collection); var availableModules = modelSystemSession.GetValidModules(collection); if (!availableModules.Any(m => m.Name == "TestGenericModule`2")) { Assert.Fail(); } } } }
public void TestDisablingRequiredField() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { string error = null; // build a small model system var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); // disable a module Assert.IsTrue(root.Children[0].AddCollectionMember(typeof(TestRequiredSubmodule), ref error, "SimpleChild"), error); var requiredParent = root.Children[0].Children[0]; requiredParent.Children[0].Type = typeof(TestModule); var simpleChild = requiredParent.Children[0]; Assert.AreEqual(false, simpleChild.IsDisabled, "By default simple child should not be disabled!"); Assert.IsFalse(simpleChild.SetDisabled(true, ref error), "You should not be able to disable a required submodule!"); } }
public void TestUndoRedo() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); Assert.AreEqual(typeof(TestModelSystemTemplate), root.Type, "The root was not updated to the proper type!"); string error = null; Assert.IsTrue(session.Undo(ref error), "The undo failed!"); Assert.AreEqual(null, root.Type, "The root was not updated to the proper type after undo!"); Assert.IsTrue(session.Redo(ref error), "The undo failed!"); Assert.AreEqual(typeof(TestModelSystemTemplate), root.Type, "The root was not updated to the proper type after redo!"); } }
public void TestChangingAModulesName() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { string error = null; var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); var oldName = root.Name; const string newName = "New Name"; Assert.IsTrue(root.SetName(newName, ref error), "Failed to set the module's name!"); Assert.AreEqual(root.Name, newName, "The new name was not assigned!"); if (!session.Undo(ref error)) { Assert.Fail("We were unable to undo! " + error); } Assert.AreEqual(root.Name, oldName, "The old name was not restored!"); if (!session.Redo(ref error)) { Assert.Fail("We were unable to redo! " + error); } Assert.AreEqual(root.Name, newName, "The new name was not restored after redo!"); } }
public void TestAddingACollectionMember() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); Assert.AreEqual(typeof(TestModelSystemTemplate), root.Type, "The root was not updated to the proper type!"); Assert.IsNotNull(root.Children, "The test model system template doesn't have any children models!"); var collection = root.Children.FirstOrDefault((child) => child.Name == "Test Collection"); Assert.IsNotNull(collection, "We were unable to find a child member that contained the test collection!"); string error = null; Assert.IsTrue(collection.AddCollectionMember(typeof(TestModule), ref error), "We were unable to properly add a new collection member."); Assert.IsFalse(collection.AddCollectionMember(typeof(int), ref error), "We were able to use an integer as a collection member!"); } }
public void TestNewLinkedParameter() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var modelSystem = session.ModelSystemModel; var linkedParameters = modelSystem.LinkedParameters; Assert.AreEqual(0, linkedParameters.Count, "The model system already had a linked parameter before we added any!"); string error = null; Assert.IsTrue(linkedParameters.NewLinkedParameter("Test", ref error), "We failed to create our first linked parameter!"); Assert.AreEqual(1, linkedParameters.Count, "After adding a linked parameter it still reports that there isn't one linked parameter."); ObservableCollection <LinkedParameterModel> linkedParameterList = linkedParameters.GetLinkedParameters(); Assert.IsTrue(session.Undo(ref error)); Assert.AreEqual(0, linkedParameters.Count, "After undoing the add new linked parameter there was still a linked parameter left!"); Assert.IsTrue(session.Redo(ref error)); Assert.AreEqual(1, linkedParameters.Count, "After re-adding a linked parameter it still reports that there isn't one linked parameter."); } }
public void TestEditParameterToDefault() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); var parameters = root.Parameters.GetParameters(); Assert.IsNotNull(parameters, "There are no parameters for our test model system template!"); var inputDirectory = GetParameter(parameters, "Input Directory"); Assert.IsNotNull(inputDirectory, "There was no parameter called input directory."); string error = null; var previousValue = inputDirectory.Value; var newValue = "NewValue"; Assert.IsTrue(inputDirectory.SetValue(newValue, ref error), "The assignment of a value to a string somehow failed!"); Assert.AreEqual(newValue, inputDirectory.Value, "The valid value was not stored in the parameter!"); Assert.IsTrue(inputDirectory.SetToDefault(ref error), "Set to default failed!"); Assert.AreEqual(previousValue, inputDirectory.Value, "We did not revert to the previous value!"); } }
public void TestSettingModelSystemRootInAProject() { string error = null; var runtime = TestXTMFCore.CreateRuntime(); var projectController = runtime.ProjectController; var projectName = "TestProject"; var msName = "TestModelSystem"; var alternateName = "TestModelSystemName2"; Project project; Assert.IsTrue(projectController.DeleteProject(projectName, ref error), error); Assert.IsTrue((project = projectController.LoadOrCreate(projectName, ref error)) != null, error); using (var projectSession = projectController.EditProject(project)) { var testModelSystem = CreateTestModelSystem(runtime); Assert.IsTrue(projectSession.AddModelSystem(testModelSystem, msName, ref error), error); using (var session = projectSession.EditModelSystem(0)) { var model = session.ModelSystemModel; Assert.AreEqual(msName, model.Name, "The initial name of the model system was not set correctly."); Assert.IsTrue(model.Root.SetName(alternateName, ref error), error); Assert.AreEqual(alternateName, model.Name, "The assigned name of the model system was not updated."); Assert.IsTrue(session.Undo(ref error), error); Assert.AreEqual(msName, model.Name, "The undone name of the model system was not updated."); Assert.IsTrue(session.Redo(ref error), error); Assert.AreEqual(alternateName, model.Name, "The undone name of the model system was not updated."); } } }
public void TestImportModelSystemFromFileIntoProject() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ProjectController; string error = null; controller.DeleteProject("TestProject", ref error); Project project; Assert.IsTrue((project = controller.LoadOrCreate("TestProject", ref error)) != null); using (var session = controller.EditProject(project)) { var testModelSystem = CreateTestModelSystem(runtime); Assert.IsTrue(session.AddModelSystem(testModelSystem, ref error)); var modelSystemDirectory = session.GetConfiguration().ModelSystemDirectory; Assert.IsTrue(!String.IsNullOrWhiteSpace(modelSystemDirectory)); var modelSystemFileName = Path.Combine(modelSystemDirectory, "TestModelSystem.xml"); var fileInfo = new FileInfo(modelSystemFileName); Assert.IsTrue(fileInfo.Exists); Assert.AreEqual(1, session.Project.ModelSystemStructure.Count); Assert.IsTrue(session.ImportModelSystemFromFile(modelSystemFileName, "TestModelSystem2", ref error), error); Assert.AreEqual(2, session.Project.ModelSystemStructure.Count); Assert.AreEqual("TestModelSystem2", session.Project.ModelSystemStructure[1].Name); } }
public void TestDeleteLinkedParameter() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var modelSystem = session.ModelSystemModel; var linkedParameters = modelSystem.LinkedParameters; Assert.AreEqual(0, linkedParameters.Count, "The model system already had a linked parameter before we added any!"); string error = null; Assert.IsTrue(linkedParameters.NewLinkedParameter("Test", ref error), "We failed to create our first linked parameter!"); Assert.AreEqual(1, linkedParameters.Count, "After adding a linked parameter it still reports that there isn't one linked parameter."); var linkedParameterList = linkedParameters.GetLinkedParameters(); var zeroElement = linkedParameterList[0]; Assert.IsTrue(linkedParameters.RemoveLinkedParameter(zeroElement, ref error), "We were unable to delete the linked parameter!"); Assert.IsFalse(linkedParameters.RemoveLinkedParameter(zeroElement, ref error), "We were able to delete the linked parameter for a second time!"); Assert.AreEqual(0, linkedParameters.Count, "A linked parameter remained after deleting the only one!"); Assert.IsTrue(session.Undo(ref error)); Assert.AreEqual(1, linkedParameters.Count, "After undoing the linked parameter was not added back!"); Assert.IsTrue(session.Redo(ref error)); Assert.AreEqual(0, linkedParameters.Count, "After redoing the linked parameter remained!"); } }
public void TestSettingParameterInLinkedParameter() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var modelSystem = session.ModelSystemModel; var linkedParameters = modelSystem.LinkedParameters; Assert.AreEqual(0, linkedParameters.Count, "The model system already had a linked parameter before we added any!"); string error = null; Assert.IsTrue(linkedParameters.NewLinkedParameter("Test", ref error), "We failed to create our first linked parameter!"); Assert.AreEqual(1, linkedParameters.Count, "After adding a linked parameter it still reports that there isn't one linked parameter."); var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); var parameters = root.Parameters.GetParameters(); Assert.IsNotNull(parameters, "There are no parameters for our test model system template!"); var inputDirectory = GetParameter(parameters, "Input Directory"); var secondaryString = GetParameter(parameters, "SecondaryString"); var linkedParameterList = linkedParameters.GetLinkedParameters(); Assert.IsTrue(linkedParameterList[0].AddParameter(inputDirectory, ref error), error); Assert.IsTrue(linkedParameterList[0].AddParameter(secondaryString, ref error), error); string oldValue = linkedParameterList[0].GetValue(); string newValue = "NewValue"; Assert.IsTrue(linkedParameterList[0].SetValue(newValue, ref error)); // assign to both with through the linked parameter Assert.AreEqual(newValue, linkedParameterList[0].GetValue()); Assert.AreEqual(newValue, inputDirectory.Value); Assert.AreEqual(newValue, secondaryString.Value); // assign to both using the secondary string Assert.IsTrue(secondaryString.SetValue(oldValue, ref error)); Assert.AreEqual(oldValue, linkedParameterList[0].GetValue()); Assert.AreEqual(oldValue, inputDirectory.Value); Assert.AreEqual(oldValue, secondaryString.Value); Assert.IsTrue(session.Undo(ref error)); Assert.AreEqual(newValue, linkedParameterList[0].GetValue()); Assert.AreEqual(newValue, inputDirectory.Value); Assert.AreEqual(newValue, secondaryString.Value); Assert.IsTrue(session.Redo(ref error)); Assert.AreEqual(oldValue, linkedParameterList[0].GetValue()); Assert.AreEqual(oldValue, inputDirectory.Value); Assert.AreEqual(oldValue, secondaryString.Value); } }
public void TestRun() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ProjectController; string error = null; controller.DeleteProject("TestProject", ref error); Project project; Assert.IsTrue((project = controller.LoadOrCreate("TestProject", ref error)) != null); ((Configuration)runtime.Configuration).RunInSeperateProcess = false; using (var session = controller.EditProject(project)) { var testModelSystem = CreateTestModelSystem(runtime); Assert.IsTrue(session.AddModelSystem(testModelSystem, ref error)); using (var modelSystemSession = session.EditModelSystem(0)) { Assert.IsNotNull(modelSystemSession); var root = modelSystemSession.ModelSystemModel.Root; var collection = root.Children.FirstOrDefault((child) => child.Name == "Test Collection"); Assert.IsNotNull(collection); XTMFRun run; Assert.IsNotNull(run = modelSystemSession.Run("TestRun", ref error)); modelSystemSession.ExecuteRun(run, true); bool finished = false; List <ErrorWithPath> errors = null; Action <List <ErrorWithPath> > catchErrors = (errorPath) => { errors = errorPath; finished = true; }; run.ValidationError += catchErrors; run.RuntimeValidationError += catchErrors; run.RunCompleted += () => { finished = true; }; // Runs now allow changes during the execution // Assert.IsFalse(collection.AddCollectionMember(typeof(TestModule), ref error)); for (int i = 0; i < 100 & !finished; i++) { Thread.Sleep(i); Thread.MemoryBarrier(); } if (!finished) { Assert.Fail("The model system did not complete in time."); } if (errors != null) { Assert.Fail(errors[0].Message); } // now that it is done we should be able to edit it again Assert.IsTrue(collection.AddCollectionMember(typeof(TestModule), ref error), error); } } }
public void TestImportModelSystem() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var importName = "TestImportModelSystem"; string error = null; controller.Delete(importName); Assert.IsNull(controller.Load(importName)); Assert.IsTrue(controller.ImportModelSystem("TestImportModelSystem.xml", false, ref error), error); Assert.IsNotNull(controller.Load(importName)); }
public void TestCreatingEditSession() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); var session = controller.EditModelSystem(ms); try { var secondSession = controller.EditModelSystem(ms); try { using (session) { Assert.IsTrue(session.EditingModelSystem, "The session doesn't believe that it is editing a model system!"); Assert.IsFalse(session.EditingProject, "The session believes that is it editing a project!"); Assert.IsTrue(session == secondSession, "The two given sessions for the same model system are not the same!"); } session = null; var thirdSession = controller.EditModelSystem(ms); using (thirdSession) { Assert.IsTrue(secondSession == thirdSession, "The second session and the third session should have been the same!"); secondSession.Dispose(); } secondSession = null; using (var fourthSession = controller.EditModelSystem(ms)) { Assert.IsFalse(thirdSession == fourthSession, "The third session and the fourth session should have been different!"); } } finally { if (secondSession != null) { secondSession.Dispose(); } } } finally { if (session != null) { session.Dispose(); } } }
public void TestRemovingModuleToLinkedParameter() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var modelSystem = session.ModelSystemModel; var linkedParameters = modelSystem.LinkedParameters; Assert.AreEqual(0, linkedParameters.Count, "The model system already had a linked parameter before we added any!"); string error = null; Assert.IsTrue(linkedParameters.NewLinkedParameter("Test", ref error), "We failed to create our first linked parameter!"); Assert.AreEqual(1, linkedParameters.Count, "After adding a linked parameter it still reports that there isn't one linked parameter."); var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); var parameters = root.Parameters.GetParameters(); Assert.IsNotNull(parameters, "There are no parameters for our test model system template!"); var inputDirectory = GetParameter(parameters, "Input Directory"); var linkedParameterList = linkedParameters.GetLinkedParameters(); Assert.IsTrue(linkedParameterList[0].AddParameter(inputDirectory, ref error), error); var moduleParametersLinked = linkedParameterList[0].GetParameters(); Assert.AreEqual(1, moduleParametersLinked.Count, "The number of module parameters that are linked should just be one!"); Assert.IsTrue(linkedParameterList[0].RemoveParameter(moduleParametersLinked[0], ref error)); Assert.IsFalse(linkedParameterList[0].RemoveParameter(moduleParametersLinked[0], ref error), "We got a true for removing a parameter that was already removed"); moduleParametersLinked = linkedParameterList[0].GetParameters(); Assert.AreEqual(0, moduleParametersLinked.Count, "No module parameters should be left."); Assert.IsTrue(session.Undo(ref error)); moduleParametersLinked = linkedParameterList[0].GetParameters(); Assert.AreEqual(1, moduleParametersLinked.Count, "No module parameter should be returned after undo."); Assert.IsTrue(session.Redo(ref error)); moduleParametersLinked = linkedParameterList[0].GetParameters(); Assert.AreEqual(0, moduleParametersLinked.Count, "No module parameters should be left after redo."); } }
public void TestExportingModelSystemToString() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ProjectController; string error = null; controller.DeleteProject("TestProject", ref error); Project project; Assert.IsTrue((project = controller.LoadOrCreate("TestProject", ref error)) != null); using (var session = controller.EditProject(project)) { var testModelSystem = CreateTestModelSystem(runtime); Assert.IsTrue(session.AddModelSystem(testModelSystem, ref error)); Assert.IsTrue(session.ExportModelSystemAsString(0, out string modelSystem, ref error), error); } }
public void TestAddingModelSystem() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ProjectController; string error = null; controller.DeleteProject("TestProject", ref error); Project project; Assert.IsTrue((project = controller.LoadOrCreate("TestProject", ref error)) != null); using (var session = controller.EditProject(project)) { var testModelSystem = CreateTestModelSystem(runtime); Assert.IsTrue(session.AddModelSystem(testModelSystem, ref error)); Assert.AreEqual(1, project.ModelSystemStructure.Count); } }
public void TestNoDeleteDuringSession() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); Assert.IsTrue(controller.Delete(ms), "We were unable to delete a model system that should have existed!"); ms = controller.LoadOrCreate(msName); using (var session = controller.EditModelSystem(ms)) { Assert.IsFalse(controller.Delete(ms), "Even though the model system had an editing session it was deleted!"); } Assert.IsTrue(controller.Delete(ms), "Even though the model system was no longer being editing it was not deleted!"); }
public void TestEditingModelSystem() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); } }
public void TestRemovingEntireCollection() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); Assert.AreEqual(typeof(TestModelSystemTemplate), root.Type, "The root was not updated to the proper type!"); Assert.IsNotNull(root.Children, "The test model system template doesn't have any children models!"); var collection = root.Children.FirstOrDefault((child) => child.Name == "Test Collection"); Assert.IsNotNull(collection, "We were unable to find a child member that contained the test collection!"); string error = null; Assert.IsTrue(collection.AddCollectionMember(typeof(TestModule), ref error), "We were unable to properly add a new collection member."); Assert.IsTrue(collection.AddCollectionMember(typeof(TestModule), ref error), "We were unable to properly add a new collection member."); Assert.IsFalse(collection.AddCollectionMember(typeof(int), ref error), "We were able to use an integer as a collection member!"); Assert.AreEqual(2, collection.Children.Count, "An incorrect number of children were found."); var oldChildren = collection.Children.ToList(); Assert.IsTrue(collection.RemoveAllCollectionMembers(ref error), "We were unable to remove all collection members!"); Assert.AreEqual(0, collection.Children.Count, "After removing all of the collection members, there were still elements left in the collection."); Assert.IsTrue(session.Undo(ref error), "We failed to undo the remove all!"); Assert.AreEqual(2, collection.Children.Count, "After undoing the remove all there were still issues."); for (int i = 0; i < collection.Children.Count; i++) { Assert.AreEqual(oldChildren[i], collection.Children[i], "A child was not the same as before!"); } } }
public void TestRun() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ProjectController; string error = null; controller.DeleteProject("TestProject", ref error); Project project; Assert.IsTrue((project = controller.LoadOrCreate("TestProject", ref error)) != null); using (var session = controller.EditProject(project)) { var testModelSystem = CreateTestModelSystem(runtime); Assert.IsTrue(session.AddModelSystem(testModelSystem, ref error)); using (var modelSystemSession = session.EditModelSystem(0)) { Assert.IsNotNull(modelSystemSession); var root = modelSystemSession.ModelSystemModel.Root; var collection = root.Children.FirstOrDefault((child) => child.Name == "Test Collection"); Assert.IsNotNull(collection); XTMFRun run; Assert.IsNotNull(run = modelSystemSession.Run("TestRun", ref error)); bool finished = false; run.RunComplete += () => { finished = true; }; Assert.IsFalse(collection.AddCollectionMember(typeof(TestModule), ref error)); run.Start(); for (int i = 0; i < 100 & !finished; i++) { Thread.Sleep(i); Thread.MemoryBarrier(); } if (!finished) { Assert.Fail("The model system did not complete in time."); } // now that it is done we should be able to edit it again Assert.IsTrue(collection.AddCollectionMember(typeof(TestModule), ref error), error); } } }
public void TestImportingModelSystemFromString() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ProjectController; string error = null; controller.DeleteProject("TestProject", ref error); Project project; Assert.IsTrue((project = controller.LoadOrCreate("TestProject", ref error)) != null); using (var session = controller.EditProject(project)) { var testModelSystem = CreateTestModelSystem(runtime); Assert.IsTrue(session.AddModelSystem(testModelSystem, ref error)); Assert.IsTrue(session.ExportModelSystemAsString(0, out string modelSystem, ref error), error); Assert.IsTrue(session.ImportModelSystemFromString(modelSystem, "TestModelSystem2", ref error), error); Assert.AreEqual(2, session.Project.ModelSystemStructure.Count); Assert.AreEqual("TestModelSystem2", session.Project.ModelSystemStructure[1].Name); } }
public void TestNotChangingSubmoduleNameOnTypeChange() { var runtime = TestXTMFCore.CreateRuntime(); var controller = runtime.ModelSystemController; var msName = "TestModelSystem"; controller.Delete(msName); var ms = controller.LoadOrCreate(msName); Assert.AreNotEqual(null, ms, "The model system 'TestModelSystem' was null!"); using (var session = controller.EditModelSystem(ms)) { var model = session.ModelSystemModel; Assert.IsNotNull(model, "No model system model was created!"); ModelSystemStructureModel root = model.Root; Assert.IsNotNull(root, "No root object was made!"); root.Type = typeof(TestModelSystemTemplate); Assert.AreEqual(typeof(TestModelSystemTemplate), root.Type, "The root was not updated to the proper type!"); Assert.IsNotNull(root.Children, "The test model system template doesn't have any children models!"); var collection = root.Children.FirstOrDefault((child) => child.Name == "Test Collection"); Assert.IsNotNull(collection, "We were unable to find a child member that contained the test collection!"); string error = null; Assert.IsTrue(collection.AddCollectionMember(typeof(TestRequiredSubmodule), ref error), "We were unable to properly add a new collection member."); Assert.AreEqual(1, collection.Children.Count, "The collection does not have 1 child!"); var parent = collection.Children[0]; Assert.AreEqual(1, parent.Children.Count, "TestRequiredSubmodule has more than one child!"); var childToRename = parent.Children[0]; var originalName = childToRename.Name; childToRename.Type = typeof(TestRequiredSubmodule); Assert.AreEqual(originalName, childToRename.Name, "The name changed when the type changed on a non collection member!"); } }