public void ShouldThrowNotSupportedExceptionIfCalledWithOtherThanInitializationContextTypeOfContext()
    {
      TestInitializationActionDiscoverer actionDiscoverer = new TestInitializationActionDiscoverer();

      Assert.ThrowsDelegate action = () => actionDiscoverer.GetInitializationActions(new object());

      Assert.Throws<NotSupportedException>(action);
    }
    public void ShouldTakeIntoTheAccoutThePriority()
    {
      TestInitializationActionDiscoverer actionDiscoverer = new TestInitializationActionDiscoverer();
      Test test = new Test();

      IEnumerable<InitializationAction> actions = actionDiscoverer.GetInitializationActions(new TestInitializationContext(test, typeof(Test).GetMethod("TestMethodWithPrioritizedInitializationHandler"), new object[0])).ToArray();

      Assert.Equal(3, actions.Count());
      Assert.Equal(typeof(InitializationHandler2).AssemblyQualifiedName, actions.First().Id);
      Assert.Equal(typeof(InitializationHandler2), ((InitializationHandler)actions.First().State).Type);
      Assert.Equal(typeof(InitializationHandler1).AssemblyQualifiedName, actions.ElementAt(1).Id);
      Assert.Equal(typeof(InitializationHandler1), ((InitializationHandler)actions.ElementAt(1).State).Type);
      Assert.Equal(typeof(InitializationHandler2).AssemblyQualifiedName, actions.ElementAt(2).Id);
      Assert.Equal(typeof(InitializationHandler2), ((InitializationHandler)actions.ElementAt(2).State).Type);
    }
    public void ShouldDiscoverActionsByInitializationHandlerAttributes()
    {
      const string Argument = "argument";

      TestInitializationActionDiscoverer actionDiscoverer = new TestInitializationActionDiscoverer();
      Test test = new Test();

      IEnumerable<InitializationAction> actions = actionDiscoverer.GetInitializationActions(new TestInitializationContext(test, typeof(Test).GetMethod("TestMethod"), new object[] { Argument })).ToArray();

      Assert.Equal(1, actions.Count());

      TestInitializationContext expectedInitializationContext = new TestInitializationContext(test, typeof(Test).GetMethod("TestMethod"), new object[] { Argument });
      
      Assert.Equal(typeof(InitializationHandler1).AssemblyQualifiedName, actions.Single().Id);
      Assert.IsType<InitializationHandler>(actions.Single().State);
      Assert.Equal(typeof(InitializationHandler1), ((InitializationHandler)actions.Single().State).Type);
      Assert.Equal(new object[] { "parameter" }, ((InitializationHandler)actions.Single().State).Arguments);
      Assert.Equal(expectedInitializationContext.Instance, ((TestInitializationContext)actions.Single().Context).Instance);
      Assert.Equal(expectedInitializationContext.Method, ((TestInitializationContext)actions.Single().Context).Method);
      Assert.Equal(expectedInitializationContext.Arguments, ((TestInitializationContext)actions.Single().Context).Arguments);
    }