コード例 #1
0
        public void BuilderShouldUseTargetBindingContextForSource3()
        {
            const string sourcePath = "IntProperty";
            var targetObj = new BindingSourceEventNotifierModel();
            var builder = new BindingBuilder();
            builder.Bind(targetObj, () => model => model.ObjectProperty).To(sourcePath);

            IList<Func<IDataContext, IBindingSource>> sources = builder.GetData(BindingBuilderConstants.Sources);
            IBindingSource source = sources.Single().Invoke(builder);
            BindingParserTest.BindingSourceShouldBeValidDataContext(targetObj, source, sourcePath);
            var sourceObj = new BindingSourceModel();
            BindingServiceProvider.ContextManager.GetBindingContext(targetObj).Value = sourceObj;
            BindingParserTest.BindingSourceShouldBeValidDataContext(targetObj, source, sourcePath);
        }
コード例 #2
0
        public void BuilderShouldUseTargetBindingContextForSource2()
        {
            const string targetPath = "Text";
            const string sourcePath = "IntProperty";
            var targetObj = new object();
            var builder = new BindingBuilder();
            builder.Bind(targetObj, targetPath).To<BindingSourceModel>(() => (model, ctx) => model.IntProperty);

            IList<Func<IDataContext, IObserver>> sources = builder.GetData(BindingBuilderConstants.Sources);
            IObserver source = sources.Single().Invoke(builder);
            BindingParserTest.BindingSourceShouldBeValidDataContext(targetObj, source, sourcePath);
            var sourceObj = new BindingSourceModel();
            BindingServiceProvider.ContextManager.GetBindingContext(targetObj).Value = sourceObj;
            BindingParserTest.BindingSourceShouldBeValidDataContext(targetObj, source, sourcePath);
        }
コード例 #3
0
        public void TestSendAndReceiveWithTopicSingleCallback()
        {
            provider = services.BuildServiceProvider();
            var admin    = provider.GetRabbitAdmin();
            var exchange = new TopicExchange("topic");

            admin.DeclareExchange(exchange);
            var template = provider.GetRabbitTemplate();

            template.DefaultSendDestination = new RabbitDestination(exchange.ExchangeName, string.Empty);
            var binding = BindingBuilder.Bind(queue).To(exchange).With("*.end");

            admin.DeclareBinding(binding);
            try
            {
                template.Execute(c =>
                {
                    var consumer = CreateConsumer(template.ConnectionFactory);
                    var tag      = consumer.GetConsumerTags()[0];
                    Assert.NotNull(tag);
                    template.ConvertAndSend("foo", "message");
                    try
                    {
                        var result = GetResult(consumer, false);
                        Assert.Null(result);
                        template.ConvertAndSend("foo.end", "message");
                        result = GetResult(consumer, true);
                        Assert.Equal("message", result);
                    }
                    finally
                    {
                        consumer.Channel.BasicCancel(tag);
                    }
                });
            }
            finally
            {
                Assert.True(admin.DeleteExchange("topic"));
            }
        }
コード例 #4
0
        public void TestSendAndReceiveWithFanout()
        {
            provider = services.BuildServiceProvider();
            var admin    = provider.GetRabbitAdmin();
            var exchange = new FanoutExchange("fanout");

            admin.DeclareExchange(exchange);
            admin.DeclareBinding(BindingBuilder.Bind(queue).To(exchange));

            var template = provider.GetRabbitTemplate();

            template.DefaultSendDestination = new RabbitDestination(exchange.ExchangeName, string.Empty);
            try
            {
                template.Execute(channel =>
                {
                    var consumer = CreateConsumer(template.ConnectionFactory);
                    var tag      = consumer.GetConsumerTags()[0];
                    Assert.NotNull(tag);

                    try
                    {
                        template.ConvertAndSend("message");
                        var result = GetResult(consumer, true);
                        Assert.Equal("message", result);
                    }
                    finally
                    {
                        consumer.Stop();
                    }
                });
            }
            finally
            {
                admin.DeleteExchange("fanout");
            }
        }
コード例 #5
0
        public void TestSendAndReceiveWithTopicSingleCallback()
        {
            var admin    = new RabbitAdmin(this.connectionFactory);
            var exchange = new TopicExchange("topic");

            admin.DeclareExchange(exchange);
            this.template.Exchange = exchange.Name;

            admin.DeclareBinding(BindingBuilder.Bind(queue).To(exchange).With("*.end"));

            this.template.Execute <object>(
                delegate
            {
                var consumer = this.CreateConsumer(this.template);
                var tag      = consumer.ConsumerTag;
                Assert.IsNotNull(tag);

                this.template.ConvertAndSend("foo", "message");

                try
                {
                    var result = this.GetResult(consumer);
                    Assert.AreEqual(null, result);

                    this.template.ConvertAndSend("foo.end", "message");
                    result = this.GetResult(consumer);
                    Assert.AreEqual("message", result);
                }
                finally
                {
                    consumer.Channel.BasicCancel(tag);
                }

                return(null);
            });
        }
コード例 #6
0
        public void BuilderShouldUseGetErrorsMethod3()
        {
            var builder = new BindingBuilder();
            var sourceModel = new BindingSourceModel();
            builder.Bind(sourceModel, "empty").To(sourceModel, () => model => BindingSyntaxEx.GetErrors("1", "2", model.ObjectProperty));

            var source = builder.GetData(BindingBuilderConstants.Sources).Single().Invoke(builder);
            source.Path.Path.ShouldEqual(GetMemberPath(sourceModel, model => model.ObjectProperty));
            source.GetSource(true).ShouldEqual(sourceModel);

            var behavior = builder.GetOrAddBehaviors().OfType<NotifyDataErrorsAggregatorBehavior>().Single();
            behavior.ErrorPaths.SequenceEqual(new[] { "1", "2" }).ShouldBeTrue();
            builder.AddOrUpdate(BindingConstants.Binding, new DataBindingMock { Behaviors = new[] { behavior } });

            var expression = builder.GetData(BindingBuilderConstants.MultiExpression);
            behavior.Errors = new List<object> { "test" };
            expression(builder, new object[] { sourceModel }).ShouldEqual(behavior.Errors);
        }
コード例 #7
0
        public void BuilderShouldUseSelfExpression1()
        {
            var builder = new BindingBuilder();
            var sourceModel = new BindingSourceModel();
            builder.Bind(sourceModel, "empty").To<BindingSourceModel>(() => model => BindingSyntaxEx.Self<BindingSourceModel>());

            var source = builder.GetData(BindingBuilderConstants.Sources).Single().Invoke(builder);
            builder.GetData(BindingBuilderConstants.MultiExpression).ShouldBeNull();
            source.Path.IsEmpty.ShouldBeTrue();
            source.GetSource(true).ShouldEqual(sourceModel);
            var pathMembers = source.GetPathMembers(true);
            pathMembers.LastMember.GetValue(pathMembers.PenultimateValue, null).ShouldEqual(sourceModel);
        }
コード例 #8
0
        public void BuilderShouldUseEventArgs2()
        {
            var builder = new BindingBuilder();
            builder.Bind(new object(), "empty").To<BindingSourceModel>(() => model => BindingSyntaxEx.EventArgs<EventArgs>().GetType().Name);

            builder.Add(BindingConstants.CurrentEventArgs, EventArgs.Empty);
            var expression = builder.GetData(BindingBuilderConstants.MultiExpression);
            expression(builder, Empty.Array<object>()).ShouldEqual(EventArgs.Empty.GetType().Name);
        }
コード例 #9
0
        public void BuilderShouldUseLambdaExpression2()
        {
            var builder = new BindingBuilder();
            builder.Bind(new object(), "empty")
                .To<BindingSourceModel>(() => model => model.StringProperty.OfType<char>().Count(c => c == '1') + ((BindingSourceModel)model.ObjectProperty).IntProperty);

            var expression = builder.GetData(BindingBuilderConstants.MultiExpression);
            expression.Invoke(builder, new object[] { "1", 10 }).ShouldEqual(11);
            expression.Invoke(builder, new object[] { "", 0 }).ShouldEqual(0);

            var list = builder.GetData(BindingBuilderConstants.Sources);
            list.Count.ShouldEqual(2);
            list[0].Invoke(builder).Path.Path.ShouldEqual(GetMemberPath<BindingSourceModel>(model => model.StringProperty));
            list[1].Invoke(builder).Path.Path.ShouldEqual(GetMemberPath<BindingSourceModel>(model => ((BindingSourceModel)model.ObjectProperty).IntProperty));
        }
コード例 #10
0
 public void BuilderShouldUseTargetNullValue()
 {
     var nullValue = new object();
     var builder = new BindingBuilder();
     builder.Bind(new object(), "test").To("test").WithTargetNullValue(nullValue);
     builder.GetData(BindingBuilderConstants.TargetNullValue).ShouldEqual(nullValue);
 }
コード例 #11
0
        public void BuilderShouldUseSourceObject1()
        {
            const string targetPath = "Text";
            const string sourcePath = "IntProperty";
            var targetObj = new object();
            var sourceObj = new BindingSourceModel();
            var builder = new BindingBuilder();
            builder.Bind(targetObj, targetPath).To(sourceObj, sourcePath);

            IList<Func<IDataContext, IBindingSource>> sources = builder.GetData(BindingBuilderConstants.Sources);
            IBindingSource source = sources.Single().Invoke(builder);
            BindingParserTest.BindingSourceShouldBeValid(source, sourcePath, sourceObj);
        }
コード例 #12
0
        public void TestMultiEntities()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IConfiguration>(new ConfigurationBuilder().Build());
            serviceCollection.AddRabbitServices();
            serviceCollection.AddRabbitAdmin();
            var e1 = new Config.DirectExchange("e1", false, true);

            serviceCollection.AddRabbitExchange(e1);
            var q1 = new Config.Queue("q1", false, false, true);

            serviceCollection.AddRabbitQueue(q1);
            var binding = BindingBuilder.Bind(q1).To(e1).With("k1");

            serviceCollection.AddRabbitBinding(binding);
            var es = new Declarables(
                "es",
                new DirectExchange("e2", false, true),
                new DirectExchange("e3", false, true));

            serviceCollection.AddSingleton(es);
            var qs = new Declarables(
                "qs",
                new Config.Queue("q2", false, false, true),
                new Config.Queue("q3", false, false, true));

            serviceCollection.AddSingleton(qs);
            var bs = new Declarables(
                "qs",
                new Binding("b1", "q2", DestinationType.QUEUE, "e2", "k2", null),
                new Binding("b2", "q3", DestinationType.QUEUE, "e3", "k3", null));

            serviceCollection.AddSingleton(bs);
            var ds = new Declarables(
                "ds",
                new DirectExchange("e4", false, true),
                new Queue("q4", false, false, true),
                new Binding("b3", "q4", DestinationType.QUEUE, "e4", "k4", null));

            serviceCollection.AddSingleton(ds);
            var provider = serviceCollection.BuildServiceProvider();
            var admin    = provider.GetRabbitAdmin() as RabbitAdmin;
            var template = admin.RabbitTemplate;

            template.ConvertAndSend("e1", "k1", "foo");
            template.ConvertAndSend("e2", "k2", "bar");
            template.ConvertAndSend("e3", "k3", "baz");
            template.ConvertAndSend("e4", "k4", "qux");
            Assert.Equal("foo", template.ReceiveAndConvert <string>("q1"));
            Assert.Equal("bar", template.ReceiveAndConvert <string>("q2"));
            Assert.Equal("baz", template.ReceiveAndConvert <string>("q3"));
            Assert.Equal("qux", template.ReceiveAndConvert <string>("q4"));
            admin.DeleteQueue("q1");
            admin.DeleteQueue("q2");
            admin.DeleteQueue("q3");
            admin.DeleteQueue("q4");
            admin.DeleteExchange("e1");
            admin.DeleteExchange("e2");
            admin.DeleteExchange("e3");
            admin.DeleteExchange("e4");

            var ctx = provider.GetService <IApplicationContext>();
            var mixedDeclarables = ctx.GetService <Declarables>("ds");

            Assert.NotNull(mixedDeclarables);
            var queues = mixedDeclarables.GetDeclarablesByType <IQueue>();

            Assert.Single(queues);
            Assert.Equal("q4", queues.Single().QueueName);
            var exchanges = mixedDeclarables.GetDeclarablesByType <IExchange>();

            Assert.Single(exchanges);
            Assert.Equal("e4", exchanges.Single().ExchangeName);
            var bindings = mixedDeclarables.GetDeclarablesByType <IBinding>();

            Assert.Single(bindings);
            Assert.Equal("q4", bindings.Single().Destination);
        }
コード例 #13
0
ファイル: Container.cs プロジェクト: tharinga/uJect
 public BindingBuilder <T> Bind <T>()
 {
     return(BindingBuilder <T> .Bind <T>(this));
 }
コード例 #14
0
        public void ExchangeBinding()
        {
            var binding = BindingBuilder.Bind(new DirectExchange("q")).To(new FanoutExchange("f"));

            Assert.NotNull(binding);
        }
コード例 #15
0
        public void BuilderShouldUseResourceMethod2()
        {
            const string key = "key";
            var builder = new BindingBuilder();
            var sourceModel = new BindingSourceModel();
            var result = new BindingSourceModel { ObjectProperty = "Test" };
            BindingServiceProvider.ResourceResolver.AddMethod<string, object, BindingSourceModel>(key, (s1, s2, context) =>
            {
                s1.ShouldEqual(key);
                s2.ShouldEqual(builder);
                context.ShouldEqual(builder);
                return result;
            });
            builder.Bind(sourceModel, "empty").To<BindingSourceModel>(() => model => BindingSyntaxEx.ResourceMethod<BindingSourceModel>(key, key, builder).ObjectProperty);

            var sources = builder.GetData(BindingBuilderConstants.Sources);
            sources.Count.ShouldEqual(1);
            sources[0].Invoke(builder).Path.Path.ShouldEqual(string.Empty);
            var expression = builder.GetData(BindingBuilderConstants.MultiExpression);
            expression(builder, Empty.Array<object>()).ShouldEqual(result.ObjectProperty);
        }
コード例 #16
0
 public void BuilderShouldUseValidateBehaviors()
 {
     var builder = new BindingBuilder();
     builder.Bind(new object(), "test").To("test").Validate();
     var behaviors = builder.GetData(BindingBuilderConstants.Behaviors);
     behaviors.Count.ShouldEqual(2);
     behaviors.OfType<ValidatesOnExceptionsBehavior>().Single().ShouldNotBeNull();
     behaviors.OfType<ValidatesOnNotifyDataErrorsBehavior>().Single().ShouldNotBeNull();
 }
コード例 #17
0
        public void BuilderShouldUseBindingContextExtension4()
        {
            const string targetPath = "Text";
            const string sourcePath = "IntProperty";
            var targetObj = new object();
            var builder = new BindingBuilder();
            builder.Bind(targetObj, targetPath).To<BindingSourceModel>(() => model => BindingSyntaxEx.Self<object>().DataContext<BindingSourceModel>().IntProperty);

            IList<Func<IDataContext, IBindingSource>> sources = builder.GetData(BindingBuilderConstants.Sources);
            IBindingSource source = sources.Single().Invoke(builder);
            source.Path.Path.ShouldEqual(AttachedMemberConstants.DataContext + "." + sourcePath);
        }
コード例 #18
0
 public void BuilderShouldUseFallback1()
 {
     var fallback = new object();
     var builder = new BindingBuilder();
     builder.Bind(new object(), "test").To("test").WithFallback(fallback);
     builder.GetData(BindingBuilderConstants.Fallback).Invoke(builder).ShouldEqual(fallback);
 }
コード例 #19
0
        public void TopicBinding()
        {
            var binding = BindingBuilder.Bind(new Queue("q")).To(new TopicExchange("t")).With("r");

            Assert.NotNull(binding);
        }
コード例 #20
0
 public void BuilderShouldUseFallback2()
 {
     Func<IDataContext, object> fallback = context => null;
     var builder = new BindingBuilder();
     builder.Bind(new object(), "test").To("test").WithFallback(fallback);
     builder.GetData(BindingBuilderConstants.Fallback).ShouldEqual(fallback);
 }
コード例 #21
0
        public void BuilderShouldUseLambdaExpression1()
        {
            var builder = new BindingBuilder();
            builder.Bind(new object(), "empty")
                .To<BindingSourceModel>(() => model => model.IntProperty + 100 + model.NestedModel.IntProperty + int.Parse(model.NestedModel["1"]));

            var expression = builder.GetData(BindingBuilderConstants.MultiExpression);
            expression.Invoke(builder, new object[] { 10, 10, "10" }).ShouldEqual(130);
            expression.Invoke(builder, new object[] { -10, 10, "-100" }).ShouldEqual(0);

            var list = builder.GetData(BindingBuilderConstants.Sources);
            list.Count.ShouldEqual(3);
            list[0].Invoke(builder).Path.Path.ShouldEqual(GetMemberPath<BindingSourceModel>(model => model.IntProperty));
            list[1].Invoke(builder).Path.Path.ShouldEqual(GetMemberPath<BindingSourceModel>(model => model.NestedModel.IntProperty));
            list[2].Invoke(builder).Path.Path.ShouldEqual(GetMemberPath<BindingSourceModel>(model => model.NestedModel["1"]));
        }
コード例 #22
0
 public void BuilderShouldUseFallback3()
 {
     var builder = new BindingBuilder();
     builder.Bind(builder, "test").To("test").WithFallback(() => o => BindingSyntaxEx.Self<object>());
     builder.GetData(BindingBuilderConstants.Fallback).Invoke(builder).ShouldEqual(builder);
 }
コード例 #23
0
        public void BuilderShouldUseLambdaExpression3()
        {
            var builder = new BindingBuilder();
            builder.Bind(new object(), "empty")
                .To<BindingSourceModel>(() => model => model.StringProperty.OfType<char>().Select(s => s == null ? 10 + 4 : 3 + 10).FirstOrDefault() == 0 ? false : true || true);

            var expression = builder.GetData(BindingBuilderConstants.MultiExpression);
            expression.Invoke(builder, new object[] { "1" }).ShouldEqual("1".OfType<char>().Select(s => s == null ? 10 + 4 : 3 + 10).FirstOrDefault() == 0 ? false : true || true);
            expression.Invoke(builder, new object[] { "2" }).ShouldEqual("2".OfType<char>().Select(s => s == null ? 10 + 4 : 3 + 10).FirstOrDefault() == 0 ? false : true || true);

            var list = builder.GetData(BindingBuilderConstants.Sources);
            list.Count.ShouldEqual(1);
            list[0].Invoke(builder).Path.Path.ShouldEqual(GetMemberPath<BindingSourceModel>(model => model.StringProperty));
        }
コード例 #24
0
 public void BuilderShouldUseDelayBehaviorTarget()
 {
     var builder = new BindingBuilder();
     builder.Bind(new object(), "test").To("test").WithDelay(10, true);
     var behavior = builder.GetData(BindingBuilderConstants.Behaviors).OfType<DelayBindingBehavior>().Single();
     behavior.Delay.ShouldEqual(10);
     behavior.IsTarget.ShouldBeTrue();
 }
コード例 #25
0
        public void BuilderShouldUseEventArgs3()
        {
            var builder = new BindingBuilder();
            builder.Bind(new object(), "empty").To<BindingSourceModel>(() => model => BindingSyntaxEx.EventArgs<BindingSourceModel>().ObjectProperty);

            var sourceModel = new BindingSourceModel { ObjectProperty = "test" };
            builder.Add(BindingConstants.CurrentEventArgs, sourceModel);
            var expression = builder.GetData(BindingBuilderConstants.MultiExpression);
            expression(builder, Empty.Array<object>()).ShouldEqual(sourceModel.ObjectProperty);
        }
コード例 #26
0
 public void BuilderShouldUseConverterCulture1()
 {
     var culture = CultureInfo.InvariantCulture;
     var builder = new BindingBuilder();
     builder.Bind(new object(), "test").To("test").WithConverterCulture(culture);
     builder.GetData(BindingBuilderConstants.ConverterCulture).Invoke(builder).ShouldEqual(culture);
 }
コード例 #27
0
        public void BuilderShouldUseResource2()
        {
            const string key = "key";
            var builder = new BindingBuilder();
            var sourceModel = new BindingSourceModel { ObjectProperty = "test" };
            BindingServiceProvider.ResourceResolver.AddObject(key, sourceModel);
            builder.Bind(sourceModel, "empty").To<BindingSourceModel>(() => model => BindingSyntaxEx.Self<BindingSourceModel>().ObjectProperty);

            var source = builder.GetData(BindingBuilderConstants.Sources).Single().Invoke(builder);
            builder.GetData(BindingBuilderConstants.MultiExpression).ShouldBeNull();
            source.Path.Path.ShouldEqual(GetMemberPath(sourceModel, model => model.ObjectProperty));
            source.GetSource(true).ShouldEqual(sourceModel);
            var pathMembers = source.GetPathMembers(true);
            pathMembers.LastMember.GetValue(pathMembers.PenultimateValue, null).ShouldEqual(sourceModel.ObjectProperty);
        }
コード例 #28
0
 public void BuilderShouldUseConverterCulture2()
 {
     Func<IDataContext, CultureInfo> culture = context => null;
     var builder = new BindingBuilder();
     builder.Bind(new object(), "test").To("test").WithConverterCulture(culture);
     builder.GetData(BindingBuilderConstants.ConverterCulture).ShouldEqual(culture);
 }
コード例 #29
0
        public void BuilderShouldUseGetErrorsMethod4()
        {
            var builder = new BindingBuilder();
            var sourceModel = new BindingSourceModel();
            builder.Bind(sourceModel, "empty").To(sourceModel, () => model => BindingSyntaxEx.GetErrors("1", "2").Concat(BindingSyntaxEx.GetErrors(model.ObjectProperty)));


            var sources = builder.GetData(BindingBuilderConstants.Sources).Select(func => func(builder)).ToArray();
            sources[0].GetSource(true).ShouldEqual(sourceModel);
            sources[1].GetSource(true).ShouldEqual(sourceModel);
            if (sources[0].Path.IsEmpty)
                sources[1].Path.Path.ShouldEqual(GetMemberPath(sourceModel, model => model.ObjectProperty));
            else
                sources[0].Path.Path.ShouldEqual(GetMemberPath(sourceModel, model => model.ObjectProperty));

            var behaviors = builder.GetOrAddBehaviors().OfType<NotifyDataErrorsAggregatorBehavior>().ToArray();
            builder.AddOrUpdate(BindingConstants.Binding, new DataBindingMock { Behaviors = behaviors });
            var behavior = behaviors.Single(b => !b.ErrorPaths.IsNullOrEmpty());
            behavior.ErrorPaths.SequenceEqual(new[] { "1", "2" }).ShouldBeTrue();

            behaviors.ForEach(aggregatorBehavior => aggregatorBehavior.Errors = new[] { "1" });
            var expression = builder.GetData(BindingBuilderConstants.MultiExpression);
            var errors = (IEnumerable<object>)expression(builder, new object[] { sourceModel, sourceModel });
            errors.SequenceEqual(behaviors[0].Errors.Concat(behaviors[1].Errors)).ShouldBeTrue();
        }
コード例 #30
0
 public void BuilderShouldUseConverterCulture3()
 {
     var builder = new BindingBuilder();
     builder.Bind(CultureInfo.InvariantCulture, "test").To("test").WithConverterCulture(() => o => BindingSyntaxEx.Self<CultureInfo>());
     builder.GetData(BindingBuilderConstants.ConverterCulture).Invoke(builder).ShouldEqual(CultureInfo.InvariantCulture);
 }
コード例 #31
0
        public void BuilderShouldUseElementSource2()
        {
            const string name = "name";
            var builder = new BindingBuilder();
            var targetObj = new BindingSourceModel { ObjectProperty = "test" };
            var relativeObj = new BindingSourceModel();
            bool isInvoked = false;
            IEventListener eventListener = null;
            var memberMock = new BindingMemberInfoMock
            {
                TryObserveMember = (o, listener) =>
                {
                    eventListener = listener;
                    return null;
                }
            };

            var treeManagerMock = new VisualTreeManagerMock
            {
                FindByName = (o, s) =>
                {
                    o.ShouldEqual(targetObj);
                    s.ShouldEqual(name);
                    isInvoked = true;
                    return relativeObj;
                },
                GetRootMember = type => memberMock
            };
            BindingServiceProvider.VisualTreeManager = treeManagerMock;

            builder.Bind(targetObj, "empty").To<BindingSourceModel>(() => model => BindingSyntaxEx.Element<BindingSourceModel>(name).ObjectProperty);
            var source = builder.GetData(BindingBuilderConstants.Sources).Single().Invoke(builder);
            builder.GetData(BindingBuilderConstants.MultiExpression).ShouldBeNull();
            source.Path.Path.ShouldEqual(GetMemberPath(targetObj, model => model.ObjectProperty));
            source.GetSource(true).ShouldEqual(relativeObj);
            var pathMembers = source.GetPathMembers(true);
            pathMembers.LastMember.GetValue(pathMembers.PenultimateValue, null).ShouldEqual(relativeObj.ObjectProperty);
            isInvoked.ShouldBeTrue();

            isInvoked = false;
            eventListener.ShouldNotBeNull();
            eventListener.Handle(this, EventArgs.Empty);
            isInvoked.ShouldBeTrue();
        }
コード例 #32
0
 public void BuilderShouldUseConverterParameter1()
 {
     var parameter = new object();
     var builder = new BindingBuilder();
     builder.Bind(new object(), "test").To("test").WithConverterParameter(parameter);
     builder.GetData(BindingBuilderConstants.ConverterParameter).Invoke(builder).ShouldEqual(parameter);
 }
コード例 #33
0
        public void BuilderShouldUseBindingContextExtension1()
        {
            const string targetPath = "Text";
            var targetObj = new object();
            var builder = new BindingBuilder();
            builder.Bind(targetObj, targetPath).To<BindingSourceModel>(() => model => BindingSyntaxEx.DataContext<BindingSourceModel>());

            IList<Func<IDataContext, IBindingSource>> sources = builder.GetData(BindingBuilderConstants.Sources);
            IBindingSource source = sources.Single().Invoke(builder);
            BindingParserTest.BindingSourceShouldBeValidDataContext(targetObj, source, string.Empty);
            var sourceObj = new BindingSourceModel();
            BindingServiceProvider.ContextManager.GetBindingContext(targetObj).Value = sourceObj;
            BindingParserTest.BindingSourceShouldBeValidDataContext(targetObj, source, string.Empty);
        }
コード例 #34
0
 public void BuilderShouldUseConverterParameter2()
 {
     Func<IDataContext, object> parameter = context => null;
     var builder = new BindingBuilder();
     builder.Bind(new object(), "test").To("test").WithConverterParameter(parameter);
     builder.GetData(BindingBuilderConstants.ConverterParameter).ShouldEqual(parameter);
 }
コード例 #35
0
        public void BuilderShouldUseDynamicMember3()
        {
            const string targetPath = "Text";
            var targetObj = new object();
            var builder = new BindingBuilder();
            var src = new BindingSourceModel { ObjectProperty = new BindingSourceModel { StringProperty = "test" } };
            builder.Bind(targetObj, targetPath).To<BindingSourceModel>(() => model => model.GetObjectProperty().Member<string>("StringProperty").Member<int>("Length"));

            IList<Func<IDataContext, IBindingSource>> sources = builder.GetData(BindingBuilderConstants.Sources);
            IBindingSource source = sources.Single().Invoke(builder);
            BindingParserTest.BindingSourceShouldBeValidDataContext(targetObj, source, string.Empty);
            var sourceObj = new BindingSourceModel();
            BindingServiceProvider.ContextManager.GetBindingContext(targetObj).Value = sourceObj;
            BindingParserTest.BindingSourceShouldBeValidDataContext(targetObj, source, string.Empty);

            var data = builder.GetData(BindingBuilderConstants.MultiExpression);
            data.Invoke(builder, new[] { src }).ShouldEqual(((BindingSourceModel)src.GetObjectProperty()).StringProperty.Length);
        }
コード例 #36
0
 public void BuilderShouldUseConverterParameter3()
 {
     var builder = new BindingBuilder();
     builder.Bind(builder, "test").To("test").WithConverterParameter(() => o => BindingSyntaxEx.Self<object>());
     builder.GetData(BindingBuilderConstants.ConverterParameter).Invoke(builder).ShouldEqual(builder);
 }
コード例 #37
0
        public void BuilderShouldUseDynamicMember5()
        {
            const string targetPath = "Text";
            var targetObj = new object();
            var builder = new BindingBuilder();
            var src = new BindingSourceModel { ObjectProperty = "test" };
            builder.Bind(targetObj, targetPath).To(src, () => model => model.Member<string>("ObjectProperty").Member<int>("Length") + 0);

            IList<Func<IDataContext, IBindingSource>> sources = builder.GetData(BindingBuilderConstants.Sources);
            IBindingSource source = sources.Single().Invoke(builder);
            source.Path.Path.ShouldEqual("ObjectProperty.Length");
            source.GetSource(true).ShouldEqual(src);

            var data = builder.GetData(BindingBuilderConstants.MultiExpression);
            data.Invoke(builder, new object[] { ((string)src.ObjectProperty).Length }).ShouldEqual(((string)src.ObjectProperty).Length);
        }
コード例 #38
0
        public void DirectBindingWithQueueName()
        {
            var binding = BindingBuilder.Bind(new Queue("q")).To(new DirectExchange("d")).WithQueueName();

            Assert.NotNull(binding);
        }