public void PropertyValidationTest()
        {
            var myProp = new FudgeContextProperty("EvenProp", x => (int)x % 2 == 0);        // Only accept even integers

            var context = new FudgeContext();

            context.SetProperty(myProp, 12);

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                context.SetProperty(myProp, 17);
            });
        }
        public void FieldNameConventionsWithContextProperty()
        {
            var context = new FudgeContext();           // So we don't mess with other unit tests
            var obj1    = new FieldConventionClass {
                MyName = "Bobby", myAge = 6
            };
            FudgeMsg        msg;
            FudgeSerializer serializer;

            // Default is identity
            serializer = new FudgeSerializer(context);
            Assert.Equal(FudgeFieldNameConvention.Identity, serializer.TypeMap.FieldNameConvention);
            msg = serializer.SerializeToMsg(obj1);
            Assert.Equal("Bobby", msg.GetString("MyName"));
            Assert.Equal(6, msg.GetInt("myAge"));
            Assert.Equal(obj1, serializer.Deserialize(msg));

            context.SetProperty(ContextProperties.FieldNameConventionProperty, FudgeFieldNameConvention.AllLowerCase);
            serializer = new FudgeSerializer(context);
            msg        = serializer.SerializeToMsg(obj1);
            Assert.Equal("Bobby", msg.GetString("myname"));
            Assert.Equal(6, msg.GetInt("myage"));
            Assert.Equal(obj1, serializer.Deserialize(msg));

            context.SetProperty(ContextProperties.FieldNameConventionProperty, FudgeFieldNameConvention.AllUpperCase);
            serializer = new FudgeSerializer(context);
            msg        = serializer.SerializeToMsg(obj1);
            Assert.Equal("Bobby", msg.GetString("MYNAME"));
            Assert.Equal(6, msg.GetInt("MYAGE"));
            Assert.Equal(obj1, serializer.Deserialize(msg));

            context.SetProperty(ContextProperties.FieldNameConventionProperty, FudgeFieldNameConvention.CamelCase);
            serializer = new FudgeSerializer(context);
            msg        = serializer.SerializeToMsg(obj1);
            Assert.Equal("Bobby", msg.GetString("myName"));
            Assert.Equal(6, msg.GetInt("myAge"));
            Assert.Equal(obj1, serializer.Deserialize(msg));

            context.SetProperty(ContextProperties.FieldNameConventionProperty, FudgeFieldNameConvention.PascalCase);
            serializer = new FudgeSerializer(context);
            msg        = serializer.SerializeToMsg(obj1);
            Assert.Equal("Bobby", msg.GetString("MyName"));
            Assert.Equal(6, msg.GetInt("MyAge"));
            Assert.Equal(obj1, serializer.Deserialize(msg));
        }
        public void PropertiesCreatedAfterContext()
        {
            var context = new FudgeContext();

            var newProp = new FudgeContextProperty("NewProp");

            Assert.Null(context.GetProperty(newProp));
            context.SetProperty(newProp, "test");
            Assert.Equal("test", context.GetProperty(newProp));
        }
        public void PicksUpPropertiesFromContext()
        {
            var context = new FudgeContext();

            var map1 = new SerializationTypeMap(context);
            Assert.True(map1.AllowTypeDiscovery);

            context.SetProperty(ContextProperties.AllowTypeDiscoveryProperty, false);
            var map2 = new SerializationTypeMap(context);
            Assert.False(map2.AllowTypeDiscovery);
        }
        public void PicksUpPropertiesFromContext()
        {
            var newContext = new FudgeContext();

            var writer = new FudgeXmlStreamWriter(newContext, XmlWriter.Create(new MemoryStream()), "msg");

            Assert.True(writer.AutoFlushOnMessageEnd);

            newContext.SetProperty(FudgeXmlStreamWriter.AutoFlushOnMessageEndProperty, false);
            writer = new FudgeXmlStreamWriter(newContext, XmlWriter.Create(new MemoryStream()), "msg");
            Assert.False(writer.AutoFlushOnMessageEnd);
        }
        public void PicksUpPropertiesFromContext()
        {
            var context = new FudgeContext();

            var map1 = new SerializationTypeMap(context);

            Assert.True(map1.AllowTypeDiscovery);

            context.SetProperty(ContextProperties.AllowTypeDiscoveryProperty, false);
            var map2 = new SerializationTypeMap(context);

            Assert.False(map2.AllowTypeDiscovery);
        }
        public void BasicPropertyTest()
        {
            var myProp  = new FudgeContextProperty("SomeProp");
            var context = new FudgeContext();

            Assert.Null(context.GetProperty(myProp));
            Assert.Equal(12, context.GetProperty(myProp, 12));

            context.SetProperty(myProp, 17);

            Assert.Equal(17, context.GetProperty(myProp));
            Assert.Equal(17, context.GetProperty(myProp, 12));
        }
        public void PicksUpPropertiesFromContext()
        {
            var newContext = new FudgeContext();

            var writer = new FudgeXmlStreamWriter(newContext, XmlWriter.Create(new MemoryStream()), "msg");
            Assert.True(writer.AutoFlushOnMessageEnd);

            newContext.SetProperty(FudgeXmlStreamWriter.AutoFlushOnMessageEndProperty, false);
            writer = new FudgeXmlStreamWriter(newContext, XmlWriter.Create(new MemoryStream()), "msg");
            Assert.False(writer.AutoFlushOnMessageEnd);
        }
        public void PropertyValidationTest()
        {
            var myProp = new FudgeContextProperty("EvenProp", x => (int)x % 2 == 0);        // Only accept even integers

            var context = new FudgeContext();
            context.SetProperty(myProp, 12);

            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                context.SetProperty(myProp, 17);
            });
        }
        public void PropertiesCreatedAfterContext()
        {
            var context = new FudgeContext();

            var newProp = new FudgeContextProperty("NewProp");

            Assert.Null(context.GetProperty(newProp));
            context.SetProperty(newProp, "test");
            Assert.Equal("test", context.GetProperty(newProp));
        }
        public void BasicPropertyTest()
        {
            var myProp = new FudgeContextProperty("SomeProp");
            var context = new FudgeContext();

            Assert.Null(context.GetProperty(myProp));
            Assert.Equal(12, context.GetProperty(myProp, 12));

            context.SetProperty(myProp, 17);

            Assert.Equal(17, context.GetProperty(myProp));
            Assert.Equal(17, context.GetProperty(myProp, 12));
        }
        public void FieldNameConventionsWithContextProperty()
        {
            var context = new FudgeContext();           // So we don't mess with other unit tests
            var obj1 = new FieldConventionClass {MyName = "Bobby", myAge = 6};
            FudgeMsg msg;
            FudgeSerializer serializer;

            // Default is identity
            serializer = new FudgeSerializer(context);
            Assert.Equal(FudgeFieldNameConvention.Identity, serializer.TypeMap.FieldNameConvention);
            msg = serializer.SerializeToMsg(obj1);
            Assert.Equal("Bobby", msg.GetString("MyName"));
            Assert.Equal(6, msg.GetInt("myAge"));
            Assert.Equal(obj1, serializer.Deserialize(msg));

            context.SetProperty(ContextProperties.FieldNameConventionProperty, FudgeFieldNameConvention.AllLowerCase);
            serializer = new FudgeSerializer(context);
            msg = serializer.SerializeToMsg(obj1);
            Assert.Equal("Bobby", msg.GetString("myname"));
            Assert.Equal(6, msg.GetInt("myage"));
            Assert.Equal(obj1, serializer.Deserialize(msg));

            context.SetProperty(ContextProperties.FieldNameConventionProperty, FudgeFieldNameConvention.AllUpperCase);
            serializer = new FudgeSerializer(context);
            msg = serializer.SerializeToMsg(obj1);
            Assert.Equal("Bobby", msg.GetString("MYNAME"));
            Assert.Equal(6, msg.GetInt("MYAGE"));
            Assert.Equal(obj1, serializer.Deserialize(msg));

            context.SetProperty(ContextProperties.FieldNameConventionProperty, FudgeFieldNameConvention.CamelCase);
            serializer = new FudgeSerializer(context);
            msg = serializer.SerializeToMsg(obj1);
            Assert.Equal("Bobby", msg.GetString("myName"));
            Assert.Equal(6, msg.GetInt("myAge"));
            Assert.Equal(obj1, serializer.Deserialize(msg));

            context.SetProperty(ContextProperties.FieldNameConventionProperty, FudgeFieldNameConvention.PascalCase);
            serializer = new FudgeSerializer(context);
            msg = serializer.SerializeToMsg(obj1);
            Assert.Equal("Bobby", msg.GetString("MyName"));
            Assert.Equal(6, msg.GetInt("MyAge"));
            Assert.Equal(obj1, serializer.Deserialize(msg));
        }