public void SerializationRespectsScalarStyleOverride() { var writer = new StringWriter(); var obj = new ScalarStyleExample(); var overrides = new YamlAttributeOverrides(); var style1 = new YamlMemberAttribute(); style1.ScalarStyle = ScalarStyle.DoubleQuoted; var style2 = new YamlMemberAttribute(); style2.ScalarStyle = ScalarStyle.Literal; overrides.Add(typeof(ScalarStyleExample), "LiteralString", style1); overrides.Add(typeof(ScalarStyleExample), "DoubleQuotedString", style2); var serializer = new Serializer(overrides: overrides); serializer.Serialize(writer, obj); var serialized = writer.ToString(); Dump.WriteLine(serialized); serialized.Should() .Be("LiteralString: \"Test\"\r\nDoubleQuotedString: |-\r\n Test\r\n", "the properties should be specifically styled"); }
public void SerializationRespectsScalarStyle() { var writer = new StringWriter(); var obj = new ScalarStyleExample(); Serializer.Serialize(writer, obj); var serialized = writer.ToString(); serialized.Should() .Be("LiteralString: |-\r\n Test\r\nDoubleQuotedString: \"Test\"\r\n".Replace("\r\n", Environment.NewLine), "the properties should be specifically styled"); }
public void SerializationRespectsScalarStyleOverride() { var writer = new StringWriter(); var obj = new ScalarStyleExample(); var serializer = new SerializerBuilder() .WithAttributeOverride <ScalarStyleExample>(e => e.LiteralString, new YamlMemberAttribute { ScalarStyle = ScalarStyle.DoubleQuoted }) .WithAttributeOverride <ScalarStyleExample>(e => e.DoubleQuotedString, new YamlMemberAttribute { ScalarStyle = ScalarStyle.Literal }) .Build(); serializer.Serialize(writer, obj); var serialized = writer.ToString(); serialized.Should() .Be("LiteralString: \"Test\"\r\nDoubleQuotedString: |-\r\n Test\r\n".Replace("\r\n", Environment.NewLine), "the properties should be specifically styled"); }