Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Assignment 5 - Pokemon Edition");

            PokemonReader reader  = new PokemonReader();
            Pokedex       pokedex = reader.Load("pokemon151.xml");

            // List out all the pokemons loaded
            foreach (Pokemon pokemon in pokedex.Pokemons)
            {
                Console.WriteLine(pokemon.Name);
            }

            // TODO: Add a pokemon bag with 2 bulbsaur, 1 charlizard, 1 mew and 1 dragonite
            // and save it out and load it back and list it out.

            // TODO: Add item reader and print out all the items

            // TODO: hook up item data to display with the inventory

            var source = new Inventory()
            {
                ItemToQuantity =
                    new Dictionary <object, object> {
                    { "Poke ball", 10 }, { "Potion", 10 }
                }
            };

            // TODO: move this into a inventory with a serialize and deserialize function.
            string inventoryFile = "inventory.xml";

            using (var writer = XmlWriter.Create(inventoryFile))
                (new XmlSerializer(typeof(Inventory))).Serialize(writer, source);

            using (var rd = new StreamReader(inventoryFile))
            {
                var serializer = new XmlSerializer(typeof(Inventory));
                try
                {
                    Inventory inventory = serializer.Deserialize(rd) as Inventory;
                    if (inventory != null)
                    {
                        foreach (var item in inventory.ItemToQuantity)
                        {
                            Console.WriteLine("Item: {0} Quantity: {1}", item.Key, item.Value);
                        }
                    }
                }

                catch (Exception ex)
                {
                    Console.WriteLine("Cannot load {0} due to the following {1}",
                                      inventoryFile, ex.Message);
                }
            }


            Console.ReadKey();
        }
Exemplo n.º 2
0
        public void Init()
        {
            string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pokemon151.xml");

            PokemonReader reader = new PokemonReader();

            mPokedex = reader.Load(filePath);
        }
Exemplo n.º 3
0
        public void TestMethod7()
        {
            Pokedex       poke          = new Pokedex();
            PokemonReader pokemonReader = new PokemonReader();

            poke = pokemonReader.LoadPokedex("pokemon151.xml");

            Assert.IsNotNull(poke.GetPokemonByIndex(6));
        }
Exemplo n.º 4
0
        public void TestMethod8()
        {
            Pokedex       poke          = new Pokedex();
            PokemonReader pokemonReader = new PokemonReader();

            poke = pokemonReader.LoadPokedex("pokemon151.xml");

            Assert.AreEqual(4178, poke.GetHighestMaxCPPokemon().MaxCP);
        }
Exemplo n.º 5
0
        public void TestMethod9()
        {
            Pokedex       poke          = new Pokedex();
            PokemonReader pokemonReader = new PokemonReader();

            poke = pokemonReader.LoadPokedex("pokemon151.xml");

            Assert.AreEqual(487, poke.GetHighestHPPokemon().HP);
        }
Exemplo n.º 6
0
        public void TestMethod10()
        {
            Pokedex       poke          = new Pokedex();
            PokemonReader pokemonReader = new PokemonReader();

            poke = pokemonReader.LoadPokedex("pokemon151.xml");

            Assert.AreEqual(300, poke.GetHighestAttackPokemon().Attack);
        }
Exemplo n.º 7
0
        public void TestMethod11()
        {
            Pokedex       poke          = new Pokedex();
            PokemonReader pokemonReader = new PokemonReader();

            poke = pokemonReader.LoadPokedex("pokemon151.xml");

            Assert.AreEqual(256, poke.GetHighestDefensePokemon().Defense);
        }
Exemplo n.º 8
0
        public void TestMethod5()
        {
            Pokedex       poke          = new Pokedex();
            PokemonReader pokemonReader = new PokemonReader();

            poke = pokemonReader.LoadPokedex("pokemon151.xml");

            Assert.IsNotNull(poke.GetPokemonsOfType("Fire"));
        }
Exemplo n.º 9
0
        public void TestMethod6()
        {
            Pokedex       poke          = new Pokedex();
            PokemonReader pokemonReader = new PokemonReader();

            poke = pokemonReader.LoadPokedex("pokemon151.xml");

            Assert.IsNotNull(poke.GetPokemonByName("Bulbasaur"));
        }
Exemplo n.º 10
0
        public void GetHighestAttackPokemonTest()
        {
            Pokedex       pokedex = new Pokedex();
            PokemonReader reader  = new PokemonReader();

            pokedex = reader.Load("pokemon151.xml");
            Pokemon pokemon = pokedex.GetHighestAttackPokemon();

            Assert.AreEqual(pokemon.Name, "Mewtwo");
        }
Exemplo n.º 11
0
        public void GetPokemonsofTypeTest()
        {
            Pokedex       pokedex = new Pokedex();
            PokemonReader reader  = new PokemonReader();

            pokedex = reader.Load("pokemon151.xml");
            System.Collections.Generic.List <Pokemon> testlist = new System.Collections.Generic.List <Pokemon>();
            testlist = pokedex.GetPokemonsOfType("Grass");

            Assert.AreEqual(testlist.Count, 14);
        }
Exemplo n.º 12
0
        public void PokemonReader_ShouldLogDeserializationOfPokemon()
        {
            // Arrange
            _dateTimeWrapperMock.Setup(x => x.GetNow()).Returns(new DateTime(2010, 1, 1));
            var reader = new PokemonReader(_dateTimeWrapperMock.Object, _loggerMock.Object);

            // Act
            reader.ReadPokemon(_json);

            // Assert
            _loggerMock.Verify(x => x.Information($"Pokemon deserialized. Id: {_expectedPokemon.Id}, Name: {_expectedPokemon.Name}, Type: {_expectedPokemon.Type}, Timestamp: {_expectedPokemon.Timestamp}"));
        }
Exemplo n.º 13
0
        public void PokemonReader_ShouldDeserializePokemon()
        {
            // Arrange
            _dateTimeWrapperMock.Setup(x => x.GetNow()).Returns(new DateTime(2010, 1, 1));
            var reader = new PokemonReader(_dateTimeWrapperMock.Object, _loggerMock.Object);

            // Act
            var result = reader.ReadPokemon(_json);

            // Assert
            result.Should().BeEquivalentTo(_expectedPokemon);
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Assignment 5 - Pokemon Edition");

            PokemonReader reader  = new PokemonReader();
            PokemonSaver  saver   = new PokemonSaver();
            Pokedex       pokedex = reader.Load_Pokedex("pokemon151.xml");

            // List out all the pokemons loaded
            foreach (Pokemon pokemon in pokedex.Pokemons)
            {
                Console.WriteLine(pokemon.Name);
            }


            PokemonBag theBag = new PokemonBag();

            theBag.AddPokemon(pokedex, "bulbasaur");
            theBag.AddPokemon(pokedex, "bulbasaur");
            theBag.AddPokemon(pokedex, "charizard");
            theBag.AddPokemon(pokedex, "mew");
            theBag.AddPokemon(pokedex, "dragonite");


            string fileName = "myPokemonBag.xml";

            // Serializting and saving pokemonBeg object with exception handling
            try
            {
                saver.Save_PokeBag(theBag, fileName);
            }
            catch (Exception e)
            {
                Console.WriteLine(string.Format("\nSaving {0} failed, due to error: {1}\n", fileName, e.Message));
            }

            // Deserializting and loading pokemonBag object with exception handling
            PokemonBag newBag = new PokemonBag();

            try
            {
                newBag = reader.Load_PokemonBag(fileName);
            }
            catch (Exception e)
            {
                Console.WriteLine(string.Format("Loading {0} failed, due to error: {1}", fileName, e.Message));
            }

            //TODO::add a beg pretty print function in pokemonbag class. ----DONE
            newBag.PrettyPrint(pokedex);

            Console.ReadKey();
        }
Exemplo n.º 15
0
        public void EntityReader_ShouldLogValidationResult()
        {
            // Arrange
            _dateTimeWrapperMock.Setup(x => x.GetNow()).Returns(new DateTime(2010, 1, 1));
            _databaseMock.Setup(x => x.IsValidationEnabled()).Returns(true);
            var reader = new PokemonReader(_dateTimeWrapperMock.Object, _loggerMock.Object, _databaseMock.Object);

            // Act
            reader.ReadPokemon(_json);

            // Assert
            _loggerMock.Verify(x => x.Information($"Validation result: {true}"));
        }
Exemplo n.º 16
0
        public void GetPokemonByIndexTest()
        {
            int           index   = 1;
            Pokedex       pokedex = new Pokedex();
            PokemonReader reader  = new PokemonReader();

            pokedex = reader.Load("pokemon151.xml");
            for (int i = 0; i < pokedex.Pokemons.Count; i++)
            {
                if (pokedex.Pokemons[i].Index == index)
                {
                    Assert.AreEqual(pokedex.Pokemons[i].Index, 1);
                }
            }
        }
Exemplo n.º 17
0
        public void GetPokemonBynameTest()
        {
            string        name    = "Bulbasaur";
            Pokedex       pokedex = new Pokedex();
            PokemonReader reader  = new PokemonReader();

            pokedex = reader.Load("pokemon151.xml");
            for (int i = 0; i < pokedex.Pokemons.Count; i++)
            {
                if (pokedex.Pokemons[i].Name == name)
                {
                    Assert.AreEqual(pokedex.Pokemons[i].Name, "Bulbasaur");
                }
            }
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Assignment 5 - Pokemon Edition");

            PokemonReader reader  = new PokemonReader();
            Pokedex       pokedex = reader.Load("pokemon151.xml");

            // List out all the pokemons loaded
            foreach (Pokemon pokemon in pokedex.Pokemons)
            {
                Console.WriteLine(pokemon.Name);
            }

            // TODO: Add a pokemon bag with 2 bulbsaur, 1 charlizard, 1 mew and 1 dragonite
            // and save it out and load it back and list it out.

            Console.ReadKey();
        }
Exemplo n.º 19
0
        public void PokemonReader_ShouldDeserializePokemon()
        {
            // Arrange
            var expectedPokemon = new Pokemon
            {
                Id   = 1,
                Name = "Charmander",
                Type = PokemonType.Fire
            };
            var reader = new PokemonReader();

            // Act
            var result = reader.ReadPokemon(_json);

            // Assert
            Assert.AreEqual(expectedPokemon.Id, result.Id);
            Assert.AreEqual(expectedPokemon.Name, result.Name);
            Assert.AreEqual(expectedPokemon.Type, result.Type);
        }
Exemplo n.º 20
0
        public async Task <ImportingStatus> ImportPokemon(string filePath)
        {
            try
            {
                Console.WriteLine($"Received pokemon to import: {filePath}...");

                var fileContent = File.ReadAllText(filePath);
                var reader      = new PokemonReader();
                var pokemon     = reader.ReadPokemon(fileContent);

                var database = new PokemonStore();
                await database.SavePokemon(pokemon);

                Console.WriteLine($"Pokemon saved. Id: {pokemon.Id}, Name: {pokemon.Name}, Type: {pokemon.Type}, Timestamp: {pokemon.Timestamp}");

                return(ImportingStatus.Success);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error! " + e.Message);
                return(ImportingStatus.Error);
            }
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Assignment 5 - Pokemon Edition");

            PokemonReader reader  = new PokemonReader();
            Pokedex       pokedex = reader.Load("pokemon151.xml");

            Console.WriteLine("Displaying List of Pokemon:");
            // List out all the pokemons loaded
            foreach (Pokemon pokemon in pokedex.Pokemons)
            {
                Console.WriteLine(pokemon.Name);
            }

            ItemReader itemReader    = new ItemReader();
            ItemsData  itemsDatafile = itemReader.Load("itemData.xml");

            Console.WriteLine("\nDisplaying List of Items from file");

            foreach (Item item in itemsDatafile.Items)
            {
                item.Print();
            }

            int iLevelLock = 10;

            Console.WriteLine("Displaying items unlocked at level {0}", iLevelLock);
            List <Item> UnlockedItems = itemsDatafile.UnlockedItemsAtLevel(iLevelLock);

            foreach (Item item in UnlockedItems)
            {
                item.Print();
            }

            string itemname = "Super Potion";

            Console.WriteLine("Searching for item {0}", itemname);
            itemsDatafile.FindItem(itemname).Print();

            string InventoryFile = "inventory.xml";

            Console.WriteLine("-----Creating Inventory-----");
            var source = new Inventory()
            {
                ItemToQuantity =
                    new Dictionary <object, object> {
                    { "Poke ball", 10 }, { "Potion", 10 },
                    { "Premier ball", 20 }, { "Revive", 3 }, { "Great ball", 8 },
                    { "Hyper Potion", 2 }
                }
            };

            source.Serialize(source);
            source.Deserialize(InventoryFile);

            string entry = "Poke ball";

            Console.WriteLine("\nSearching for {0} in Inventory", entry);
            source.FindItem("Poke ball");

            Console.WriteLine("\nDisplaying items in inventory whose Level Req < {0}", iLevelLock);
            source.UnlockItems(iLevelLock, itemsDatafile);

            // TODO: Add a pokemon bag with 2 bulbsaur, 1 charlizard, 1 mew and 1 dragonite
            // and save it out and load it back and list it out.
            Console.WriteLine("\nSaving more pokemons inside bag\n");
            PokemonBag bag = new PokemonBag();

            bag.Add(pokedex.GetPokemonByName("Bulbasaur").Index);
            bag.Add(pokedex.GetPokemonByName("Bulbasaur").Index);
            bag.Add(pokedex.GetPokemonByName("Charizard").Index);
            bag.Add(pokedex.GetPokemonByName("Mew").Index);
            bag.Add(pokedex.GetPokemonByName("Dragonite").Index);

            const string filepath = "PokeBag.xml";

            bag.Save(filepath);
            PokemonBag loadResult = bag.Load(filepath);

            Console.WriteLine("\nLoad all pokemons from bag..\n");
            loadResult.Pokemons.ForEach(item => Console.WriteLine(item));

            Console.ReadKey();
        }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            ItemsData data     = new ItemsData();
            Item      testitem = new Item();

            Console.WriteLine("Welcome to Assignment 5 - Pokemon Edition");

            PokemonReader reader  = new PokemonReader();
            Pokedex       pokedex = reader.Load("pokemon151.xml");

            // List out all the pokemons loaded
            foreach (Pokemon pokemon in pokedex.Pokemons)
            {
                Console.WriteLine(pokemon.Name);
            }
            // TODO: load the pokemon151 xml
            XmlDocument loadPokemon151 = new XmlDocument();

            loadPokemon151.Load("pokemon151.xml");

            // TODO: Add item reader and print out all the items
            using (XmlReader itemReader = XmlReader.Create("itemData.xml"))
            {
                while (itemReader.Read())
                {
                    if (itemReader.IsStartElement())
                    {
                        switch (itemReader.Name.ToString())
                        {
                        case "Name":
                            Console.WriteLine("Item Name : " + itemReader.ReadElementContentAsString());


                            break;

                        case "UnlockRequirement":
                            Console.WriteLine("UnlockRequirement : " + itemReader.ReadElementContentAsFloat());

                            break;

                        case "Description":
                            Console.WriteLine("Description : " + itemReader.ReadElementContentAsString());

                            break;

                        case "Effect":
                            Console.WriteLine("Effect : " + itemReader.ReadElementContentAsString());

                            break;
                        }
                        data.Items.Add(testitem);
                    }
                    Console.WriteLine("");
                }
            }



            // TODO: hook up item data to display with the inventory

            var source = new Inventory()
            {
                ItemToQuantity = new Dictionary <object, object> {
                    { "Poke ball", 10 }, { "Potion", 10 }
                }
            };


            // TODO: move this into a inventory with a serialize and deserialize function.

            source.Serialize(source);
            source.Deserialize("inventory.xml");



            PokemonBag mybag = new PokemonBag();

            mybag.Pokemons.Add(1);
            mybag.Pokemons.Add(1);
            mybag.Pokemons.Add(6);
            mybag.Pokemons.Add(151);
            mybag.Pokemons.Add(149);


            FileStream      fs = new FileStream(@"serializePokemon.dat", FileMode.Create);//path of file
            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(fs, mybag);
            fs.Close();

            fs = new FileStream(@"serializePokemon.dat", FileMode.Open);
            BinaryFormatter nbf    = new BinaryFormatter();
            PokemonBag      mylist = nbf.Deserialize(fs) as PokemonBag;

            Console.WriteLine("\nList of the the pokemons caught");
            foreach (int i in mylist.Pokemons)
            {
                Console.WriteLine(pokedex.GetPokemonByIndex(i).Name);
            }
            Console.WriteLine(pokedex.GetHighestHPPokemon().Name);
            Console.WriteLine(pokedex.GetHighestAttackPokemon().Name);
            Console.WriteLine(pokedex.GetHighestDefensePokemon().Name);
            Console.WriteLine(pokedex.GetHighestMaxCPPokemon().Name);
            // TODO: Add a pokemon bag with 2 bulbsaur, 1 charlizard, 1 mew and 1 dragonite
            // and save it out and load it back and list it out.

            Console.ReadKey();
        }
 public PokedexController(IConfiguration configuration, PokemonReader pokemonReader)
 {
     this.configuration = configuration;
     this.pokemonReader = pokemonReader;
 }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Assignment 5 - Pokemon Edition");

            PokemonReader reader  = new PokemonReader();
            Pokedex       pokedex = reader.LoadPokedex("pokemon151.xml");

            // List out all the pokemons loaded
            foreach (Pokemon pokemon in pokedex.Pokemons)
            {
                //Console.WriteLine(pokemon.Name);
            }

            // TODO: Add a pokemon bag with 2 bulbsaur, 1 charizard, 1 mew and 1 dragonite
            // and save it out and load it back and list it out.

            PokemonBag pokemonbag = new PokemonBag();

            pokemonbag.Pokemons.Add(1);
            pokemonbag.Pokemons.Add(1);
            pokemonbag.Pokemons.Add(6);
            pokemonbag.Pokemons.Add(151);
            pokemonbag.Pokemons.Add(149);

            Pokedex newPokedex = new Pokedex();

            using (PokemonUtil pokemonUtil = new PokemonUtil("PokemonBag"))
            {
                pokemonUtil.Init();
                pokemonUtil.AddPokemonsToProcess(ref pokemonbag, ref pokedex);
                newPokedex.Pokemons.AddRange(pokemonUtil.PokemonsToProcess);
                pokemonUtil.Write();
                pokemonUtil.Print();
                pokemonUtil.Clear();
            }

            PokemonWriter pokemonWriter = new PokemonWriter();

            pokemonWriter.SavePokemons("PokemonBag.xml", ref newPokedex);

            Pokedex dex = reader.LoadPokedex("PokemonBag.xml");

            // TODO: load the pokemon151 xml
            XElement pokemon151XML = XElement.Load(@"pokemon151.xml");
            // Console.WriteLine(pokemon151XML);

            // TODO: Add item reader and print out all the items
            Item          itemdata   = new Item();
            List <Item>   itemlist   = new List <Item>();
            XmlTextReader readerItem = new XmlTextReader("itemData.xml");

            while (readerItem.Read())
            {
                if (readerItem.NodeType == XmlNodeType.Element && readerItem.Name == "Name")
                {
                    string name = readerItem.ReadElementContentAsString();
                    itemdata.Name = name;
                    // Console.WriteLine("Name: " + itemdata.Name);
                }

                if (readerItem.NodeType == XmlNodeType.Element && readerItem.Name == "UnlockRequirement")
                {
                    string UnlockRequirement = readerItem.ReadElementContentAsString();
                    itemdata.UnlockRequirement = Int32.Parse(UnlockRequirement);
                    // Console.WriteLine("UnlockRequirement: " + itemdata.UnlockRequirement);
                }

                if (readerItem.NodeType == XmlNodeType.Element && readerItem.Name == "Description")
                {
                    string Description = readerItem.ReadElementContentAsString();
                    itemdata.Description = Description;
                    // Console.WriteLine("Description: " + itemdata.Description);
                }

                if (readerItem.NodeType == XmlNodeType.Element && readerItem.Name == "Effect")
                {
                    string Effect = readerItem.ReadElementContentAsString();
                    itemdata.Effect = Effect;
                    //Console.WriteLine("Effect: " + itemdata.Effect);

                    itemlist.Add(itemdata);
                    itemdata = new Item();
                }
            }

            foreach (Item i in itemlist)
            {
                i.Print();
            }

            // TODO: hook up item data to display with the inventory

            Inventory source = new Inventory()
            {
                ItemToQuantity =
                    new Dictionary <object, object> {
                    { "Poke ball", 10 }, { "Potion", 10 }
                }
            };


            // TODO: move this into a inventory with a serialize and deserialize function.

            source.Serialize(source, "inventory.xml");
            source.Deserialize("inventory.xml");



            Console.ReadKey();
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Assignment 5 - Pokemon Edition");

            PokemonReader reader  = new PokemonReader();
            Pokedex       pokedex = reader.Load("pokemon151.xml");

            // List out all the pokemons loaded
            foreach (Pokemon pokemon in pokedex.Pokemons)
            {
                Console.WriteLine(pokemon.Name);
            }


            // TODO: Add a pokemon bag with 2 bulbsaur, 1 charlizard, 1 mew and 1 dragonite
            // and save it out and load it back and list it out.

            // TODO: Add item reader and print out all the items
            ItemReader itemReader = new ItemReader();
            ItemsData  itemsData  = itemReader.Load("itemData.xml");

            foreach (var item in itemsData.Items)
            {
                Console.WriteLine(item.Name);
            }

            // TODO: hook up item data to display with the inventory

            var source = new Inventory()
            {
                ItemToQuantity =
                    new Dictionary <object, object> {
                    { "Poke ball", 10 }, { "Potion", 10 }
                }
            };

            // TODO: move this into a inventory with a serialize and deserialize function.
            string inventoryFile = "inventory.xml";

            source.Load(inventoryFile, itemsData);
            source.Save("invent.xml");


            Console.WriteLine("=========Bag=========");

            PokemonBag pokebag = new PokemonBag();

            pokebag.Pokemons.Add(pokedex.GetPokemonByName("Bulbasaur"));
            pokebag.Pokemons.Add(pokedex.GetPokemonByName("Bulbasaur"));
            pokebag.Pokemons.Add(pokedex.GetPokemonByName("Charizard"));
            pokebag.Pokemons.Add(pokedex.GetPokemonByName("Mew"));
            pokebag.Pokemons.Add(pokedex.GetPokemonByName("Dragonite"));

            Pokedex bagdex = new Pokedex();

            bagdex.Pokemons = pokebag.Pokemons;
            reader.Save("bagdex", bagdex);
            Pokedex loadDex = reader.Load("bagdex.xml");

            foreach (Pokemon pokemon in loadDex.Pokemons)
            {
                Console.WriteLine(pokemon.Name);
            }

            Console.ReadKey();
        }