public void DuplicatePrimitiveValuesAreNotCircularObjectReference() { var dataObject = new DataObjectWithList { Strings = { "test", "test" }, Ints = { 1, 2, 1 } }; string text; using (var ms = new MemoryStream()) using (var reader = new StreamReader(ms, Encoding.UTF8)) { KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Serialize(ms, dataObject, "test"); ms.Seek(0, SeekOrigin.Begin); text = reader.ReadToEnd(); } var expected = TestDataHelper.ReadTextResource("Text.non_circular_list.vdf"); Assert.That(text, Is.EqualTo(expected)); }
public void CanDeserializeNestedLists() { DataObject dataObject; using (var rs = TestDataHelper.OpenResource("Text.list_of_lists.vdf")) { dataObject = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize <DataObject>(rs); } Assert.That(dataObject, Is.Not.Null); Assert.That(dataObject.Values, Is.Not.Null); Assert.That(dataObject.Values, Has.Count.EqualTo(2)); Assert.That(dataObject.Values[0], Is.Not.Null); Assert.That(dataObject.Values[0], Has.Count.EqualTo(2)); Assert.That(dataObject.Values[0][0], Is.EqualTo("first")); Assert.That(dataObject.Values[0][1], Is.EqualTo("second")); Assert.That(dataObject.Values[1], Is.Not.Null); Assert.That(dataObject.Values[1], Has.Count.EqualTo(2)); Assert.That(dataObject.Values[1][0], Is.EqualTo("third")); Assert.That(dataObject.Values[1][1], Is.EqualTo("fourth")); }
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)); }
public void CreatesTextDocument() { var dataObject = new[] { new Dictionary <string, string> { ["description"] = "Dota 2 is a complex game where you get sworn at\nin Russian all the time.", ["Developer"] = "Valve Software", ["Name"] = "Dota 2" }, new Dictionary <string, string> { ["description"] = "Known as \"America's #1 war-themed hat simulator\", this game lets you wear stupid items while killing people.", ["Developer"] = "Valve Software", ["Name"] = "Team Fortress 2" }, }; string text; using (var ms = new MemoryStream()) { KVSerializer.Create(KVSerializationFormat.KeyValues1Text).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)); }
public void SerializesValuesCorrectlyWithCulture() { var dataObject = new DataObject { Test = new Dictionary<string, float[]> { ["test"] = new[] { 1.1234f, 2.2345f, 3.54677f }, ["test2"] = new[] { 1.1234f, 2.2345f, 3.54677f } }, }; string text; using (var ms = new MemoryStream()) { KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Serialize(ms, dataObject, "test"); ms.Seek(0, SeekOrigin.Begin); using var reader = new StreamReader(ms); text = reader.ReadToEnd(); } var expected = TestDataHelper.ReadTextResource("Text.dictionary_with_array_values.vdf"); Assert.That(text, Is.EqualTo(expected)); }
public void SetUp() { using var stream = TestDataHelper.OpenResource("Text.duplicate_lists.vdf"); data = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize(stream); }
public void SingleLineComment(string resourceName) { using var stream = TestDataHelper.OpenResource("Text." + resourceName + ".vdf"); Assert.That(() => KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize(stream), Throws.Nothing); }
public void SetUp() { using var stream = TestDataHelper.OpenResource("Text.top_level_list_of_values.vdf"); data = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize <TEnumerable>(stream); }
public void SetUp() { data = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize <ContainerClass>(TestDataHelper.ReadTextResource("Text.duplicate_keys_object.vdf")); }
KvObject IKvTextReader.Read(string resourceName, KvSerializerOptions options) { using (var stream = TestDataHelper.OpenResource(resourceName)) return(KvSerializer.Create(KvSerializationFormat.KeyValues1Text).Deserialize(stream, options)); }
public void SetUp() { using var stream = TestDataHelper.OpenResource("Text.unquoted_document.vdf"); data = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize(stream); }
public void SetUp() { using var stream = TestDataHelper.OpenResource("Text.nested_object_graph.vdf"); data = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize <ObjectGraph>(stream); }
public void SetUp() { using var stream = TestDataHelper.OpenResource("Text.list_of_values.vdf"); data = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize <ContainerClass>(stream); }
public void SetUp() { data = KVSerializer.Deserialize <ContainerClass>(TestDataHelper.ReadTextResource("Text.duplicate_keys_object.vdf")); }
public void SetUp() { using var stream = TestDataHelper.OpenResource("Text.object_person_mixed_case.vdf"); person = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize <Person>(stream); }
Stream IIncludedFileLoader.OpenFile(string filePath) { Assert.That(filePath, Is.EqualTo("file.vdf")); return(TestDataHelper.OpenResource("Text.kv_included.vdf")); }
T IKvTextReader.Read <T>(string resourceName, KvSerializerOptions options) { var text = TestDataHelper.ReadTextResource(resourceName); return(_serializer.Deserialize <T>(text, options)); }