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 SerializeTests()
        {
            var yamlStore = new YamlObjectStore();
            var obj       = new TestSimpleObject();

            obj.Name         = "Foo";
            obj.Number       = 39;
            obj.FloatNumber  = 2019.24f;
            obj.ListOfValues = new string[] { "one", "two", "three" };
            obj.Optional     = "Optional";
            obj.DiceValues   = new SilverNeedle.Dice.Cup(SilverNeedle.Dice.Die.D6());
            obj.IgnoreMe     = "ignore";

            yamlStore.Serialize(obj);

            Assert.Equal("Tests.Serialization.ObjectStoreSerializerTests+TestSimpleObject", yamlStore.GetString("serialized-type"));

            Assert.Equal("Foo", yamlStore.GetString("name"));
            Assert.Equal(39, yamlStore.GetInteger("number"));
            Assert.Equal(2019.24f, yamlStore.GetFloat("float"));
            Assert.Equal(new string[] { "one", "two", "three" }, yamlStore.GetList("list"));
            Assert.Equal("Optional", yamlStore.GetString("optional"));
            Assert.False(yamlStore.HasKey("IgnoreMe"));
        }