Exemple #1
0
        public void TopicBinderBuilder_WithAutoPropertyRegistrations_WorksAsExpected()
        {
            var topicBinderFactory = TopicBinderFactoryBuilder.CreateDefault <TestTopicParameters>().BuildFactory();

            var topicBinder = topicBinderFactory.CreateBinder("test/+BoolProperty/+CharProperty/+DecimalProperty/+DoubleProperty/+FloatProperty/+IntProperty/+UintProperty/+LongProperty/+UlongProperty/+ShortProperty/+UshortProperty/+GuidProperty/+StringProperty");

            var guid   = Guid.NewGuid();
            var target = topicBinder.Bind($"test/{true}/{'a'}/{0.25M}/{0.123d}/{0.456f}/{int.MinValue}/{uint.MaxValue}/{long.MinValue}/{ulong.MaxValue}/{short.MinValue}/{ushort.MaxValue}/{guid}/testing");

            Assert.True(target.BoolProperty);
            Assert.Equal('a', target.CharProperty);
            Assert.Equal(0.25M, target.DecimalProperty);
            Assert.Equal(0.123d, target.DoubleProperty);
            Assert.Equal(0.456f, target.FloatProperty);
            Assert.Equal(int.MinValue, target.IntProperty);
            Assert.Equal(uint.MaxValue, target.UintProperty);
            Assert.Equal(long.MinValue, target.LongProperty);
            Assert.Equal(ulong.MaxValue, target.UlongProperty);
            Assert.Equal(short.MinValue, target.ShortProperty);
            Assert.Equal(ushort.MaxValue, target.UshortProperty);
            Assert.Equal(guid, target.GuidProperty);
            Assert.Equal("testing", target.StringProperty);
        }
        private static ITopicBinder <TTopicParameters> CreateTopicBinder <TTopicParameters>(
            string topicPattern,
            Action <ITopicBinderFactoryBuilder <TTopicParameters> > topicBinderFactoryBuilderConfigurator
            )
            where TTopicParameters : class, new()
        {
            ITopicBinderFactoryBuilder <TTopicParameters> topicBinderFactoryBuilder;

            if (topicBinderFactoryBuilderConfigurator != null)
            {
                topicBinderFactoryBuilder = TopicBinderFactoryBuilder.Create <TTopicParameters>();
                topicBinderFactoryBuilderConfigurator.Invoke(topicBinderFactoryBuilder);
            }
            else
            {
                topicBinderFactoryBuilder = TopicBinderFactoryBuilder.CreateDefault <TTopicParameters>();
            }

            var topicBinderFactory = topicBinderFactoryBuilder.BuildFactory();

            var topicBinder = topicBinderFactory.CreateBinder(topicPattern);

            return(topicBinder);
        }
 public static ITopicBinderFactory <TModel> CreateDefault <TModel>(Func <TModel> targetFactory)
     where TModel : class
 {
     return(TopicBinderFactoryBuilder.CreateDefault(targetFactory).WithAutoProperties().BuildFactory());
 }
 public static ITopicBinderFactory <TModel> CreateDefault <TModel>()
     where TModel : class, new()
 {
     return(TopicBinderFactoryBuilder.CreateDefault <TModel>().WithAutoProperties().BuildFactory());
 }