Example #1
0
        public void OpenXmlDYNwithSelectionNode()
        {
            // Define package loading reference path
            var dir    = SystemTestBase.GetTestDirectory(ExecutingDirectory);
            var pkgDir = Path.Combine(dir, "pkgs\\Dynamo Samples");
            var pkgMan = this.CurrentDynamoModel.GetPackageManagerExtension();
            var loader = pkgMan.PackageLoader;
            var pkg    = loader.ScanPackageDirectory(pkgDir);

            // Load the sample package
            loader.Load(pkg);
            // Assert expected package was loaded
            Assert.AreEqual(pkg.Name, "Dynamo Samples");

            // Run the graph with correct info serialized, node should deserialize to correct selection
            string path = Path.Combine(TestDirectory, "pkgs", "Dynamo Samples", "extra", "DropDownSample_1Dot3.dyn");

            RunModel(path);

            var node = CurrentDynamoModel.CurrentWorkspace.Nodes.FirstOrDefault();

            // Second selection selected
            Assert.AreEqual(1, node.GetType().GetProperty("SelectedIndex").GetValue(node));
            Assert.AreEqual("Cersei", node.GetType().GetProperty("SelectedString").GetValue(node));
        }
Example #2
0
        public void GetSelectedStringFromItemShouldReturnString()
        {
            // Define package loading reference path
            var dir    = SystemTestBase.GetTestDirectory(ExecutingDirectory);
            var pkgDir = Path.Combine(dir, "pkgs\\Dynamo Samples");
            var pkgMan = this.CurrentDynamoModel.GetPackageManagerExtension();
            var loader = pkgMan.PackageLoader;
            var pkg    = loader.ScanPackageDirectory(pkgDir);

            // Load the sample package
            loader.Load(pkg);
            // Assert expected package was loaded
            Assert.AreEqual(pkg.Name, "Dynamo Samples");

            // Run the graph with correct info serialized, node should deserialize to correct selection
            string path = Path.Combine(TestDirectory, "pkgs", "Dynamo Samples", "extra", "DropDownSample.dyn");

            RunModel(path);

            var node = CurrentDynamoModel.CurrentWorkspace.Nodes.FirstOrDefault();

            // Second selection selected
            Assert.AreEqual(1, node.GetType().GetProperty("SelectedIndex").GetValue(node));
            Assert.AreEqual("Cersei", node.GetType().GetProperty("SelectedString").GetValue(node));

            // Call GetSelectedStringFromItem() on DropDownItem should give back SelectedString
            Assert.AreNotEqual("Cersei", node.GetType().GetMethod("GetSelectedStringFromItem", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(node, new object[] { new DynamoDropDownItem("Tywin", 0) }));
        }
Example #3
0
        public void OpenJsonDYNwithSelectionNodeAndWrongSelectionIndexSerialized()
        {
            // Define package loading reference path
            var dir    = SystemTestBase.GetTestDirectory(ExecutingDirectory);
            var pkgDir = Path.Combine(dir, "pkgs\\Dynamo Samples");
            var pkgMan = this.CurrentDynamoModel.GetPackageManagerExtension();
            var loader = pkgMan.PackageLoader;
            var pkg    = loader.ScanPackageDirectory(pkgDir);

            // Load the sample package
            loader.Load(pkg);
            // Assert expected package was loaded
            Assert.AreEqual(pkg.Name, "Dynamo Samples");

            // Run the graph with incorrect SelectedIndex serialized,
            // this could be across host versions, index changed in newer version of host
            // node should still deserialize to correct selection
            string path = Path.Combine(TestDirectory, "pkgs", "Dynamo Samples", "extra", "DropDownSampleWithWrongIndex.dyn");

            RunModel(path);

            var node = CurrentDynamoModel.CurrentWorkspace.Nodes.FirstOrDefault();

            // Second selection selected
            Assert.AreEqual(1, node.GetType().GetProperty("SelectedIndex").GetValue(node));
            Assert.AreEqual("Cersei", node.GetType().GetProperty("SelectedString").GetValue(node));
        }
Example #4
0
        public void PopulateItemsShouldNotChangeSelectedIndex()
        {
            // Define package loading reference path
            var dir    = SystemTestBase.GetTestDirectory(ExecutingDirectory);
            var pkgDir = Path.Combine(dir, "pkgs\\Dynamo Samples");
            var pkgMan = this.CurrentDynamoModel.GetPackageManagerExtension();
            var loader = pkgMan.PackageLoader;
            var pkg    = loader.ScanPackageDirectory(pkgDir);

            // Load the sample package
            loader.Load(pkg);
            // Assert expected package was loaded
            Assert.AreEqual(pkg.Name, "Dynamo Samples");

            // Run the graph with correct info serialized, node should deserialize to correct selection
            string path = Path.Combine(TestDirectory, "pkgs", "Dynamo Samples", "extra", "DropDownSample.dyn");

            RunModel(path);

            var node = CurrentDynamoModel.CurrentWorkspace.Nodes.FirstOrDefault();

            // Second selection selected
            Assert.AreEqual(1, node.GetType().GetProperty("SelectedIndex").GetValue(node));
            Assert.AreEqual("Cersei", node.GetType().GetProperty("SelectedString").GetValue(node));

            // Call PopulateItems() on node should not change index
            // TODO fix the selection state code in PopulateItemsCore() in DynamoSamples repo
            // and update the test to be the correct behavior
            node.GetType().GetMethod("PopulateItems").Invoke(node, new object[] { });
            Assert.AreNotEqual(1, node.GetType().GetProperty("SelectedIndex").GetValue(node));
            Assert.AreNotEqual("Cersei", node.GetType().GetProperty("SelectedString").GetValue(node));
        }
Example #5
0
        protected void RunCommandsFromFile(string commandFileName,
                                           bool autoRun = false, CommandCallback commandCallback = null)
        {
            string commandFilePath = SystemTestBase.GetTestDirectory(ExecutingDirectory);

            commandFilePath = Path.Combine(commandFilePath, @"core\recorded\");
            commandFilePath = Path.Combine(commandFilePath, commandFileName);

            if (this.ViewModel != null)
            {
                var message = "Multiple DynamoViewModel instances detected!";
                throw new InvalidOperationException(message);
            }

            var model = DynamoModel.Start(
                new DynamoModel.DefaultStartConfiguration()
            {
                StartInTestMode = true
            });

            ViewModel = DynamoViewModel.Start(
                new DynamoViewModel.StartConfiguration()
            {
                DynamoModel     = model,
                CommandFilePath = commandFilePath
            });

            ViewModel.HomeSpace.RunSettings.RunType = autoRun ?
                                                      RunType.Automatic :
                                                      RunType.Manual;

            RegisterCommandCallback(commandCallback);

            // Create the view.
            var dynamoView = new DynamoView(this.ViewModel);

            dynamoView.ShowDialog();

            Assert.IsNotNull(ViewModel);
            Assert.IsNotNull(ViewModel.Model);
            Assert.IsNotNull(ViewModel.Model.CurrentWorkspace);
            workspace          = ViewModel.Model.CurrentWorkspace;
            workspaceViewModel = ViewModel.CurrentSpaceViewModel;
        }