public void BothDashboardsSerialize() { var project = new MyProject(); project.CreateWorld(typeof(MyTestingWorld)); project.Network = new MyNetwork(); var node = project.CreateNode <Node>(); node.Name = "Foo"; project.Network.AddChild(node); var dashboard = new Dashboard(); foreach (PropertySetup propertySetup in GetPropertyExamples(project)) { dashboard.Add(propertySetup.Target, propertySetup.PropertyName); } var groupDashboard = new GroupDashboard(); groupDashboard.Properties.Add(new DashboardPropertyGroup("Group 1")); groupDashboard.Properties[0].Add(dashboard.Properties[0]); YAXSerializer serializer = MyProject.GetSerializer <Dashboard>(); YAXSerializer groupSerializer = MyProject.GetSerializer <GroupDashboard>(); string serializedDashboard = serializer.Serialize(dashboard); string serializedGroupDashboard = groupSerializer.Serialize(groupDashboard); Dashboard deserializedDashboard = (Dashboard)serializer.Deserialize(serializedDashboard); deserializedDashboard.RestoreFromIds(project); project.Dashboard = deserializedDashboard; GroupDashboard deserializedGroupDashboard = (GroupDashboard)groupSerializer.Deserialize(serializedGroupDashboard); deserializedGroupDashboard.RestoreFromIds(project); project.GroupedDashboard = deserializedGroupDashboard; var compareLogic = new CompareLogic(new ComparisonConfig { MaxDifferences = 20, MembersToIgnore = new List <string> { "Proxy", "GenericProxy" } }); ComparisonResult result = compareLogic.Compare(dashboard, deserializedDashboard); m_output.WriteLine(result.DifferencesString); Assert.True(result.AreEqual); result = compareLogic.Compare(groupDashboard, deserializedGroupDashboard); m_output.WriteLine(result.DifferencesString); Assert.True(result.AreEqual); }
public MyProject CreateProject(Type worldType, string projectName = null) { Project = new MyProject { Network = new MyNetwork() }; Project.CreateWorld(worldType); return(Project); }
public void SimulationStateChangedOnNodesTest() { var simulation = TypeMap.GetInstance <MySimulation>(); var handler = new MySimulationHandler(simulation); MyProject project = new MyProject { Network = new MyNetwork() }; project.CreateWorld(typeof(MyTestingWorld)); var node = project.CreateNode <TestingNode>(); node.Event = new AutoResetEvent(false); project.Network.AddChild(node); var connection = new MyConnection(project.Network.GroupInputNodes[0], project.Network.Children[0]); connection.Connect(); project.Network.PrepareConnections(); handler.Project = project; handler.UpdateMemoryModel(); handler.StartSimulation(); node.Event.WaitOne(); Assert.Equal(MySimulationHandler.SimulationState.STOPPED, node.PreviousState); Assert.Equal(MySimulationHandler.SimulationState.RUNNING, node.CurrentState); handler.PauseSimulation(); node.Event.WaitOne(); Assert.Equal(MySimulationHandler.SimulationState.RUNNING, node.PreviousState); Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.CurrentState); handler.StartSimulation(stepCount: 1u); node.Event.WaitOne(); // Here the sim goes from paused to RUNNING_STEP. Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.PreviousState); Assert.Equal(MySimulationHandler.SimulationState.RUNNING_STEP, node.CurrentState); node.Event.WaitOne(); // Here it goes to PAUSED. Assert.Equal(MySimulationHandler.SimulationState.RUNNING_STEP, node.PreviousState); Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.CurrentState); handler.StopSimulation(); node.Event.WaitOne(); Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.PreviousState); Assert.Equal(MySimulationHandler.SimulationState.STOPPED, node.CurrentState); handler.Finish(); }
public void SimulationStateChangedOnNodesTest() { var simulation = new MyLocalSimulation(); var handler = new MySimulationHandler(simulation); MyProject project = new MyProject { Network = new MyNetwork() }; project.CreateWorld(typeof(MyTestingWorld)); var node = project.CreateNode<TestingNode>(); node.Event = new AutoResetEvent(false); project.Network.AddChild(node); var connection = new MyConnection(project.Network.GroupInputNodes[0], project.Network.Children[0]); connection.Connect(); project.Network.PrepareConnections(); handler.Project = project; handler.UpdateMemoryModel(); handler.StartSimulation(oneStepOnly: false); node.Event.WaitOne(); Assert.Equal(MySimulationHandler.SimulationState.STOPPED, node.PreviousState); Assert.Equal(MySimulationHandler.SimulationState.RUNNING, node.CurrentState); handler.PauseSimulation(); node.Event.WaitOne(); Assert.Equal(MySimulationHandler.SimulationState.RUNNING, node.PreviousState); Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.CurrentState); handler.StartSimulation(oneStepOnly: true); node.Event.WaitOne(); // Here the sim goes from paused to RUNNING_STEP. Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.PreviousState); Assert.Equal(MySimulationHandler.SimulationState.RUNNING_STEP, node.CurrentState); node.Event.WaitOne(); // Here it goes to PAUSED. Assert.Equal(MySimulationHandler.SimulationState.RUNNING_STEP, node.PreviousState); Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.CurrentState); handler.StopSimulation(); node.Event.WaitOne(); Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.PreviousState); Assert.Equal(MySimulationHandler.SimulationState.STOPPED, node.CurrentState); handler.Finish(); }
public void SerializesAndDeserializesCorrectly() { // I.e. deserialized(serialized(PROJECT)) should equal PROJECT string tmpPath = Path.GetTempPath(); MyConfiguration.SetupModuleSearchPath(); MyConfiguration.LoadModules(); MyConfiguration.KnownNodes.Add(typeof(TestNode), new MyNodeConfig()); var project = new MyProject(); project.Network = project.CreateNode <MyNetwork>(); project.Network.Name = "Network"; project.CreateWorld(typeof(MyTestingWorld)); project.Name = "test"; var node = project.CreateNode <TestNode>(); project.Network.AddChild(node); project.Restore(); string serialized = project.Serialize(tmpPath); MyProject deserializedProject = MyProject.Deserialize(serialized, tmpPath); // MaxDifferences = 20 - A magic number. It shows more than one difference in the log. // There should eventually be zero differences, so this number can be arbitrary. Adjust as needed. // Observers are ignored - there are none, and the (de)serialization mechanism works with them in a special way. var compareLogic = new CompareLogic(new ComparisonConfig { MaxDifferences = 20, MembersToIgnore = new List <string> { "Observers" } }); ComparisonResult result = compareLogic.Compare(project, deserializedProject); m_output.WriteLine(result.DifferencesString); Assert.True(result.AreEqual); }
public MyProject CreateProject(Type worldType, string projectName = null) { Project = new MyProject { Network = new MyNetwork(), Name = projectName }; Project.CreateWorld(worldType); return Project; }