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 IActionResult Character(string strategy, int level, string scores)
        {
            var build  = strategyGateway.Find(strategy);
            var roller = GatewayProvider.Find <AbilityScoreGenerator>(scores);

            build.TargetLevel        = level;
            build.AbilityScoreRoller = roller.Generator;

            var gen = GatewayProvider.Find <CharacterDesigner>(build.Designer);

            var character = new CharacterSheet(build);

            gen.ExecuteStep(character);

            ViewData["character"]     = new CharacterSheetTextView(character);
            ViewData["characterFull"] = character;
            ViewData["strategy"]      = strategy;
            ViewData["scores"]        = scores;
            ViewData["level"]         = level;

            var saveObj = new YamlObjectStore();

            character.Save(saveObj);
            ViewData["save-data"] = saveObj.WriteToString();
            return(View());
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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"));
        }
Exemplo n.º 5
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"));
        }
Exemplo n.º 6
0
        public void CanSaveAndLoadCharacterSheets()
        {
            var             bob   = CharacterTestTemplates.AverageBob();
            YamlObjectStore store = new YamlObjectStore();

            bob.Alignment = CharacterAlignment.ChaoticEvil;
            bob.Gender    = Gender.Male;
            bob.Save(store);

            var yaml   = store.WriteToString();
            var loaded = yaml.ParseYaml();

            var bob2 = CharacterSheet.Load(loaded);

            Assert.Equal(bob.Name, bob2.Name);
            Assert.Equal(CharacterAlignment.ChaoticEvil, bob2.Alignment);
            Assert.Equal(Gender.Male, bob2.Gender);
            Assert.NotNull(bob2.Offense);
        }
Exemplo n.º 7
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"));
        }