public void ShouldDiscoverInitializationActionsMatchingToAssemblyDefinedInitializationHandlerAttributes()
    {
      TestApplicationInitializationContext context = new TestApplicationInitializationContext(Substitute.For<TestApplication>(Substitute.For<InitializationManager>(new TestInitializationActionDiscoverer(), new InitializationActionExecutor())));
      TestApplicationInitializationActionDiscoverer discoverer = new TestApplicationInitializationActionDiscoverer();

      IEnumerable<InitializationAction> result = discoverer.GetInitializationActions(context).ToArray();

      Assert.Equal(3, result.Count());

      Assert.Equal(typeof(SampleInitializationHandler).AssemblyQualifiedName, result.First().Id);
      Assert.IsType<InitializationHandler>(result.First().State);
      Assert.Equal(typeof(SampleInitializationHandler), ((InitializationHandler)result.First().State).Type);
      Assert.Empty(((InitializationHandler)result.First().State).Arguments);
      Assert.Equal(context, result.First().Context);

      Assert.Equal(typeof(SampleInitializationHandler).AssemblyQualifiedName, result.ElementAt(1).Id);
      Assert.IsType<InitializationHandler>(result.ElementAt(1).State);
      Assert.Equal(typeof(SampleInitializationHandler), ((InitializationHandler)result.ElementAt(1).State).Type);
      Assert.Equal(new object[] { "parameter" }, ((InitializationHandler)result.ElementAt(1).State).Arguments);
      Assert.Equal(context, result.ElementAt(1).Context);

      Assert.Equal(typeof(SampleInitializationHandler).AssemblyQualifiedName, result.ElementAt(2).Id);
      Assert.IsType<InitializationHandler>(result.ElementAt(2).State);
      Assert.Equal(typeof(SampleInitializationHandler), ((InitializationHandler)result.ElementAt(2).State).Type);
      Assert.Empty(((InitializationHandler)result.ElementAt(2).State).Arguments);
      Assert.Equal(context, result.ElementAt(2).Context);
    }
        /// <summary>
        /// Gets initialization actions.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>The list of initialization actions.</returns>
        public sealed override IEnumerable <InitializationAction> GetInitializationActions(object context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            TestApplicationInitializationContext applicationContext = context as TestApplicationInitializationContext;

            if (applicationContext == null)
            {
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Only contexts derived from '{0}' are supported.", typeof(TestApplicationInitializationContext).AssemblyQualifiedName));
            }

            return(this.GetInitializationActions(applicationContext));
        }
    /// <summary>
    /// Gets initialization actions.
    /// </summary>
    /// <param name="context">The context.</param>
    /// <returns>The list of initialization actions.</returns>
    protected virtual IEnumerable<InitializationAction> GetInitializationActions(TestApplicationInitializationContext context)
    {
      List<InitializationHandlerAttribute> attributes = new List<InitializationHandlerAttribute>();

      foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
      {
        attributes.AddRange(Utility.GetAttributes<InitializationHandlerAttribute>(assembly));
      }

      attributes.Sort(InitializationHandlerAttributePriorityComparer.Default);

      List<InitializationAction> result = new List<InitializationAction>();

      foreach (InitializationHandlerAttribute initializationHandlerAttribute in attributes)
      {
        result.Add(Utility.InitializationActionFromInitializationHandlerAttribute(initializationHandlerAttribute, context));
      }

      return result;
    }
        /// <summary>
        /// Gets initialization actions.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>The list of initialization actions.</returns>
        protected virtual IEnumerable <InitializationAction> GetInitializationActions(TestApplicationInitializationContext context)
        {
            List <InitializationHandlerAttribute> attributes = new List <InitializationHandlerAttribute>();

            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                attributes.AddRange(Utility.GetAttributes <InitializationHandlerAttribute>(assembly));
            }

            attributes.Sort(InitializationHandlerAttributePriorityComparer.Default);

            List <InitializationAction> result = new List <InitializationAction>();

            foreach (InitializationHandlerAttribute initializationHandlerAttribute in attributes)
            {
                result.Add(Utility.InitializationActionFromInitializationHandlerAttribute(initializationHandlerAttribute, context));
            }

            return(result);
        }