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 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); } }