コード例 #1
0
ファイル: TestsTests.cs プロジェクト: mpandreucci/ApsimX
        public void ManagerScriptTest()
        {
            string  managerCode = "using System; using Models.Core; namespace Models { public class Script : Model, ITest { public void Run() { @action } } }";
            Manager testManager = new Manager();

            testManager.Name = "TestScript";

            Folder testFolder = new Folder();

            testFolder.Name = "TestFolder";

            testFolder.Children = new List <Model>()
            {
                testManager
            };
            testManager.Parent = testFolder;

            MockStorage storage = new MockStorage();

            Simulations simToRun = Simulations.Create(new List <IModel>()
            {
                testFolder, storage
            });
            IJobManager jobManager = Runner.ForSimulations(simToRun, simToRun, true);

            // Test should fail if it throws.
            testManager.Code = managerCode.Replace("@action", "throw new Exception(\"Test has failed.\");");
            TestWithAllJobRunners(jobManager, EnsureSimulationRanRed);

            // Test should pass if it doesn't throw.
            testManager.Code = managerCode.Replace("@action", "return;");
            TestWithAllJobRunners(jobManager, EnsureSimulationRanGreen);
        }
コード例 #2
0
        public void EnsureReportWritesToStorage()
        {
            MockLocator locator = new MockLocator();
            MockStorage storage = new MockStorage();

            Report report = new Report();

            report.VariableNames = new string[] { "A", "B", "C" };
            report.EventNames    = new string[0];

            Utilities.InjectLink(report, "simulation", new Simulation()
            {
                Name = "Sim1"
            });
            Utilities.InjectLink(report, "clock", new MockClock());
            Utilities.InjectLink(report, "storage", storage);
            Utilities.InjectLink(report, "locator", locator);
            Utilities.InjectLink(report, "events", new MockEvents());

            Utilities.CallEvent(report, "Commencing");

            locator.Values["A"] = new VariableObject(10);
            locator.Values["B"] = new VariableObject(20);
            locator.Values["C"] = new VariableObject(30);
            report.DoOutput(null, null);

            locator.Values["A"] = new VariableObject(40);
            locator.Values["B"] = new VariableObject(50);
            locator.Values["C"] = new VariableObject(60);
            report.DoOutput(null, null);
            Utilities.CallEvent(report, "Completed");


            Assert.AreEqual(storage.columnNames.ToArray(), new string[] { "Zone", "A", "B", "C" });
            Assert.AreEqual(storage.rows.Count, 2);
            Assert.AreEqual(storage.rows[0].values, new object[] { null, 10, 20, 30 });
            Assert.AreEqual(storage.rows[1].values, new object[] { null, 40, 50, 60 });
        }