Example #1
0
        public void NonCallbackTargetTypeCallsNext()
        {
            var called = false;
            var callbackFactoryMock = new Mock <ICallbackFactory <object> >();
            var binder = new CallbackBinder <object>(context => called = true, callbackFactoryMock.Object);

            var ctx = new BindingContext <object>(ObjectBindingDirection.In, context => { });

            ctx.TargetType = typeof(string);

            binder.Bind(ctx);

            Assert.True(called);
        }
Example #2
0
        public void OutDirectionCallsNext()
        {
            var called = false;
            var callbackFactoryMock = new Mock <ICallbackFactory <object> >();
            var binder = new CallbackBinder <object>(context => called = true, callbackFactoryMock.Object);

            var ctx = new BindingContext <object>(ObjectBindingDirection.Out, context => { });

            ctx.ObjectValue = "str";

            binder.Bind(ctx);

            Assert.True(called);
        }
Example #3
0
        public void TypedCallbackCallsFactory()
        {
            BindingDelegate <object> bindingDelegate = context =>
            {
            };
            var callbackFactoryMock = new Mock <ICallbackFactory <object> >();

            callbackFactoryMock.Setup(_ => _.CreateCallback(1, typeof(Action), bindingDelegate)).Returns("str");
            var binder = new CallbackBinder <object>(context => {
                context.ObjectValue = new CallbackDescriptor
                {
                    FunctionId = 1
                };
            }, callbackFactoryMock.Object);

            var ctx = new BindingContext <object>(ObjectBindingDirection.In, bindingDelegate);

            ctx.TargetType = typeof(Action);

            binder.Bind(ctx);

            Assert.Equal("str", ctx.ObjectValue);
        }
Example #4
0
        public void FailedCreationSetsNull()
        {
            BindingDelegate <object> bindingDelegate = context =>
            {
            };
            var callbackFactoryMock = new Mock <ICallbackFactory <object> >();

            callbackFactoryMock.Setup(_ => _.CreateCallback(1, typeof(Action), bindingDelegate))
            .Throws(new InvalidOperationException());
            var binder = new CallbackBinder <object>(context => {
                context.ObjectValue = new CallbackDescriptor
                {
                    FunctionId = 1
                };
            }, callbackFactoryMock.Object);

            var ctx = new BindingContext <object>(ObjectBindingDirection.In, bindingDelegate);

            ctx.TargetType = typeof(Action);

            binder.Bind(ctx);

            Assert.Null(ctx.ObjectValue);
        }