public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.top_level_list_of_values.vdf"))
     {
         data = KVSerializer.Deserialize <TEnumerable>(stream);
     }
 }
 public void SingleLineComment(string resourceName)
 {
     using (var stream = TestDataHelper.OpenResource("Text." + resourceName + ".vdf"))
     {
         Assert.That(() => KVSerializer.Deserialize(stream), Throws.Nothing);
     }
 }
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.unquoted_document.vdf"))
     {
         data = KVSerializer.Deserialize(stream);
     }
 }
Beispiel #4
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.duplicate_keys.vdf"))
     {
         data = KVSerializer.Deserialize <Dictionary <string, string> >(stream);
     }
 }
Beispiel #5
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.list_of_values.vdf"))
     {
         data = KVSerializer.Deserialize <SerializedType>(stream);
     }
 }
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.escaped_backslash_not_special.vdf"))
     {
         data = KVSerializer.Deserialize(stream);
     }
 }
 KVObject IKVTextReader.Read(string resourceName, KVSerializerOptions options)
 {
     using (var stream = TestDataHelper.OpenResource(resourceName))
     {
         return(KVSerializer.Deserialize(stream, options));
     }
 }
Beispiel #8
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.type_guessing.vdf"))
     {
         data = KVSerializer.Deserialize(stream);
     }
 }
Beispiel #9
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.nested_object_graph.vdf"))
     {
         data = KVSerializer.Deserialize <ObjectGraph>(stream);
     }
 }
Beispiel #10
0
 public void DeserializeWithNullStream()
 {
     Assert.That(
         () => KVSerializer.Deserialize(stream: null),
         Throws.Exception.TypeOf <ArgumentNullException>()
         .With.Property(nameof(ArgumentNullException.ParamName)).EqualTo("stream"));
 }
Beispiel #11
0
 public static KVObject Deserialize(this KVSerializer serializer, byte[] data, KVSerializerOptions options = null)
 {
     using (var ms = new MemoryStream(data))
     {
         return(serializer.Deserialize(ms, options));
     }
 }
Beispiel #12
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.escaped_quotation_marks.vdf"))
     {
         data = KVSerializer.Deserialize(stream);
     }
 }
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.object_person_mixed_case.vdf"))
     {
         person = KVSerializer.Deserialize <Person>(stream);
     }
 }
Beispiel #14
0
        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);
        }
Beispiel #15
0
 public void InvalidTextSyntaxThrowsKeyValueException(string resourceName)
 {
     using (var stream = TestDataHelper.OpenResource("Text." + resourceName + ".vdf"))
     {
         Assert.That(
             () => KVSerializer.Deserialize(stream),
             Throws.Exception.TypeOf <KeyValueException>());
     }
 }
Beispiel #16
0
 public void ThrowsInvalidOperationException()
 {
     using (var stream = TestDataHelper.OpenResource("Text.list_of_values_skipping_keys.vdf"))
     {
         Assert.That(
             () => KVSerializer.Deserialize <SerializedType>(stream),
             Throws.Exception.InstanceOf <InvalidOperationException>()
             .With.Message.EqualTo($"Cannot deserialize a non-array value to type \"{typeof(TEnumerable).Namespace}.{typeof(TEnumerable).Name}\"."));
     }
 }
        public void SetUp()
        {
            var options = new KVSerializerOptions {
                HasEscapeSequences = true
            };

            using (var stream = TestDataHelper.OpenResource("Text.escaped_whitespace.vdf"))
            {
                data = KVSerializer.Deserialize(stream, options);
            }
        }
        public void ReadsRawValueWhenNotHasEscapeSequences()
        {
            KVObject data;

            using (var stream = TestDataHelper.OpenResource("Text.escaped_garbage.vdf"))
            {
                data = KVSerializer.Deserialize(stream);
            }

            Assert.That((string)data["key"], Is.EqualTo(@"\7"));
        }
        public static TObject Deserialize <TObject>(this KVSerializer serializer, string text, KVSerializerOptions options = null)
        {
            using var ms     = new MemoryStream();
            using var writer = new StreamWriter(ms);
            writer.Write(text);
            writer.Flush();

            ms.Seek(0, SeekOrigin.Begin);

            return(serializer.Deserialize <TObject>(ms, options));
        }
        public void SetUp()
        {
            var options = new KVSerializerOptions {
                FileLoader = new StubIncludedFileLoader()
            };

            using (var stream = TestDataHelper.OpenResource("Text.kv_with_base.vdf"))
            {
                data = KVSerializer.Deserialize(stream, options);
            }
        }
        static KVObject ParseResource(string name, string[] conditions)
        {
            KVObject data;

            using (var stream = TestDataHelper.OpenResource(name))
            {
                data = KVSerializer.Deserialize(stream, new KVSerializerOptions {
                    Conditions = conditions
                });
            }

            return(data);
        }
Beispiel #22
0
        public void CanReadTeamFortressCleanupCommands()
        {
            KVObject data;

            using (var stream = TestDataHelper.OpenResource($"Text.steam_440.vdf"))
            {
                data = KVSerializer.Deserialize(stream);
            }

            var cleanupcmds = (string)data["config"]["cleanupcmds"];
            var expected    = @"if not exist hl2.exe goto EOF;ren ""..\..\common\Team Fortress 2"" TF2_bak;del /q /s bin\*;cd tf;del /q /s *.cache media\*.mov;mkdir download;cd download;move ..\maps .\;move ..\materials .\;move ..\models .\;move ..\particles .\;move ..\resource .\;move ..\sound .\;move ..\scripts .\;cd resource;del game.ico tf.ttf tf2.ttf tf2build.ttf tf2professor.ttf tf2secondary.ttf tfd.ttf;cd ..\sound\ui;del gamestartup*.mp3 tv_tune*.mp3 holiday\gamestartup_*.mp3;:EOF";

            Assert.That(cleanupcmds, Is.EqualTo(expected));
        }
Beispiel #23
0
        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.Deserialize(stream),
                    Throws.Exception.InstanceOf <InvalidDataException>()
                    .With.Message.EqualTo($"Invalid conditional syntax \"{conditional}\""));
            }
        }
        public void ThrowsExceptionWhenHasEscapeSequences()
        {
            var options = new KVSerializerOptions {
                HasEscapeSequences = true
            };

            using (var stream = TestDataHelper.OpenResource("Text.escaped_garbage.vdf"))
            {
                Assert.That(
                    () => KVSerializer.Deserialize(stream, options),
                    Throws.Exception.TypeOf <KeyValueException>()
                    .With.InnerException.TypeOf <InvalidDataException>()
                    .With.Message.EqualTo(@"Unknown escaped character '\7'."));
            }
        }
        KVObject IKVTextReader.Read(string resourceName, KVSerializerOptions options)
        {
            var text = TestDataHelper.ReadTextResource(resourceName);

            return(KVSerializer.Deserialize(text, options));
        }
Beispiel #26
0
 public void SetUp()
 {
     data = KVSerializer.Deserialize <ContainerClass>(TestDataHelper.ReadTextResource("Text.duplicate_keys_object.vdf"));
 }
 public static TObject Deserialize <TObject>(this KVSerializer serializer, byte[] data, KVSerializerOptions options = null)
 {
     using var ms = new MemoryStream(data);
     return(serializer.Deserialize <TObject>(ms, options));
 }