Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }