Exemplo n.º 1
0
        public void CanSetValuesIntoMappingElementForSerialization()
        {
            var yamlStore = new YamlObjectStore();

            yamlStore.SetValue("name", "A Name");
            yamlStore.SetValue("number", 2383);
            yamlStore.SetValue("list-of-values", new string[] { "one", "two", "three" });
            yamlStore.SetValue("boolean", true);
            yamlStore.SetValue("float-val", 283.238f);
            var childObj = new YamlObjectStore();

            childObj.SetValue("name", "childName");
            yamlStore.SetValue("child", childObj);

            var listOfObject = new YamlObjectStore[] { new YamlObjectStore(), new YamlObjectStore() };

            listOfObject[0].SetValue("name", "Test 1");
            listOfObject[1].SetValue("name", "Test 2");
            yamlStore.SetValue("list-of-objects", listOfObject);

            Assert.Equal("A Name", yamlStore.GetString("name"));
            Assert.Equal(2383, yamlStore.GetInteger("number"));
            Assert.True(yamlStore.GetBool("boolean"));
            Assert.Equal(283.238f, yamlStore.GetFloat("float-val"));
            Assert.Equal(new string[] { "one", "two", "three" }, yamlStore.GetList("list-of-values"));
            Assert.Equal("childName", yamlStore.GetObject("child").GetString("name"));
            Assert.Equal(2, yamlStore.GetObjectList("list-of-objects").Count());
        }
Exemplo n.º 2
0
        public void CanWriteObjectsIntoYamlString()
        {
            var yamlStore = new YamlObjectStore();

            yamlStore.SetValue("name", "A Name");
            yamlStore.SetValue("number", 2383);
            yamlStore.SetValue("list-of-values", new string[] { "one", "two", "three" });
            var childObj = new YamlObjectStore();

            childObj.SetValue("name", "childName");
            yamlStore.SetValue("child", childObj);

            var listOfObject = new YamlObjectStore[] { new YamlObjectStore(), new YamlObjectStore() };

            listOfObject[0].SetValue("name", "Test 1");
            listOfObject[1].SetValue("name", "Test 2");
            yamlStore.SetValue("list-of-objects", listOfObject);

            var yamlOutput   = yamlStore.WriteToString();
            var expectedYaml = @"name: A Name
number: 2383
list-of-values:
- one
- two
- three
child:
  name: childName
list-of-objects:
- name: Test 1
- name: Test 2
...
";

            Assert.Equal(expectedYaml, yamlOutput);

            // Deserializing Results In Same object store
            var deserialize = expectedYaml.ParseYaml();

            Assert.Equal("A Name", deserialize.GetString("name"));
            Assert.Equal(2383, deserialize.GetInteger("number"));
            Assert.Equal(new string[] { "one", "two", "three" }, deserialize.GetList("list-of-values"));
            Assert.Equal("childName", deserialize.GetObject("child").GetString("name"));
        }