예제 #1
0
        public void WithAfterExecuteWithActionOnExtensionWithInitializer_Behavior_ShouldAddBehaviorToLastExecutable()
        {
            IBehavior <ICustomExtension> behavior = null;
            Action <IBehaviorAware <ICustomExtension>, object> contextInitializer = null;

            var extension = new Mock <IExecutable <ICustomExtension> >();

            extension.Setup(x => x.Add(It.IsAny <IBehavior <ICustomExtension> >())).Callback <IBehavior <ICustomExtension> >(
                b => behavior = b);

            this.executableFactory.Setup(
                f =>
                f.CreateExecutable(It.IsAny <Expression <Func <object> > >(), It.IsAny <Expression <Action <ICustomExtension, object> > >(), It.IsAny <Action <IBehaviorAware <ICustomExtension>, object> >()))
            .Callback <Expression <Func <object> >, Expression <Action <ICustomExtension, object> >, Action <IBehaviorAware <ICustomExtension>, object> >(
                (func, action, ctx) => contextInitializer = ctx).Returns(Mock.Of <IExecutable <ICustomExtension> >);

            var context = new object();

            this.testee.Execute(() => context, (e, o) => e.Dispose()).With(o => new TestableBehavior(o));

            contextInitializer(extension.Object, context);

            behavior.Should().NotBeNull();
            behavior.As <TestableBehavior>().Context.Should().Be(context);
        }
예제 #2
0
        public void WithAfterExecuteWithActionOnExtensionWithInitializer_Behavior_ShouldAddBehaviorToLastExecutable()
        {
            IBehavior <ICustomExtension> behavior = null;
            Action <IBehaviorAware <ICustomExtension>, object> contextInitializer = null;

            var extension = A.Fake <IExecutable <ICustomExtension> >();

            A.CallTo(() => extension.Add(A <IBehavior <ICustomExtension> > ._)).Invokes((IBehavior <ICustomExtension> b) => behavior = b);

            A.CallTo(() => this.executableFactory.CreateExecutable(
                         A <Expression <Func <object> > > ._,
                         A <Expression <Action <ICustomExtension, object> > > ._,
                         A <Action <IBehaviorAware <ICustomExtension>, object> > ._))
            .Invokes((Expression <Func <object> > func, Expression <Action <ICustomExtension, object> > action, Action <IBehaviorAware <ICustomExtension>, object> ctx) => contextInitializer = ctx)
            .Returns(A.Fake <IExecutable <ICustomExtension> >());

            var context = new object();

            this.testee.Execute(() => context, (e, o) => e.Dispose()).With(o => new TestableBehavior(o));

            contextInitializer(extension, context);

            behavior.Should().NotBeNull();
            behavior.As <TestableBehavior>().Context.Should().Be(context);
        }