public void ShouldThrowInvalidOperationExceptionIfThereIsNoConstructorThatMatchesArguments()
    {
      InitializationActionExecutor executor = new InitializationActionExecutor();
      InitializationAction action = new InitializationAction("Action") { State = new InitializationHandler(typeof(SimpleInitializer), new object[] { 1 }) };

      Assert.ThrowsDelegate routine = () => executor.ExecuteInitializationForAction(action);

      Assert.Throws<InvalidOperationException>(routine);
    }
    public void ShouldThrowExceptionOnInitializationIfActionStateIsNotAnInitializationHandler()
    {
      InitializationActionExecutor executor = new InitializationActionExecutor();
      InitializationAction initializationAction = new InitializationAction("System.String,mscorlib") { State = "a" };

      Assert.ThrowsDelegate action = () => executor.ExecuteInitializationForAction(initializationAction);

      Assert.Throws<ArgumentException>(action);
    }
    public void ShouldSetInitializationContextIfInitializationHandlerImplementsIInitializationContextAware()
    {
      InitializationActionExecutor executor = new InitializationActionExecutor();
      TestInitializationContext context = new TestInitializationContext(null, typeof(string).GetMethod("Intern"), new object[0]);
      InitializationAction action = new InitializationAction("Action") { State = new InitializationHandler(typeof(InitializationContextAwareInitializer), new object[0]), Context = context };

      InitializationContextAwareInitializer.InitializationContext = null;

      executor.ExecuteInitializationForAction(action);

      Assert.Equal(context, InitializationContextAwareInitializer.InitializationContext);
    }
    public void ShouldCreateInitializerInstanceOnInitializationAndSaveItIntoActionsState()
    {
      InitializationActionExecutor executor = new InitializationActionExecutor();
      InitializationAction action = new InitializationAction("Action") { State = new InitializationHandler(typeof(SimpleInitializer), new object[0]) };

      SimpleInitializer.Parameter = null;
      
      executor.ExecuteInitializationForAction(action);

      Assert.NotNull(SimpleInitializer.Parameter);
      Assert.Equal(string.Empty, SimpleInitializer.Parameter);
    }
    public void ShouldCreateInitializerInstanceUsingParametersOnInitializationAndSaveItIntoActionsState(Type initializerType)
    {
      const string Parameter = "parameter";

      InitializationActionExecutor executor = new InitializationActionExecutor();
      InitializationAction action = new InitializationAction("Action") { State = new InitializationHandler(initializerType, new object[] { Parameter }) };

      SimpleInitializer.Parameter = null;

      executor.ExecuteInitializationForAction(action);

      Assert.NotNull(SimpleInitializer.Parameter);
      Assert.Equal(Parameter, SimpleInitializer.Parameter);
    }
コード例 #6
0
    /// <summary>
    /// Initializes a new instance of the <see cref="InitializationManager"/> class.
    /// </summary>
    /// <param name="initializationActionDiscoverer">The initialization Action discoverer.</param>
    /// <param name="initializationActionExecutor">The initialization Action executor.</param>
    /// <param name="actions">The action container.</param>
    public InitializationManager(InitializationActionDiscoverer initializationActionDiscoverer, InitializationActionExecutor initializationActionExecutor, IDictionary<int, IList<InitializationAction>> actions)
    {
      if (initializationActionDiscoverer == null)
      {
        throw new ArgumentNullException("initializationActionDiscoverer");
      }

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

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

      this.initializationActionDiscoverer = initializationActionDiscoverer;
      this.initializationActionExecutor = initializationActionExecutor;
      this.actions = actions;
    }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InitializationManager"/> class.
        /// </summary>
        /// <param name="initializationActionDiscoverer">The initialization Action discoverer.</param>
        /// <param name="initializationActionExecutor">The initialization Action executor.</param>
        /// <param name="actions">The action container.</param>
        public InitializationManager(InitializationActionDiscoverer initializationActionDiscoverer, InitializationActionExecutor initializationActionExecutor, IDictionary <int, IList <InitializationAction> > actions)
        {
            if (initializationActionDiscoverer == null)
            {
                throw new ArgumentNullException("initializationActionDiscoverer");
            }

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

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

            this.initializationActionDiscoverer = initializationActionDiscoverer;
            this.initializationActionExecutor   = initializationActionExecutor;
            this.actions = actions;
        }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InitializationManager"/> class.
 /// </summary>
 /// <param name="initializationActionDiscoverer">The initialization Action discoverer.</param>
 /// <param name="initializationActionExecutor">The initialization Action executor.</param>
 public InitializationManager(InitializationActionDiscoverer initializationActionDiscoverer, InitializationActionExecutor initializationActionExecutor) : this(initializationActionDiscoverer, initializationActionExecutor, new Dictionary<int, IList<InitializationAction>>())
 {
 }
    public void ShouldDoNothingOnCleanupIfInitializerInstanceIsNotSet()
    {
      InitializationActionExecutor executor = new InitializationActionExecutor();
      InitializationAction action = new InitializationAction("Action");

      executor.ExecuteCleanupForAction(action);
    }
    public void ShouldDoNothingOnCleanupIfInitializerInstanceCannotBeDisposed()
    {
      InitializationActionExecutor executor = new InitializationActionExecutor();
      InitializationAction action = new InitializationAction("Action") { State = new SimpleInitializer() };

      executor.ExecuteCleanupForAction(action);
    }
    public void ShouldDisposeInitializerInstanceOnCleanup()
    {
      InitializationActionExecutor executor = new InitializationActionExecutor();
      InitializationAction action = new InitializationAction("Action") { State = new DisposibleInitializer() };

      DisposibleInitializer.Disposed = false;

      executor.ExecuteCleanupForAction(action);

      Assert.True(DisposibleInitializer.Disposed);
    }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InitializationManager"/> class.
 /// </summary>
 /// <param name="initializationActionDiscoverer">The initialization Action discoverer.</param>
 /// <param name="initializationActionExecutor">The initialization Action executor.</param>
 public InitializationManager(InitializationActionDiscoverer initializationActionDiscoverer, InitializationActionExecutor initializationActionExecutor) : this(initializationActionDiscoverer, initializationActionExecutor, new Dictionary <int, IList <InitializationAction> >())
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="InitializationManagerTest"/> class.
 /// </summary>
 public InitializationManagerTest()
 {
   this.actionDiscoverer = Substitute.For<TestInitializationActionDiscoverer>();
   this.actionExecutor = Substitute.For<InitializationActionExecutor>();
   this.manager = new InitializationManager(this.actionDiscoverer, this.actionExecutor);
 }