string PerformNewLineTest(string value, bool hasEscapeSequences) { KVObject convertedKv; var kv = new KVObject("newLineTestCase", value); var options = new KVSerializerOptions { HasEscapeSequences = hasEscapeSequences }; string text; using (var ms = new MemoryStream()) { KVSerializer.Serialize(ms, kv, options); ms.Seek(0, SeekOrigin.Begin); text = Encoding.ASCII.GetString(ms.GetBuffer(), 0, (int)ms.Length); convertedKv = KVSerializer.Deserialize(ms, options); } Assert.That((string)convertedKv.Value, Is.EqualTo(value)); return(text); }
public void ThrowsException() { var dataObject1 = new DataObject { Name = "First" }; var dataObject2 = new DataObject { Name = "Second", Other = dataObject1 }; dataObject1.Other = dataObject2; Assert.That(dataObject1.Other, Is.SameAs(dataObject2), "Sanity check"); Assert.That(dataObject2.Other, Is.SameAs(dataObject1), "Sanity check"); using (var ms = new MemoryStream()) { Assert.That( () => KVSerializer.Serialize(ms, dataObject1, "test data"), Throws.Exception.InstanceOf <KeyValueException>() .With.Message.EqualTo("Serialization failed - circular object reference detected.")); } }
public void CreatesTextDocument() { var kv = new KVObject( "test data", new[] { new KVObject( "0", new[] { new KVObject("description", "Dota 2 is a complex game where you get sworn at\nin Russian all the time."), new KVObject("developer", "Valve Software"), new KVObject("name", "Dota 2") }), new KVObject( "1", new[] { new KVObject("description", "Known as \"America's #1 war-themed hat simulator\", this game lets you wear stupid items while killing people."), new KVObject("developer", "Valve Software"), new KVObject("name", "Team Fortress 2") }) }); string text; using (var ms = new MemoryStream()) { KVSerializer.Serialize(ms, kv); ms.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(ms)) { text = reader.ReadToEnd(); } } var expected = TestDataHelper.ReadTextResource("Text.serialization_expected.vdf"); Assert.That(text, Is.EqualTo(expected)); }
public void CreatesTextDocument() { var dataObject = new[] { new DataObject { Developer = "Valve Software", Name = "Dota 2", Summary = "Dota 2 is a complex game where you get sworn at\nin Russian all the time.", ExtraData = "Hidden Stuff Here" }, new DataObject { Developer = "Valve Software", Name = "Team Fortress 2", Summary = "Known as \"America's #1 war-themed hat simulator\", this game lets you wear stupid items while killing people.", ExtraData = "More Secrets" }, }; string text; using (var ms = new MemoryStream()) { KVSerializer.Serialize(ms, dataObject, "test data"); ms.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(ms)) { text = reader.ReadToEnd(); } } var expected = TestDataHelper.ReadTextResource("Text.serialization_expected.vdf"); Assert.That(text, Is.EqualTo(expected)); }