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(); }
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"); }
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"); }
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)); }); }
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); }
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); }
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)); } }