public void DoubleClickGraphFolder() { ExplorerPresenter explorerPresenter = UITestUtilities.OpenBasicFileInGui(); GtkUtilities.WaitForGtkEvents(); IModel paddock = Apsim.Find(explorerPresenter.ApsimXFile, typeof(Zone)); explorerPresenter.SelectNode(paddock); explorerPresenter.ContextMenu.AddModel(explorerPresenter, EventArgs.Empty); GtkUtilities.WaitForGtkEvents(); TreeView addModelsTree = (TreeView)ReflectionUtilities.GetValueOfFieldOrProperty("tree", explorerPresenter.CurrentPresenter); // Now, we double click on the fertiliser node. This should add a fertiliser model. // For some reason, sending a double click event doesn't trigger the ActivateRow signal. // Therefore, we need to manually activate the row. //GtkUtilities.ClickOnTreeView(treeView, path, 0, EventType.TwoButtonPress, ModifierType.None, GtkUtilities.ButtonPressType.LeftClick); ActivateNode(addModelsTree, ".Models.Fertiliser"); Assert.AreEqual(2, paddock.Children.Count); Assert.AreEqual(typeof(Models.Fertiliser), paddock.Children[1].GetType()); // While we're at it, let's make sure we can add resource models - e.g. wheat. ActivateNode(addModelsTree, ".Models.PMF.Wheat"); Assert.AreEqual(3, paddock.Children.Count); Assert.AreEqual(typeof(Plant), paddock.Children[2].GetType()); Plant wheat = paddock.Children[2] as Plant; Assert.AreEqual("Wheat", wheat.ResourceName); }
public void TestEditingNullProperty() { ExplorerPresenter explorerPresenter = UITestUtilities.OpenResourceFileInTab(Assembly.GetExecutingAssembly(), "UnitTests.ApsimNG.Resources.SampleFiles.NullSample.apsimx"); GtkUtilities.WaitForGtkEvents(); Simulations sims = explorerPresenter.ApsimXFile; Soil soil = sims.FindInScope <Soil>(); Sample sample = soil.FindChild <Sample>(); explorerPresenter.SelectNode(sample); GtkUtilities.WaitForGtkEvents(); Assert.IsNull(sample.NO3); ProfileView view = explorerPresenter.CurrentRightHandView as ProfileView; GridView grid = view.ProfileGrid as GridView; // Click on the first cell in the second column (the NO3N column) and type 1.1 and then hit enter. GtkUtilities.ClickOnGridCell(grid, 0, 1, Gdk.EventType.ButtonPress, Gdk.ModifierType.None, GtkUtilities.ButtonPressType.LeftClick); GtkUtilities.SendKeyPress(grid.Grid, '1'); GtkUtilities.SendKeyPress(grid.Grid, '.'); GtkUtilities.SendKeyPress(grid.Grid, '1'); GtkUtilities.TypeKey(grid.Grid, Gdk.Key.Return, Gdk.ModifierType.None); // The sample's NO3N property should now be an array containing 1.1. Assert.NotNull(sample.NO3); Assert.AreEqual(new double[1] { 1.1 }, sample.NO3); }
public void OpenTestFileInTab() { // Open a simple .apsimx file in the GUI. explorerPresenter = UITestUtilities.OpenResourceFileInTab(Assembly.GetExecutingAssembly(), "UnitTests.ApsimNG.Resources.SampleFiles.BasicSimulation.apsimx"); // Create a table model. model = new DualTableModel(); model.Name = "Table"; // Create a datatable and assign it to the model. DataTable table = new DataTable(); table.Columns.Add("test_col", typeof(string)); table.Rows.Add("test"); model.Tables = new List <DataTable>() { table, table.Copy() }; // Add the model to the .apsimx file. Structure.Add(model, explorerPresenter.ApsimXFile); explorerPresenter.Refresh(); // Select the table model in the GUI. explorerPresenter.SelectNode(model); GtkUtilities.WaitForGtkEvents(); }
public void AddResourceModelToReplacements() { ExplorerPresenter explorerPresenter = UITestUtilities.OpenBasicFileInGui(); GtkUtilities.WaitForGtkEvents(); // Add a replacements node. Replacements replacements = new Replacements(); Structure.Add(replacements, explorerPresenter.ApsimXFile); explorerPresenter.Refresh(); // Select the replacements node, then activate the 'add model' context menu item. explorerPresenter.SelectNode(replacements); explorerPresenter.ContextMenu.AddModel(explorerPresenter, EventArgs.Empty); GtkUtilities.WaitForGtkEvents(); TreeView addModelsTree = (TreeView)ReflectionUtilities.GetValueOfFieldOrProperty("tree", explorerPresenter.CurrentPresenter); // Now, we double click on the fertiliser node. This should add a fertiliser model. // For some reason, sending a double click event doesn't trigger the ActivateRow signal. // Therefore, we need to manually activate the row. //GtkUtilities.ClickOnTreeView(treeView, path, 0, EventType.TwoButtonPress, ModifierType.None, GtkUtilities.ButtonPressType.LeftClick); ActivateNode(addModelsTree, ".Models.PMF.Wheat"); Assert.AreEqual(1, replacements.Children.Count, "Replacements should now have 1 child after adding wheat, but it doesn't"); Assert.AreEqual(typeof(Models.PMF.Plant), replacements.Children[0].GetType()); // Wheat should have some children (read in from the resource file). IModel wheat = replacements.Children[0]; Assert.NotZero(wheat.Children.Count); // The children should all be visible. foreach (IModel child in wheat.Children) { Assert.False(child.IsHidden); } }
public void OpenTestFileInTab() { explorerPresenter = UITestUtilities.OpenResourceFileInTab(Assembly.GetExecutingAssembly(), "UnitTests.ApsimNG.Resources.SampleFiles.BasicSimulation.apsimx"); Structure.Add(new SampleModel(), explorerPresenter.ApsimXFile); }