Example #1
0
        public void CanSerializeAndDeserializeTheCharacterStrategy()
        {
            var archer = strategies.Find("archer");
            var saved  = new YamlObjectStore();

            saved.Serialize(archer);
            var loaded = new CharacterStrategy(saved);

            Assert.Equal(archer.Name, loaded.Name);
        }
Example #2
0
        public void CanSerializeOutTheEntitiesInTheContainerAndReloadThem()
        {
            var container = new ComponentContainer();

            container.Add(new CustomStatType("Foo"));
            container.Add(new CustomStatType("Bar"));
            var storage = new YamlObjectStore();

            storage.Serialize(container);
            var newContainer = new ComponentContainer();

            storage.Deserialize(newContainer);
            Assert.NotNull(newContainer.FindStat("Foo"));
            Assert.NotNull(newContainer.FindStat("Bar"));
        }
Example #3
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"));
        }