Esempio n. 1
0
        public void LoadInvalidLocationsFromSetting()
        {
            var filePath = Path.Combine(SettingDirectory, "DynamoSettings-invalidPaths.xml");

            // check files required for test exist
            Assert.IsTrue(File.Exists(filePath));

            // load the settings from XML file into DynamoModel
            var settings = PreferenceSettings.Load(filePath);

            // check settings were read correctly
            Assert.NotNull(settings);
            Assert.AreEqual(4, settings.CustomPackageFolders.Count);

            var expectedPackageFolders = new List <string> {
                @"C:\folder_name_with_invalid_:*?|_characters\foobar",
                @"C:\this_folder_doesn't_exist",
                @"X:\this_drive_doesn't_exist",
                @"\\unreachable_machine\share_packages"
            };

            IEnumerable <bool> comparisonResult = settings.CustomPackageFolders.Zip(expectedPackageFolders, string.Equals);

            Assert.IsFalse(comparisonResult.Any(isEqual => !isEqual));
        }
        public override void Setup()
        {
            base.Setup();
            var settings     = new PreferenceSettings();
            var parentFolder = Path.Combine(TestDirectory, "pkgs", "multiple_locations");

            settings.CustomPackageFolders = new List <string>
            {
                Path.Combine(parentFolder, "folder1"),
                @"C:\folder_name_with_invalid_:*?|_characters\foobar",
                @"C:\this_folder_doesn't_exist",
                Path.Combine(parentFolder, "folder2"),
                @"X:\this_drive_doesn't_exist",
                @"\\unreachable_machine\share_packages",
                Path.Combine(parentFolder, "folder3")
            };

            var settingFilePath = Path.Combine(TempFolder, "DynamoSettings.xml");

            settings.Save(settingFilePath);

            var settingsLoadedFromFile = PreferenceSettings.Load(settingFilePath);

            StartDynamo(settingsLoadedFromFile);
        }
Esempio n. 3
0
        public void PreferenceSetting_RenderPrecision()
        {
            // Test that RenderPrecision setting works as expected
            ViewModel.RenderPackageFactoryViewModel.MaxTessellationDivisions = 256;
            Assert.AreEqual(256, ViewModel.Model.PreferenceSettings.RenderPrecision);

            ViewModel.RenderPackageFactoryViewModel.MaxTessellationDivisions = 128;
            Assert.AreEqual(128, ViewModel.Model.PreferenceSettings.RenderPrecision);

            // Test serialization of RenderPrecision
            string tempPath = System.IO.Path.GetTempPath();

            tempPath = Path.Combine(tempPath, "userPreference.xml");

            PreferenceSettings initalSetting = new PreferenceSettings();
            PreferenceSettings resultSetting;

            initalSetting.RenderPrecision = 256;

            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.RenderPrecision, initalSetting.RenderPrecision);

            // Test loading old settings file without render precision attribute
            var filePath = Path.Combine(GetTestDirectory(ExecutingDirectory), @"settings\DynamoSettings-WithoutRenderPrecision.xml");
            PreferenceSettings WithoutRenderPrecision = PreferenceSettings.Load(filePath);

            Assert.AreEqual(WithoutRenderPrecision.RenderPrecision, 128);
        }
Esempio n. 4
0
        private static void MakeStandaloneAndRun(string commandFilePath, out DynamoViewModel viewModel)
        {
            DynamoPathManager.Instance.InitializeCore(
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            DynamoPathManager.PreloadAsmLibraries(DynamoPathManager.Instance);

            var model = DynamoModel.Start(
                new DynamoModel.StartConfiguration()
            {
                Preferences = PreferenceSettings.Load()
            });

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

            var view = new DynamoView(viewModel);

            var app = new Application();

            app.Run(view);
        }
Esempio n. 5
0
        private static RevitDynamoModel InitializeCoreModel(ExternalCommandData commandData)
        {
            var prefs    = PreferenceSettings.Load();
            var corePath =
                Path.GetFullPath(
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\..\");

#if !ENABLE_DYNAMO_SCHEDULER
            return(RevitDynamoModel.Start(
                       new RevitDynamoModel.StartConfiguration()
            {
                Preferences = prefs,
                DynamoCorePath = corePath,
                Context = GetRevitContext(commandData)
            }));
#else
            return(RevitDynamoModel.Start(
                       new RevitDynamoModel.StartConfiguration()
            {
                Preferences = prefs,
                DynamoCorePath = corePath,
                Context = GetRevitContext(commandData),
                SchedulerThread = new RevitSchedulerThread(commandData.Application)
            }));
#endif
        }
Esempio n. 6
0
        public void PreferenceSetting_GroupStyles()
        {
            // Test that thte group style list is being initialized with an empty list
            Assert.NotNull(ViewModel.PreferenceSettings.GroupStyleItemsList);
            Assert.AreEqual(0, ViewModel.PreferenceSettings.GroupStyleItemsList.Count);

            // Test serialization of GroupStyles
            string tempPath = System.IO.Path.GetTempPath();

            tempPath = Path.Combine(tempPath, "userPreference.xml");

            PreferenceSettings initalSetting = new PreferenceSettings();
            PreferenceSettings resultSetting;

            initalSetting.GroupStyleItemsList.Add(new GroupStyleItem {
                HexColorString = "000000",
                Name           = "GroupName"
            });

            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            // Test if the fields are being saved
            Assert.AreEqual(1, initalSetting.GroupStyleItemsList.Count);
            Assert.AreEqual(resultSetting.GroupStyleItemsList[0].Name, initalSetting.GroupStyleItemsList[0].Name);
            Assert.AreEqual(resultSetting.GroupStyleItemsList[0].HexColorString, initalSetting.GroupStyleItemsList[0].HexColorString);

            // Test loading the settings defined in the xml configuration file
            var filePath = Path.Combine(GetTestDirectory(ExecutingDirectory), @"settings\DynamoSettings-OneGroupStyle.xml");
            PreferenceSettings OneGroupStyle = PreferenceSettings.Load(filePath);

            Assert.AreEqual(1, OneGroupStyle.GroupStyleItemsList.Count);
            Assert.AreEqual(OneGroupStyle.GroupStyleItemsList[0].Name, initalSetting.GroupStyleItemsList[0].Name);
            Assert.AreEqual(OneGroupStyle.GroupStyleItemsList[0].HexColorString, initalSetting.GroupStyleItemsList[0].HexColorString);
        }
Esempio n. 7
0
        public void PreferenceSetting_AgreeAnalyticsSharing()
        {
            // Test loading old settings file with agreement
            var filePath      = Path.Combine(GetTestDirectory(ExecutingDirectory), @"settings\DynamoSettings-AnalyticsTurnedOn.xml");
            var resultSetting = PreferenceSettings.Load(filePath);

            Assert.AreEqual(true, resultSetting.IsAnalyticsReportingApproved);
            Assert.AreEqual(false, resultSetting.IsUsageReportingApproved);
            Assert.DoesNotThrow(() => Dynamo.Logging.AnalyticsService.ShutDown());
        }
Esempio n. 8
0
        public void TestSettingsSerialization()
        {
            string tempPath = System.IO.Path.GetTempPath();

            tempPath = Path.Combine(tempPath, "userPreference.xml");

            PreferenceSettings settings = new PreferenceSettings();

            // Assert defaults
            Assert.AreEqual(settings.GetIsBackgroundPreviewActive("MyBackgroundPreview"), true);
            Assert.AreEqual(settings.ShowCodeBlockLineNumber, true);
            Assert.AreEqual(settings.IsIronPythonDialogDisabled, false);
            Assert.AreEqual(settings.ShowTabsAndSpacesInScriptEditor, false);
            Assert.AreEqual(settings.EnableNodeAutoComplete, false);
            Assert.AreEqual(settings.DefaultPythonEngine, string.Empty);
            Assert.AreEqual(settings.MaxNumRecentFiles, PreferenceSettings.DefaultMaxNumRecentFiles);

            // Save
            settings.Save(tempPath);
            settings = PreferenceSettings.Load(tempPath);

            // Assert deserialized values are same when saved with defaults
            Assert.AreEqual(settings.GetIsBackgroundPreviewActive("MyBackgroundPreview"), true);
            Assert.AreEqual(settings.ShowCodeBlockLineNumber, true);
            Assert.AreEqual(settings.IsIronPythonDialogDisabled, false);
            Assert.AreEqual(settings.ShowTabsAndSpacesInScriptEditor, false);
            Assert.AreEqual(settings.EnableNodeAutoComplete, false);
            Assert.AreEqual(settings.DefaultPythonEngine, string.Empty);
            Assert.AreEqual(settings.MaxNumRecentFiles, PreferenceSettings.DefaultMaxNumRecentFiles);

            // Change setting values
            settings.SetIsBackgroundPreviewActive("MyBackgroundPreview", false);
            settings.ShowCodeBlockLineNumber         = false;
            settings.IsIronPythonDialogDisabled      = true;
            settings.ShowTabsAndSpacesInScriptEditor = true;
            settings.DefaultPythonEngine             = "CP3";
            settings.MaxNumRecentFiles      = 24;
            settings.EnableNodeAutoComplete = true;

            // Save
            settings.Save(tempPath);
            settings = PreferenceSettings.Load(tempPath);

            // Assert deserialized values are same as last changed
            Assert.AreEqual(settings.GetIsBackgroundPreviewActive("MyBackgroundPreview"), false);
            Assert.AreEqual(settings.ShowCodeBlockLineNumber, false);
            Assert.AreEqual(settings.IsIronPythonDialogDisabled, true);
            Assert.AreEqual(settings.ShowTabsAndSpacesInScriptEditor, true);
            Assert.AreEqual(settings.DefaultPythonEngine, "CP3");
            Assert.AreEqual(settings.MaxNumRecentFiles, 24);
            Assert.AreEqual(settings.EnableNodeAutoComplete, true);
        }
Esempio n. 9
0
        public void TestLoad()
        {
            string settingDirectory  = Path.Combine(TestDirectory, "settings");
            string settingsFilePath  = Path.Combine(settingDirectory, "DynamoSettings-PythonTemplate-initial.xml");
            string initialPyFilePath = Path.Combine(settingDirectory, @"PythonTemplate-initial.py");

            // Assert files required for test exist
            Assert.IsTrue(File.Exists(settingsFilePath));

            var settings = PreferenceSettings.Load(settingsFilePath);

            Assert.IsNotNull(settings);
        }
Esempio n. 10
0
        public void UsageReportingApprovedSetting()
        {
            var settings = new PreferenceSettings();

            Assert.IsFalse(settings.IsUsageReportingApproved);

            // Check when deserializing preference setting with first run flag
            var settingFilePath = Path.Combine(SettingDirectory, "DynamoSettings-firstrun.xml");
            var settingsFromXML = PreferenceSettings.Load(settingFilePath);

            Assert.IsTrue(settingsFromXML.IsFirstRun);
            Assert.IsFalse(settingsFromXML.IsUsageReportingApproved);
        }
        public void TestMigrateStdLibTokenToBuiltInToken()
        {
            string settingDirectory = Path.Combine(TestDirectory, "settings");
            string settingsFilePath = Path.Combine(settingDirectory, "DynamoSettings-stdlibtoken.xml");

            Assert.IsTrue(File.ReadAllText(settingsFilePath).Contains(DynamoModel.StandardLibraryToken));
            // Assert files required for test exist
            Assert.IsTrue(File.Exists(settingsFilePath));
            var settings = PreferenceSettings.Load(settingsFilePath);

            var token = settings.CustomPackageFolders[1];

            Assert.AreEqual(DynamoModel.BuiltInPackagesToken, token);
        }
Esempio n. 12
0
        public void PreferenceSettings_ShowEdges_Save()
        {
            // Test if variable can be serialize and deserialize without any issue
            string tempPath = System.IO.Path.GetTempPath();

            tempPath = Path.Combine(tempPath, "userPreference.xml");

            var initalSetting = new PreferenceSettings();
            PreferenceSettings resultSetting;

            initalSetting.ShowEdges = true;
            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);
            Assert.True(resultSetting.ShowEdges);
        }
Esempio n. 13
0
        public void TestGetPythonTemplateFilePath()
        {
            string settingDirectory  = Path.Combine(TestDirectory, "settings");
            string settingsFilePath  = Path.Combine(settingDirectory, "DynamoSettings-PythonTemplate-initial.xml");
            string initialPyFilePath = Path.Combine(settingDirectory, @"PythonTemplate-initial.py");

            // Assert files required for test exist
            Assert.IsTrue(File.Exists(settingsFilePath));
            Assert.IsTrue(File.Exists(initialPyFilePath));

            PreferenceSettings.Load(settingsFilePath);

            string pythonTemplateFilePath = Path.Combine(settingDirectory, PreferenceSettings.GetPythonTemplateFilePath());

            Assert.AreEqual(pythonTemplateFilePath, initialPyFilePath);
        }
Esempio n. 14
0
        public void PreferenceSetting_Analytics()
        {
            // Test deserialization of analytics setting
            // Test loading old settings file without agreement
            var filePath      = Path.Combine(GetTestDirectory(ExecutingDirectory), @"settings\DynamoSettings-firstrun.xml");
            var resultSetting = PreferenceSettings.Load(filePath);

            Assert.AreEqual(false, resultSetting.IsAnalyticsReportingApproved);
            Assert.AreEqual(false, resultSetting.IsUsageReportingApproved);

            // Test loading old settings file without render precision attribute
            filePath      = Path.Combine(GetTestDirectory(ExecutingDirectory), @"settings\DynamoSettings-AnalyticsTurnedOn.xml");
            resultSetting = PreferenceSettings.Load(filePath);
            Assert.AreEqual(true, resultSetting.IsAnalyticsReportingApproved);
            Assert.AreEqual(true, resultSetting.IsUsageReportingApproved);
        }
Esempio n. 15
0
        public void LoadInvalidPythonTemplateFromSetting()
        {
            var settingsFilePath = Path.Combine(SettingDirectory, "DynamoSettings-invalidPaths.xml");
            var pyFile           = @"C:\this_folder_doesn't_exist\PythonTemplate.py";

            // check files required for test exist
            Assert.IsTrue(File.Exists(settingsFilePath));

            // load the settings from XML file into DynamoModel
            var settings = PreferenceSettings.Load(settingsFilePath);

            // check settings were read correctly
            Assert.NotNull(settings);
            Assert.IsFalse(File.Exists(settings.PythonTemplateFilePath));
            Assert.IsFalse(File.Exists(pyFile));
            Assert.AreEqual(settings.PythonTemplateFilePath, pyFile);
        }
Esempio n. 16
0
        public void TestSetIsBackgroundPreviewActive()
        {
            string tempPath = System.IO.Path.GetTempPath();

            tempPath = Path.Combine(tempPath, "userPreference.xml");

            // Force initial state
            PreferenceSettings initialSetting = new PreferenceSettings();
            PreferenceSettings resultSetting;

            initialSetting.SetIsBackgroundPreviewActive("IsBackgroundPreviewActive", true);

            initialSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.GetIsBackgroundPreviewActive("IsBackgroundPreviewActive"),
                            initialSetting.GetIsBackgroundPreviewActive("IsBackgroundPreviewActive"));
        }
Esempio n. 17
0
        public void LoadInvalidLocationsFromSetting()
        {
            var filePath = Path.Combine(SettingDirectory, "invalidPaths_DynamoSettings.xml");
            var settings = PreferenceSettings.Load(filePath);

            Assert.NotNull(settings);
            Assert.AreEqual(4, settings.CustomPackageFolders.Count);

            var expectedPackageFolders = new List <string> {
                @"C:\folder_name_with_invalid_:*?|_characters\foobar",
                @"C:\this_folder_doesn't_exist",
                @"X:\this_drive_doesn't_exist",
                @"\\unreachable_machine\share_packages"
            };

            IEnumerable <bool> comparisonResult = settings.CustomPackageFolders.Zip(expectedPackageFolders, string.Equals);

            Assert.IsFalse(comparisonResult.Any(isEqual => !isEqual));
        }
Esempio n. 18
0
        public void PreferenceSetting_BackgroundPreview_1_0API()
        {
            bool expectedValue = !ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive;

            ViewModel.ToggleFullscreenWatchShowing(null);
            Assert.AreEqual(expectedValue, ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive);


            expectedValue = !ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive;
            ViewModel.ToggleFullscreenWatchShowing(null);
            Assert.AreEqual(expectedValue, ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive);

            #region Save And Load of PreferenceSettings

            // Test if variable can be serialize and deserialize without any issue
            string tempPath = System.IO.Path.GetTempPath();
            tempPath = Path.Combine(tempPath, "userPreference.xml");

            // Force inital state
            PreferenceSettings initalSetting = new PreferenceSettings();
            PreferenceSettings resultSetting;

            initalSetting.IsBackgroundPreviewActive = true;

            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.IsBackgroundPreviewActive, initalSetting.IsBackgroundPreviewActive);
            #endregion

            #region Second Test
            initalSetting.IsBackgroundPreviewActive = false;

            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.IsBackgroundPreviewActive, initalSetting.IsBackgroundPreviewActive);
            #endregion
        }
Esempio n. 19
0
        public void TestDisableIronPythonDialogAlert()
        {
            string tempPath = System.IO.Path.GetTempPath();

            tempPath = Path.Combine(tempPath, "userPreference.xml");

            // Force initial state
            PreferenceSettings initialSetting = new PreferenceSettings();
            PreferenceSettings resultSetting;

            Assert.AreEqual(initialSetting.IsIronPythonDialogDisabled, false);

            initialSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.IsIronPythonDialogDisabled, false);

            resultSetting.IsIronPythonDialogDisabled = true;
            resultSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.IsIronPythonDialogDisabled, true);
        }
Esempio n. 20
0
        public void TestSetDisplayCBNLineNumber()
        {
            string tempPath = System.IO.Path.GetTempPath();

            tempPath = Path.Combine(tempPath, "userPreference.xml");

            // Force initial state
            PreferenceSettings initialSetting = new PreferenceSettings();
            PreferenceSettings resultSetting;

            Assert.AreEqual(initialSetting.ShowCodeBlockLineNumber, true);

            initialSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.ShowCodeBlockLineNumber, true);

            resultSetting.ShowCodeBlockLineNumber = false;
            resultSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.ShowCodeBlockLineNumber, false);
        }
Esempio n. 21
0
        public void CanUpdatePythonTemplateSettings()
        {
            string settingDirectory          = Path.Combine(TestDirectory, "settings");
            string settingsFilePath          = Path.Combine(settingDirectory, "DynamoSettings-PythonTemplate-initial.xml");
            string changedSettingsFilePath   = Path.Combine(settingDirectory, "DynamoSettings-PythonTemplate-changed.xml");
            string initialPyFilePath         = Path.Combine(settingDirectory, @"PythonTemplate-initial.py");
            string changedPyFilePath         = Path.Combine(settingDirectory, @"PythonTemplate-changed.py");
            string initialPyVerificationText = "# Unit tests Python template example";
            string updatedPyVerificationText = "# Changed Unit tests Python template example";
            string pyTemplate        = "";
            string updatedPyTemplate = "";

            // Assert files required for test exist
            Assert.IsTrue(File.Exists(settingsFilePath));
            Assert.IsTrue(File.Exists(initialPyFilePath));
            Assert.IsTrue(File.Exists(changedPyFilePath));

            // load initial settings
            // Keep in mind the initial settings file for this test has only specified a filename, not a full path
            var settings = PreferenceSettings.Load(settingsFilePath);

            settings.PythonTemplateFilePath = Path.Combine(settingDirectory, settings.PythonTemplateFilePath);

            // Assert path in settings file and in test match
            Assert.AreEqual(settings.PythonTemplateFilePath, initialPyFilePath);

            // Propagate Python template specified in settings file to DynamoModel & read it from *.py file
            CurrentDynamoModel.PreferenceSettings.PythonTemplateFilePath = settings.PythonTemplateFilePath;
            pyTemplate = File.ReadAllText(CurrentDynamoModel.PreferenceSettings.PythonTemplateFilePath);

            // Assert the template actually reads and is not empty
            Assert.IsNotEmpty(pyTemplate);
            Assert.IsTrue(pyTemplate.StartsWith(initialPyVerificationText));

            // Assert the workspace has no nodes
            Assert.AreEqual(CurrentDynamoModel.CurrentWorkspace.Nodes.Count(), 0);

            // create a Python nodeModel & add node to workspace
            var firstPyNodeModel = new PythonNodeModels.PythonNode();

            CurrentDynamoModel.ExecuteCommand(new DynCmd.CreateNodeCommand(firstPyNodeModel, 0, 0, true, false));
            var firstPyNode = CurrentDynamoModel.CurrentWorkspace.Nodes.Last() as PythonNodeModels.PythonNode;

            // Assert a new node has been added to workspace
            Assert.AreEqual(CurrentDynamoModel.CurrentWorkspace.Nodes.Count(), 1);

            // Assert both the new python nodeModel and workspace node have been
            // initialised with the initial Python template
            Assert.AreEqual(firstPyNodeModel.Script, pyTemplate);
            Assert.AreEqual(firstPyNode.Script, pyTemplate);
            Assert.IsTrue(firstPyNodeModel.Script.StartsWith(initialPyVerificationText));
            Assert.IsTrue(firstPyNode.Script.StartsWith(initialPyVerificationText));

            // change Python template & save settings to XML file
            CurrentDynamoModel.PreferenceSettings.PythonTemplateFilePath = changedPyFilePath;
            CurrentDynamoModel.PreferenceSettings.Save(changedSettingsFilePath);

            // load updated settings
            // no need for combining paths here as we have already done so before saving
            settings = PreferenceSettings.Load(changedSettingsFilePath);

            // update the DynamoModel settings
            CurrentDynamoModel.PreferenceSettings.PythonTemplateFilePath = settings.PythonTemplateFilePath;
            updatedPyTemplate = File.ReadAllText(CurrentDynamoModel.PreferenceSettings.PythonTemplateFilePath);

            // Assert the updated template is applied and not empty
            Assert.AreEqual(
                CurrentDynamoModel.PreferenceSettings.PythonTemplateFilePath,
                changedPyFilePath
                );
            Assert.IsNotEmpty(updatedPyTemplate);
            Assert.IsTrue(updatedPyTemplate.StartsWith(updatedPyVerificationText));

            // create a Python nodeModel & add node to workspace
            var secondPyNodeModel = new PythonNodeModels.PythonNode();

            CurrentDynamoModel.ExecuteCommand(new DynCmd.CreateNodeCommand(secondPyNodeModel, 100, 100, true, false));
            var secondPyNode = CurrentDynamoModel.CurrentWorkspace.Nodes.Last() as PythonNodeModels.PythonNode;

            // Assert a new node has been added to workspace
            Assert.AreEqual(CurrentDynamoModel.CurrentWorkspace.Nodes.Count(), 2);

            // Assert both the new python nodeModel and workspace node have been
            // initialised with the updated Python template
            Assert.AreEqual(secondPyNodeModel.Script, updatedPyTemplate);
            Assert.AreEqual(secondPyNode.Script, updatedPyTemplate);
            Assert.IsTrue(secondPyNodeModel.Script.StartsWith(updatedPyVerificationText));
            Assert.IsTrue(secondPyNode.Script.StartsWith(updatedPyVerificationText));
        }
Esempio n. 22
0
        public void PreferenceSetting()
        {
            // Test Case to ensure that the link for these persistent variable
            // between DynamoViewModel, Model is not broken or replaced.
            #region BackgroundPreviewActive
            bool expectedValue = !ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive;
            ViewModel.ToggleFullscreenWatchShowing(null);
            Assert.AreEqual(expectedValue, ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive);

            expectedValue = !ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive;
            ViewModel.ToggleFullscreenWatchShowing(null);
            Assert.AreEqual(expectedValue, ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive);
            #endregion

            #region ConsoleHeight
            int expectedHeight = 100;;
            ViewModel.ToggleConsoleShowing(null);
            Assert.AreEqual(expectedHeight, ViewModel.Model.PreferenceSettings.ConsoleHeight);

            expectedHeight = 0;
            ViewModel.ToggleConsoleShowing(null);
            Assert.AreEqual(expectedHeight, ViewModel.Model.PreferenceSettings.ConsoleHeight);
            #endregion

            #region ConnectorType
            ConnectorType expectedConnector = ConnectorType.BEZIER;
            ViewModel.SetConnectorType("BEZIER");
            Assert.AreEqual(expectedConnector, ViewModel.Model.PreferenceSettings.ConnectorType);

            expectedConnector = ConnectorType.POLYLINE;
            ViewModel.SetConnectorType("POLYLINE");
            Assert.AreEqual(expectedConnector, ViewModel.Model.PreferenceSettings.ConnectorType);
            #endregion

            #region Collect Information Option
            {
                // Backup the value of Dynamo.IsTestMode and restore it later. The
                // reason for this is 'IsUsageReportingApproved' only returns the
                // actual value when not running in test mode.
                var isTestMode = DynamoModel.IsTestMode;

                // First time run, check if dynamo did set it back to false after running
                Assert.AreEqual(false, UsageReportingManager.Instance.FirstRun);

                // CollectionInfoOption To TRUE
                UsageReportingManager.Instance.SetUsageReportingAgreement(true);
                RestartTestSetup(startInTestMode: false);
                Assert.AreEqual(true, UsageReportingManager.Instance.IsUsageReportingApproved);

                // CollectionInfoOption To FALSE
                UsageReportingManager.Instance.SetUsageReportingAgreement(false);
                RestartTestSetup(startInTestMode: false);
                Assert.AreEqual(false, UsageReportingManager.Instance.IsUsageReportingApproved);

                DynamoModel.IsTestMode = isTestMode; // Restore the orignal value.
            }
            #endregion

            #region Save And Load of PreferenceSettings
            // Test if variable can be serialize and deserialize without any issue
            string tempPath = System.IO.Path.GetTempPath();
            tempPath = Path.Combine(tempPath, "userPreference.xml");

            // Force inital state
            PreferenceSettings initalSetting = new PreferenceSettings();
            PreferenceSettings resultSetting;

            #region First Test

            initalSetting.ConnectorType             = ConnectorType.BEZIER;
            initalSetting.ConsoleHeight             = 100;
            initalSetting.IsBackgroundPreviewActive = true;

            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.IsBackgroundPreviewActive, initalSetting.IsBackgroundPreviewActive);
            Assert.AreEqual(resultSetting.ConnectorType, initalSetting.ConnectorType);
            Assert.AreEqual(resultSetting.ConsoleHeight, initalSetting.ConsoleHeight);
            #endregion

            #region Second Test
            initalSetting.ConnectorType             = ConnectorType.POLYLINE;
            initalSetting.ConsoleHeight             = 0;
            initalSetting.IsBackgroundPreviewActive = false;

            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.IsBackgroundPreviewActive, initalSetting.IsBackgroundPreviewActive);
            Assert.AreEqual(resultSetting.ConnectorType, initalSetting.ConnectorType);
            Assert.AreEqual(resultSetting.ConsoleHeight, initalSetting.ConsoleHeight);
            #endregion

            #endregion

            View.Close();
        }
Esempio n. 23
0
        public void PreferenceSetting()
        {
            // Test Case to ensure that the link for these persistent variable
            // between DynamoViewModel, Controller is not broken or replaced.
            #region FullscreenWatchShowing
            bool expectedValue = !Controller.PreferenceSettings.FullscreenWatchShowing;
            Vm.ToggleFullscreenWatchShowing(null);
            Assert.AreEqual(expectedValue, Controller.PreferenceSettings.FullscreenWatchShowing);

            expectedValue = !Controller.PreferenceSettings.FullscreenWatchShowing;
            Vm.ToggleFullscreenWatchShowing(null);
            Assert.AreEqual(expectedValue, Controller.PreferenceSettings.FullscreenWatchShowing);
            #endregion

            #region ConsoleHeight
            int expectedHeight = 0;;
            Vm.ToggleConsoleShowing(null);
            Assert.AreEqual(expectedHeight, Controller.PreferenceSettings.ConsoleHeight);

            expectedHeight = 100;
            Vm.ToggleConsoleShowing(null);
            Assert.AreEqual(expectedHeight, Controller.PreferenceSettings.ConsoleHeight);
            #endregion

            #region ConnectorType
            ConnectorType expectedConnector = ConnectorType.BEZIER;
            Vm.SetConnectorType("BEZIER");
            Assert.AreEqual(expectedConnector, Controller.PreferenceSettings.ConnectorType);

            expectedConnector = ConnectorType.POLYLINE;
            Vm.SetConnectorType("POLYLINE");
            Assert.AreEqual(expectedConnector, Controller.PreferenceSettings.ConnectorType);
            #endregion

            #region Collect Information Option
            // First time run, check if dynamo did set it back to false after running
            Assert.AreEqual(false, UsageReportingManager.Instance.FirstRun);

            // CollectionInfoOption To TRUE
            UsageReportingManager.Instance.SetUsageReportingAgreement(true);
            RestartTestSetup();
            Assert.AreEqual(true, UsageReportingManager.Instance.IsUsageReportingApproved);

            // CollectionInfoOption To FALSE
            UsageReportingManager.Instance.SetUsageReportingAgreement(false);
            RestartTestSetup();
            Assert.AreEqual(false, UsageReportingManager.Instance.IsUsageReportingApproved);
            #endregion

            #region Save And Load of PreferenceSettings
            // Test if variable can be serialize and deserialize without any issue
            string tempPath = System.IO.Path.GetTempPath();
            tempPath = Path.Combine(tempPath, "userPreference.xml");

            // Force inital state
            PreferenceSettings initalSetting = new PreferenceSettings();
            PreferenceSettings resultSetting;

            #region First Test

            initalSetting.ConnectorType          = ConnectorType.BEZIER;
            initalSetting.ConsoleHeight          = 100;
            initalSetting.FullscreenWatchShowing = true;

            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.FullscreenWatchShowing, initalSetting.FullscreenWatchShowing);
            Assert.AreEqual(resultSetting.ConnectorType, initalSetting.ConnectorType);
            Assert.AreEqual(resultSetting.ConsoleHeight, initalSetting.ConsoleHeight);
            #endregion

            #region Second Test
            initalSetting.ConnectorType          = ConnectorType.POLYLINE;
            initalSetting.ConsoleHeight          = 0;
            initalSetting.FullscreenWatchShowing = false;

            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.FullscreenWatchShowing, initalSetting.FullscreenWatchShowing);
            Assert.AreEqual(resultSetting.ConnectorType, initalSetting.ConnectorType);
            Assert.AreEqual(resultSetting.ConsoleHeight, initalSetting.ConsoleHeight);
            #endregion

            #endregion

            Ui.Close();
        }
Esempio n. 24
0
        public void TestSettingsSerialization()
        {
            string tempPath = System.IO.Path.GetTempPath();

            tempPath = Path.Combine(tempPath, "userPreference.xml");

            PreferenceSettings settings = new PreferenceSettings();

            // Assert defaults
            Assert.AreEqual(settings.GetIsBackgroundPreviewActive("MyBackgroundPreview"), true);
            Assert.AreEqual(settings.ShowCodeBlockLineNumber, true);
            Assert.AreEqual(settings.IsIronPythonDialogDisabled, false);
            Assert.AreEqual(settings.ShowTabsAndSpacesInScriptEditor, false);
            Assert.AreEqual(settings.EnableNodeAutoComplete, true);
            Assert.AreEqual(settings.DefaultPythonEngine, string.Empty);
            Assert.AreEqual(settings.MaxNumRecentFiles, PreferenceSettings.DefaultMaxNumRecentFiles);
            Assert.AreEqual(settings.ViewExtensionSettings.Count, 0);

            // Save
            settings.Save(tempPath);
            settings = PreferenceSettings.Load(tempPath);

            // Assert deserialized values are same when saved with defaults
            Assert.AreEqual(settings.GetIsBackgroundPreviewActive("MyBackgroundPreview"), true);
            Assert.AreEqual(settings.ShowCodeBlockLineNumber, true);
            Assert.AreEqual(settings.IsIronPythonDialogDisabled, false);
            Assert.AreEqual(settings.ShowTabsAndSpacesInScriptEditor, false);
            Assert.AreEqual(settings.EnableNodeAutoComplete, true);
            Assert.AreEqual(settings.DefaultPythonEngine, string.Empty);
            Assert.AreEqual(settings.MaxNumRecentFiles, PreferenceSettings.DefaultMaxNumRecentFiles);
            Assert.AreEqual(settings.ViewExtensionSettings.Count, 0);

            // Change setting values
            settings.SetIsBackgroundPreviewActive("MyBackgroundPreview", false);
            settings.ShowCodeBlockLineNumber         = false;
            settings.IsIronPythonDialogDisabled      = true;
            settings.ShowTabsAndSpacesInScriptEditor = true;
            settings.DefaultPythonEngine             = "CP3";
            settings.MaxNumRecentFiles      = 24;
            settings.EnableNodeAutoComplete = false;
            settings.ViewExtensionSettings.Add(new ViewExtensionSettings()
            {
                Name           = "MyExtension",
                UniqueId       = "1234",
                DisplayMode    = ViewExtensionDisplayMode.FloatingWindow,
                WindowSettings = new WindowSettings()
                {
                    Left   = 123,
                    Top    = 456,
                    Height = 321,
                    Width  = 654,
                    Status = WindowStatus.Maximized
                }
            });

            // Save
            settings.Save(tempPath);
            settings = PreferenceSettings.Load(tempPath);

            // Assert deserialized values are same as last changed
            Assert.AreEqual(settings.GetIsBackgroundPreviewActive("MyBackgroundPreview"), false);
            Assert.AreEqual(settings.ShowCodeBlockLineNumber, false);
            Assert.AreEqual(settings.IsIronPythonDialogDisabled, true);
            Assert.AreEqual(settings.ShowTabsAndSpacesInScriptEditor, true);
            Assert.AreEqual(settings.DefaultPythonEngine, "CP3");
            Assert.AreEqual(settings.MaxNumRecentFiles, 24);
            Assert.AreEqual(settings.EnableNodeAutoComplete, false);
            Assert.AreEqual(settings.ViewExtensionSettings.Count, 1);
            var extensionSettings = settings.ViewExtensionSettings[0];

            Assert.AreEqual(extensionSettings.Name, "MyExtension");
            Assert.AreEqual(extensionSettings.UniqueId, "1234");
            Assert.AreEqual(extensionSettings.DisplayMode, ViewExtensionDisplayMode.FloatingWindow);
            Assert.IsNotNull(extensionSettings.WindowSettings);
            var windowSettings = extensionSettings.WindowSettings;

            Assert.AreEqual(windowSettings.Left, 123);
            Assert.AreEqual(windowSettings.Top, 456);
            Assert.AreEqual(windowSettings.Height, 321);
            Assert.AreEqual(windowSettings.Width, 654);
            Assert.AreEqual(windowSettings.Status, WindowStatus.Maximized);
        }
Esempio n. 25
0
        public void PreferenceSetting()
        {
            // Test Case to ensure that the link for these persistent variable
            // between DynamoViewModel, Controller is not broken or replaced.
            #region FullscreenWatchShowing
            bool expectedValue = !Controller.PreferenceSettings.FullscreenWatchShowing;
            Vm.ToggleFullscreenWatchShowing(null);
            Assert.AreEqual(expectedValue, Controller.PreferenceSettings.FullscreenWatchShowing);

            expectedValue = !Controller.PreferenceSettings.FullscreenWatchShowing;
            Vm.ToggleFullscreenWatchShowing(null);
            Assert.AreEqual(expectedValue, Controller.PreferenceSettings.FullscreenWatchShowing);
            #endregion

            #region ShowConsole
            expectedValue = !Controller.PreferenceSettings.ShowConsole;
            Vm.ToggleConsoleShowing(null);
            Assert.AreEqual(expectedValue, Controller.PreferenceSettings.ShowConsole);

            expectedValue = !Controller.PreferenceSettings.ShowConsole;
            Vm.ToggleConsoleShowing(null);
            Assert.AreEqual(expectedValue, Controller.PreferenceSettings.ShowConsole);
            #endregion

            #region ConnectorType
            ConnectorType expectedConnector = ConnectorType.BEZIER;
            Vm.SetConnectorType("BEZIER");
            Assert.AreEqual(expectedConnector, Controller.PreferenceSettings.ConnectorType);

            expectedConnector = ConnectorType.POLYLINE;
            Vm.SetConnectorType("POLYLINE");
            Assert.AreEqual(expectedConnector, Controller.PreferenceSettings.ConnectorType);
            Ui.Close();
            #endregion

            #region Save And Load of PreferenceSettings
            // Test if variable can be serialize and deserialize without any issue
            string tempPath = System.IO.Path.GetTempPath();
            tempPath = Path.Combine(tempPath, "userPreference.xml");

            // Force inital state
            PreferenceSettings initalSetting = new PreferenceSettings();
            PreferenceSettings resultSetting;

            #region First Test

            initalSetting.ConnectorType          = ConnectorType.BEZIER;
            initalSetting.ShowConsole            = true;
            initalSetting.FullscreenWatchShowing = true;

            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.FullscreenWatchShowing, initalSetting.FullscreenWatchShowing);
            Assert.AreEqual(resultSetting.ConnectorType, initalSetting.ConnectorType);
            Assert.AreEqual(resultSetting.ShowConsole, initalSetting.ShowConsole);
            #endregion

            #region Second Test
            initalSetting.ConnectorType          = ConnectorType.POLYLINE;
            initalSetting.ShowConsole            = false;
            initalSetting.FullscreenWatchShowing = false;

            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.FullscreenWatchShowing, initalSetting.FullscreenWatchShowing);
            Assert.AreEqual(resultSetting.ConnectorType, initalSetting.ConnectorType);
            Assert.AreEqual(resultSetting.ShowConsole, initalSetting.ShowConsole);
            #endregion

            #endregion
        }