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.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 SerializesValuesCorrectly()
        {
            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));
        }
Ejemplo n.º 3
0
        public void ApiSurfaceIsWellKnown()
        {
            var expected = TestDataHelper.ReadTextResource("apisurface.txt");
            var actual   = GenerateApiSurface(typeof(KVObject).Assembly);

            Assert.That(actual, Is.EqualTo(expected), "This may indicate a breaking change.");
        }
Ejemplo n.º 4
0
        public void CanDeserializeFromRandomlyCasedKeys()
        {
            var text   = TestDataHelper.ReadTextResource("Text.random_case_object.vdf");
            var actual = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize <DataObject>(text, KVSerializerOptions.DefaultOptions);

            Assert.AreEqual("Dota 2", actual.Name);
            Assert.AreEqual("Dota 2 is a complex game where you get sworn at\nin Russian all the time.", actual.Summary);
            Assert.AreEqual("Valve Software", actual.Developer);
        }
Ejemplo n.º 5
0
        public void CanDeserializeObjectListAndPropertyName()
        {
            var text   = TestDataHelper.ReadTextResource("Text.serialization_expected.vdf");
            var actual = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize <DataObject[]>(text, KVSerializerOptions.DefaultOptions);

            Assert.AreEqual("Dota 2", actual[0].Name);
            Assert.AreEqual("Dota 2 is a complex game where you get sworn at\nin Russian all the time.", actual[0].Summary);

            Assert.AreEqual("Valve Software", actual[1].Developer);
            Assert.AreEqual("Known as \"America's #1 war-themed hat simulator\", this game lets you wear stupid items while killing people.", actual[1].Summary);
        }
        public void ThrowsInvalidDataException(string conditional)
        {
            var text = TestDataHelper.ReadTextResource("Text.invalid_conditional.vdf");

            text = text.Replace("{CONDITION}", conditional);

            using var stream = new MemoryStream(Encoding.UTF8.GetBytes(text));
            Assert.That(
                () => KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize(stream),
                Throws.Exception.InstanceOf <InvalidDataException>()
                .With.Message.EqualTo($"Invalid conditional syntax \"{conditional}\""));
        }
Ejemplo n.º 7
0
        public void CanDeserializeFromRandomlyCasedKeys()
        {
            var text    = TestDataHelper.ReadTextResource("Text.random_case_object.vdf");
            var options = new KVSerializerOptions {
                HasEscapeSequences = true
            };
            var actual = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize <DataObject>(text, options);

            Assert.That(actual.Name, Is.EqualTo("Dota 2"));
            Assert.That(actual.Summary, Is.EqualTo("Dota 2 is a complex game where you get sworn at\nin Russian all the time."));
            Assert.That(actual.Developer, Is.EqualTo("Valve Software"));
        }
Ejemplo n.º 8
0
        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 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));
        }
Ejemplo n.º 10
0
 public void SetUp()
 {
     data = KVSerializer.Deserialize <ContainerClass>(TestDataHelper.ReadTextResource("Text.duplicate_keys_object.vdf"));
 }
Ejemplo n.º 11
0
 public void SetUp()
 {
     data = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize <ContainerClass>(TestDataHelper.ReadTextResource("Text.duplicate_keys_object.vdf"));
 }
Ejemplo n.º 12
0
        T IKvTextReader.Read <T>(string resourceName, KvSerializerOptions options)
        {
            var text = TestDataHelper.ReadTextResource(resourceName);

            return(_serializer.Deserialize <T>(text, options));
        }