public void Delete()
        {
            using (var unitOfWork = new GameUnitOfWork())
            {
                var service = new GameDomainService(unitOfWork);

                var game = new Game()
                {
                    Name = "Delete",
                    Price = 100,
                    Category = GameCategory.RPG
                };

                service.Insert(game);
                unitOfWork.Commit();

                //Deve haver 1 registro (adicionado acima)
                Assert.IsTrue(service.FindByName("Delet").Count > 0);

                service.Delete(game);
                unitOfWork.Commit();

                //Nao deve haver registros
                Assert.IsTrue(service.FindByName("Delet").Count == 0);
            }
        }
        public void Add(Game game)
        {
            this.Load();
            game.Id = this.Identity();

            XElement srcTree = new XElement("jogo",
                new XElement("nome", game.Name),
                new XElement("preco", game.Price),
                new XElement("categoria", game.Category),
                new XElement("disponivel", "SIM"));

            srcTree.SetAttributeValue("id", game.Id);

            this.xmlGames.Add(srcTree);
        }
        public void Insert()
        {
            using (var unitOfWork = new GameUnitOfWork())
            {
                var service = new GameDomainService(unitOfWork);

                var game = new Game()
                {
                    Name = "Test",
                    Price = 100,
                    Category = GameCategory.RPG
                };

                service.Insert(game);
                unitOfWork.Commit();

                //Deve haver ao menos 1 game que o nome inicie com Tes
                Assert.IsTrue(service.FindByName("Tes").Count > 0);
            }
        }
 public void Remove(Game game)
 {
     this.Load();
     XElement element = this.xmlGames.Elements("jogo").ToList()
                                     .Find(t => Convert.ToInt32(t.Attribute("id").Value) == game.Id);
     element.Remove();
 }
        public IList<Game> Get()
        {
            this.Load();
            var list = new List<Game>();

            foreach (XElement jogo in this.xmlGames.Elements("jogo"))
            {
                string id = jogo.Attribute("id").Value;
                string name = jogo.Element("nome").Value;
                string price = jogo.Element("preco").Value;
                string category = jogo.Element("categoria").Value;
                string available = jogo.Element("disponivel").Value;

                var game = new Game()
                {
                    Id = Convert.ToInt32(id),
                    Name = name,
                    Price = Convert.ToDouble(price),
                    Category = (GameCategory)Enum.Parse(typeof(GameCategory), category),
                    Available = available == "SIM"
                };

                list.Add(game);
            }

            return list;
        }
        public void Update(Game game)
        {
            this.Load();
            XElement element = this.xmlGames.Elements("jogo").ToList()
                                            .Find(t => (int)t.Attribute("id") == game.Id);

            element.Element("nome").Value = game.Name;
            element.Element("preco").Value = game.Price.ToString();
            element.Element("categoria").Value = game.Category.ToString();
            element.Element("disponivel").Value = game.Available ? "SIM" : "NÂO";
        }