public void no_return_sad_path_with_structuremapexception()
        {
            var wrapped = TryCatchWrapper.WrapFunc <FakeStructureMapException>("bad!", null, badSmVoid, "okay");
            var action  = Expression.Lambda <Action>(wrapped).Compile();

            Exception <StructureMapException> .ShouldBeThrownBy(() => { action(); }).ShouldBeTheSameAs(smEx);
        }
        public void no_return_happy_type()
        {
            var wrapped = TryCatchWrapper.WrapFunc <FakeStructureMapException>("bad!", null, goodVoid, "okay");
            var action  = Expression.Lambda <Action>(wrapped).Compile();

            action();
        }
예제 #3
0
        public void wrap_against_a_successful_expression_by_IDescribed()
        {
            var wrapped = TryCatchWrapper.WrapFunc <FakeStructureMapException>("bad!", typeof(string), good,
                                                                               new StubbedDescribed("my description"));

            var func = Expression.Lambda <Func <string> >(wrapped).Compile();

            func().ShouldBe("I am good");
        }
예제 #4
0
        public void wrap_against_a_successful_expression_by_string_description()
        {
            var wrapped = TryCatchWrapper.WrapFunc <FakeStructureMapException>("bad!", typeof(string), good,
                                                                               "some description");


            var func = Expression.Lambda <Func <string> >(wrapped).Compile();

            func().ShouldEqual("I am good");
        }
예제 #5
0
        private void addDecorators(ParameterExpression context, ParameterExpression pluginTypeVariable, BlockPlan plan)
        {
            _decorators.Each(decorator => {
                var decoratedExpression = decorator.ToExpression(_policies, context, pluginTypeVariable);
                var wrapped             =
                    TryCatchWrapper.WrapFunc <StructureMapInterceptorException>(
                        "Decorator Interceptor failed during object construction.  See the inner exception", _pluginType,
                        decoratedExpression, decorator);

                plan.Add(Expression.Assign(pluginTypeVariable, wrapped));
            });
        }
예제 #6
0
        public void wrap_against_a_failed_StructureMapException_by_string_description()
        {
            var wrapped = TryCatchWrapper.WrapFunc <FakeStructureMapException>("bad!", typeof(string), throwSM,
                                                                               "some description");

            var func = Expression.Lambda <Func <string> >(wrapped).Compile();

            var ex = Exception <StructureMapException> .ShouldBeThrownBy(() => func());

            ex.Message.ShouldContain("some description");
            ex.ShouldBeTheSameAs(smEx);
        }
예제 #7
0
        public void wrap_against_a_failed_generic_exception_by_IDescribed()
        {
            var wrapped = TryCatchWrapper.WrapFunc <FakeStructureMapException>("bad!", typeof(string), throwGeneral,
                                                                               new StubbedDescribed("my description"));

            var func = Expression.Lambda <Func <string> >(wrapped).Compile();

            var ex = Exception <FakeStructureMapException> .ShouldBeThrownBy(() => func());

            ex.Title.ShouldBe("bad!");
            ex.Message.ShouldContain("my description");
            ex.InnerException.ShouldBeTheSameAs(genericEx);
        }
예제 #8
0
            public IEnumerable <Expression> CreateExpressions(Policies policies, ParameterExpression originalVariable)
            {
                var variable = _variable ?? originalVariable;

                if (_variable != null)
                {
                    yield return(Expression.Assign(_variable, Expression.Convert(originalVariable, _group.Key)));
                }

                foreach (var interceptor in _group)
                {
                    var interceptionExpression = interceptor.ToExpression(policies, Parameters.Context, variable);

                    yield return
                        (TryCatchWrapper.WrapAction <StructureMapInterceptorException>(
                             "Activator interceptor failed during object creation.  See the inner exception for details.",
                             interceptionExpression, interceptor));
                }
            }