Exemplo n.º 1
0
        public void EnsureOnlyPostSimulationToolsAreRun()
        {
            foreach (var typeOfRun in runTypes)
            {
                // Open an in-memory database.
                database = new SQLite();
                database.OpenDatabase(":memory:", readOnly: false);

                var simulation = new Simulation()
                {
                    Name     = "Sim",
                    FileName = Path.GetTempFileName(),
                    Children = new List <Model>()
                    {
                        new Clock()
                        {
                            StartDate = new DateTime(1980, 1, 3),
                            EndDate   = new DateTime(1980, 1, 4)
                        },
                        new MockSummary(),
                        new DataStore(database),
                        new MockPostSimulationTool(doThrow: true)
                        {
                            Name = "PostSim"
                        }
                    }
                };

                Runner runner = new Runner(simulation, runType: typeOfRun, runSimulations: false);

                // Ensure number of simulations is correct before any are run.
                Assert.AreEqual(runner.TotalNumberOfSimulations, 0);
                Assert.AreEqual(runner.NumberOfSimulationsCompleted, 0);

                AllJobsCompletedArgs argsOfAllCompletedJobs = null;
                runner.AllSimulationsCompleted += (sender, e) => { argsOfAllCompletedJobs = e; };

                // Run simulations.
                runner.Run();

                // Simulation shouldn't have run. Check the summary messages to make
                // sure there is NOT a 'Simulation completed' message.
                Assert.AreEqual(MockSummary.messages.Count, 0);

                // Ensure number of simulations is correct after all have been run.
                Assert.AreEqual(runner.TotalNumberOfSimulations, 0);
                Assert.AreEqual(runner.NumberOfSimulationsCompleted, 0);
                Assert.AreEqual(runner.PercentComplete(), 0);

                // Make sure the expected exception was sent through the all completed jobs event.
                Assert.AreEqual(argsOfAllCompletedJobs.AllExceptionsThrown.Count, 1);
                Assert.IsTrue(argsOfAllCompletedJobs.AllExceptionsThrown[0].ToString().Contains("Intentional exception"));

                database.CloseDatabase();
            }
        }
Exemplo n.º 2
0
        public void EnsurePostSimulationToolsAreRun()
        {
            foreach (var typeOfRun in runTypes)
            {
                // Open an in-memory database.
                database = new SQLite();
                database.OpenDatabase(":memory:", readOnly: false);

                var simulation = new Simulation()
                {
                    Name     = "Sim",
                    FileName = Path.GetTempFileName(),
                    Children = new List <IModel>()
                    {
                        new Clock()
                        {
                            StartDate = new DateTime(1980, 1, 3),
                            EndDate   = new DateTime(1980, 1, 4)
                        },
                        new MockSummary(),
                        new DataStore(database),
                        new MockPostSimulationTool(doThrow: true)
                        {
                            Name = "PostSim"
                        }
                    }
                };

                Runner runner = new Runner(simulation, runType: typeOfRun);

                AllJobsCompletedArgs argsOfAllCompletedJobs = null;
                runner.AllSimulationsCompleted += (sender, e) => { argsOfAllCompletedJobs = e; };

                // Run simulations.
                runner.Run();

                // Make sure the expected exception was sent through the all completed jobs event.
                Assert.AreEqual(argsOfAllCompletedJobs.AllExceptionsThrown.Count, 1);
                Assert.IsTrue(argsOfAllCompletedJobs.AllExceptionsThrown[0].ToString().Contains("Intentional exception"));

                database.CloseDatabase();
            }
        }