Exemplo n.º 1
0
        public void SerializationIncludesKeyFromAnonymousTypeWhenEmittingDefaults()
        {
            var writer = new StringWriter();
            var obj    = new { MyString = (string)null };

            EmitDefaultsSerializer.Serialize(writer, obj, obj.GetType());
            Dump.WriteLine(writer);

            writer.ToString().Should().Contain("MyString");
        }
Exemplo n.º 2
0
        public void SerializationIncludesKeyWhenEmittingDefaults()
        {
            var writer = new StringWriter();
            var obj    = new Example {
                MyString = null
            };

            EmitDefaultsSerializer.Serialize(writer, obj, typeof(Example));
            Dump.WriteLine(writer);

            writer.ToString().Should().Contain("MyString");
        }
Exemplo n.º 3
0
        public void SerializationOfNullInListsAreAlwaysEmittedWhenUsingEmitDefaults()
        {
            var writer = new StringWriter();
            var obj    = new[] { "foo", null, "bar" };

            EmitDefaultsSerializer.Serialize(writer, obj);
            var serialized = writer.ToString();

            Dump.WriteLine(serialized);

            Regex.Matches(serialized, "-").Count.Should().Be(3, "there should have been 3 elements");
        }
Exemplo n.º 4
0
        public void SerializationEmitsPropertyWhenUsingEmitDefaultsAndDefaultValueAttribute()
        {
            var writer = new StringWriter();
            var obj    = new DefaultsExample {
                Value = DefaultsExample.DefaultValue
            };

            EmitDefaultsSerializer.Serialize(writer, obj);
            var serialized = writer.ToString();

            Dump.WriteLine(serialized);

            serialized.Should().Contain("Value");
        }