Esempio n. 1
0
        public void SuccessAndFailActions()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(new XmlTextReader(Utils.MakeTestRelativePath("ActionExecutionTests.xml")));

            Manager.EnablePackage(package);

            try
            {
                // Must fail.
                package.Execute(new MockObjects.MockReference("SuccessAndFailActions", ""));
            }
            catch (ActionExecutionException)
            {
                Assert.IsNotNull(Tracker.Executed[typeof(SuccessAction)]);
                Assert.IsNotNull(Tracker.Executed[typeof(FailAction)]);
                Assert.IsNull(Tracker.Undone[typeof(FailAction)]);
                Assert.IsNotNull(Tracker.Undone[typeof(SuccessAction)]);

                // We passed.
                return;
            }

            Assert.Fail("Execution should have failed.");
        }
Esempio n. 2
0
        public void ExecuteRecipeTypeAlias()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(Utils.MakeTestRelativePath("RecipeTest.xml"));

            EnablePackage(package);
            package.Execute(new MockObjects.MockReference("TypeAliasArgument", ""));
        }
Esempio n. 3
0
        public void TryChangeValueProviderOnChange()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(new XmlTextReader(
                                                              Utils.MakeTestRelativePath("Services\\ReadOnlyDictionaryServiceTests.xml")));

            EnablePackage(package);
            package.Execute(new MockObjects.MockReference("TryChangeValueProviderOnChange", ""));
        }
Esempio n. 4
0
        public void ExecuteNullNoWizard()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(Utils.MakeTestRelativePath("RecipeTest.xml"));

            EnablePackage(package);

            package.Execute(new MockObjects.MockReference("NullNoWizard", ""));
        }
Esempio n. 5
0
        public void ConfigurableEditor()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(Utils.MakeTestRelativePath("ValueProviderTests.xml"));

            EnablePackage(package);

            package.Execute(new MockObjects.MockReference("ValueEditorConfig", ""));
            Assert.IsTrue(Flags[0]);
        }
Esempio n. 6
0
        public void SuccessfullAction()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(new XmlTextReader(Utils.MakeTestRelativePath("ActionExecutionTests.xml")));

            Manager.EnablePackage(package);

            package.Execute(new MockObjects.MockReference("SuccessfullAction", ""));

            // Check the "SuccessAction" action was executed.
            Assert.IsNotNull(Tracker.Executed[typeof(SuccessAction)]);
        }
Esempio n. 7
0
        public void WizardChangeMonitoring()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(Utils.MakeTestRelativePath("ValueProviderTests.xml"));

            EnablePackage(package);

            package.Execute(new MockObjects.MockReference("TestChangeNotification", ""));

            Assert.IsTrue(Flags[0]);
            Assert.AreEqual("A new value-B", Values["B"]);
        }
Esempio n. 8
0
        public void CanReplaceExecutionService()
        {
            MockActionExecutionService exec = new MockActionExecutionService();
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(Utils.MakeTestRelativePath("RecipeTest.xml"));

            EnablePackage(package);
            package.AddService(typeof(IActionExecutionService), exec);

            package.Execute(new MockObjects.MockReference("TestRecipe", ""));

            Assert.IsTrue(exec.ExecuteCalled, "Custom execution service was not called");
        }
Esempio n. 9
0
        //[Ignore("Test display a dialog and waits for input, Daniel to fix it")]
        public void ValueEditorChangeMonitoring()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(Utils.MakeTestRelativePath("ValueProviderTests.xml"));

            EnablePackage(package);

            // Set a value for the FirstValueProvider class to pick.
            Values["FirstValueProvider"]  = "Hi there";
            Values["ConcatValueProvider"] = " from B";

            package.Execute(new MockObjects.MockReference("ValueEditorChangeMonitoring", ""));
            Assert.IsTrue(Flags[0]);
            Assert.AreEqual("Bye Hi there from B", Values["ConcatValueProvider"]);
        }
Esempio n. 10
0
        public void TryChangeValueProviderAfter()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(new XmlTextReader(
                                                              Utils.MakeTestRelativePath("Services\\ReadOnlyDictionaryServiceTests.xml")));

            EnablePackage(package, true);
            try
            {
                package.Execute(new MockObjects.MockReference("TryChangeValueProviderAfter", ""));
            }
            catch (ValueProviderException aex)
            {
                throw aex.InnerException;
            }
        }
Esempio n. 11
0
        public void FailAction()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(new XmlTextReader(Utils.MakeTestRelativePath("ActionExecutionTests.xml")));

            Manager.EnablePackage(package);

            try
            {
                // Must fail.
                package.Execute(new MockObjects.MockReference("FailAction", ""));
            }
            catch
            {
                // We passed.
                return;
            }

            Assert.Fail("Execution should have failed.");
        }
Esempio n. 12
0
        public void ExecuteNullWizardNoGathering()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(Utils.MakeTestRelativePath("RecipeTest.xml"));

            // Don't add the gathering service to the package.
            Manager.EnablePackage(package);
            Manager.AddService(typeof(IUIService), new MockServices.MockUIService());
            try
            {
                ExecutionResult result = package.Execute(new MockObjects.MockReference("TestRecipe", ""));
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }
                else
                {
                    throw e;
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Adds a package to the manager, enabling it for use.
        /// </summary>
        /// <param name="component">The package component.</param>
        /// <param name="name">Optional name (can be <see langword="null"/>)
        /// that must match the package name.</param>
        /// <remarks>
        /// This method is also called to add to the container services that
        /// inherit from <see cref="IComponent"/>, so the type of the component
        /// is not enforced. Just special logic is applied to package component types.
        /// </remarks>
        public override void Add(IComponent component, string name)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (component is GuidancePackage)
            {
                GuidancePackage package = (GuidancePackage)component;
                if (name != null && name != package.Configuration.Name)
                {
                    throw new ArgumentException(String.Format(
                                                    System.Globalization.CultureInfo.CurrentCulture,
                                                    Properties.Resources.RecipeManager_NameDoesntMatch,
                                                    name, package.Configuration.Caption));
                }
                // If there's a host listening, query for name to see if they match.
                IHostService host = GetService <IHostService>();
                if (host != null && host.HostName != package.Configuration.Host)
                {
                    throw new ArgumentException(String.Format(
                                                    System.Globalization.CultureInfo.CurrentCulture,
                                                    Properties.Resources.RecipeManager_PackageHostMismatch,
                                                    package.Configuration.Caption,
                                                    package.Configuration.Host,
                                                    host.HostName));
                }

                try
                {
                    // Force the package to be sited at Enabling event time also.
                    base.Add(component, package.Configuration.Name);
                    bool executebinding = true;
                    if (EnablingPackage != null)
                    {
                        CancelPackageEventArgs args = new CancelPackageEventArgs(
                            package, false);
                        EnablingPackage(this, args);
                        if (args.Cancel)
                        {
                            base.Remove(component);
                            return;
                        }
                        executebinding = args.ExecuteBindingRecipe;
                    }
                    if (executebinding && package.Configuration.BindingRecipe != null &&
                        package.Configuration.BindingRecipe.Length > 0)
                    {
                        package.TurnOnOutput();
                        package.Execute(package.Configuration.BindingRecipe);
                        package.TurnOffOutput();
                    }
                    if (EnabledPackage != null)
                    {
                        EnabledPackage(this, new PackageEventArgs(package));
                    }
                }
                catch
                {
                    // Notify host that we're disabling.
                    if (DisablingPackage != null)
                    {
                        DisablingPackage(this, new CancelPackageEventArgs(package, false));
                    }
                    // Don't let the package be enabled if an exception happened.
                    base.Remove(component);
                    if (DisabledPackage != null)
                    {
                        DisabledPackage(this, new PackageEventArgs(package));
                    }
                    package.GetService <IPersistenceService>(true).ClearState(package.Configuration.Name);
                    throw;
                }
            }
            else
            {
                // Just add the component so it gets sited.
                // Services that implement IComponent will arrive here.
                base.Add(component, name);
            }
        }