public void ShouldGetInitializationActionsFromRequest()
    {
      object[] arguments = { "argument" };
      RequestInitializationContext context = new RequestInitializationContext(new Request { InitializationHandlers = { new InitializationHandler(typeof(SampleInitializationHandler), arguments) } }, new Response());
      RequestInitializationActionDiscoverer discoverer = new RequestInitializationActionDiscoverer();

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

      Assert.Equal(1, result.Count());
      Assert.Equal(typeof(SampleInitializationHandler).FullName, result.Single().Id);
      Assert.IsType<InitializationHandler>(result.Single().State);
      Assert.Equal(typeof(SampleInitializationHandler), ((InitializationHandler)result.Single().State).Type);
      Assert.Equal(arguments, ((InitializationHandler)result.Single().State).Arguments);
      Assert.Equal(context, result.Single().Context);
    }
    /// <summary>
    /// Gets initialization actions.
    /// </summary>
    /// <param name="context">The request initialization context.</param>
    /// <returns>List of discovered initialization actions.</returns>
    protected virtual IEnumerable<InitializationAction> GetInitializationActions(RequestInitializationContext context)
    {
      if (context == null)
      {
        throw new ArgumentNullException("context");
      }

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

      foreach (InitializationHandler initializationHandler in context.Request.InitializationHandlers)
      {
        result.Add(new InitializationAction(initializationHandler.Type.FullName) { State = initializationHandler, Context = context });
      }

      return result;
    }
        /// <summary>
        /// Gets initialization actions.
        /// </summary>
        /// <param name="context">The initialization context.</param>
        /// <returns>List of discovered initialization actions.</returns>
        public sealed override IEnumerable <InitializationAction> GetInitializationActions(object context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            RequestInitializationContext requestInitializationContext = context as RequestInitializationContext;

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

            return(this.GetInitializationActions(requestInitializationContext));
        }
    /// <summary>
    /// Initializes a new instance of the <see cref="WorkerRequest"/> class.
    /// </summary>
    /// <param name="initializationManager">The initialization Manager.</param>
    /// <param name="context">The request initialization context.</param>
    /// <param name="writer">The writer.</param>
    internal WorkerRequest(InitializationManager initializationManager, RequestInitializationContext context, TextWriter writer) : base(context.Request.Path, context.Request.QueryString, writer)
    {
      if (initializationManager == null)
      {
        throw new ArgumentNullException("initializationManager");
      }

      if (context == null)
      {
        throw new ArgumentNullException("context");
      }

      this.connectionId = Interlocked.Increment(ref connectionCount);

      this.initializationManager = initializationManager;
      this.context = context;
    }
        /// <summary>
        /// Gets initialization actions.
        /// </summary>
        /// <param name="context">The request initialization context.</param>
        /// <returns>List of discovered initialization actions.</returns>
        protected virtual IEnumerable <InitializationAction> GetInitializationActions(RequestInitializationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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

            foreach (InitializationHandler initializationHandler in context.Request.InitializationHandlers)
            {
                result.Add(new InitializationAction(initializationHandler.Type.FullName)
                {
                    State = initializationHandler, Context = context
                });
            }

            return(result);
        }
 /// <summary>
 /// The set initialization context.
 /// </summary>
 /// <param name="context">The context.</param>
 public void SetInitializationContext(object context)
 {
   this.initializationContext = (RequestInitializationContext)context;
 }