예제 #1
0
        public void CanRT_Herbal()
        {
            //if (!Debugger.IsAttached) Debugger.Launch();

            var herbal = new Herbal();
            var thorny = new PlantDetails
            {
                ID             = 77,
                MainName       = "Thornfriend",
                FruitAdjective = "Luminous",
                FruitKnown     = true,
                SeedAdjective  = "Knobbly",
                SeedKnown      = true,
                GrowthTime     = 234,
            };

            var boomy = new PlantDetails
            {
                ID             = 88,
                MainName       = "Boomer",
                FruitAdjective = "Singed",
                FruitKnown     = false,
                SeedAdjective  = "Dark",
                SeedKnown      = false,
                GrowthTime     = 432,
            };

            herbal.AddPlant(thorny);
            herbal.AddPlant(boomy);

            var yaml = _serializer.Serialize(herbal);

            Assert.That(yaml, Is.Not.Null);

            var newBook = _deserializer.Deserialize <IBook>(yaml);

            Assert.That(newBook, Is.TypeOf <Herbal>());
            var newHerbal = (Herbal)newBook;

            var newDetail = newHerbal.PlantByID[77];

            Assert.That(newDetail.MainName, Is.EqualTo("Thornfriend"));
        }
예제 #2
0
        public Herbal Herbal_FromYaml(IParser parser)
        {
            parser.Consume <MappingStart>();
            Herbal herbal = new Herbal();

            while (parser.TryConsume <Scalar>(out var evt) && evt.Value == "Plant")
            {
                herbal.AddPlant(ParsePlantDetails(parser));
            }

            parser.Consume <MappingEnd>();
            return(herbal);
        }