Пример #1
0
 public void PegandoIDDoJogo()
 {
     BaseDeDados dbXml = new BaseDeDados();
     int id = dbXml.GetIdJogo("Goof Troop");
     int idEsperado = 19;
     Assert.AreEqual(id, idEsperado);
 }
Пример #2
0
        public static void EditarJogo(string jogoASerAlterado)
        {
            BaseDeDados dbXml = new BaseDeDados();

            bool rodando = true;
            string novoNome = "";
            double preco = 0.0;
            string categoria = "";
            string status = "";
            int id = dbXml.nextID();
            int respostaSeQuerMudarID = NAO;

            if (jogoASerAlterado != "")
            {

                while (rodando)
                {
                    menuPrincipal.PedirNomeDoJogo();
                    novoNome = Console.ReadLine();
                    if(novoNome != "")
                    {
                        rodando = false;
                    }
                    else
                    {
                        menuPrincipal.ExceptionDigitarNome();
                    }
                }

                rodando = true;
                while (rodando)
                {

                    try
                    {
                        menuPrincipal.PedirPreco();
                        preco = Convert.ToDouble(Console.ReadLine());
                        rodando = false;
                    }
                    catch (FormatException)
                    {
                        menuPrincipal.PedirParaDigitarValorDouble();
                    }

                }

                rodando = true;

                while (rodando)
                {
                    menuPrincipal.PerguntarSeQuerMudarOId();
                    try
                    {

                        respostaSeQuerMudarID = Convert.ToInt32(Console.ReadLine());
                        if(respostaSeQuerMudarID == 1 || respostaSeQuerMudarID == 2)
                        {
                            rodando = false;
                        }
                        else
                        {
                            throw new FormatException();
                        }

                    }
                    catch (FormatException)
                    {
                        menuPrincipal.ExcepitionSeQuermudarID();
                    }

                }

                rodando = true;

                if (respostaSeQuerMudarID == SIM)
                {
                    while (rodando)
                    {
                        menuPrincipal.PedirId();
                        try
                        {
                            id = Convert.ToInt32(Console.ReadLine());
                            rodando = false;
                        }
                        catch (FormatException)
                        {
                            Console.WriteLine("Você deve digitar um numero inteiro");
                        }
                    }

                }
                else
                {
                    id = dbXml.GetIdJogo(jogoASerAlterado);
                }

                rodando = true;
                while (rodando)
                {
                    menuPrincipal.PedirCategoria();
                    categoria = Console.ReadLine();
                    if (categoria != "")
                    {
                        rodando = false;
                    }
                    else
                    {
                        menuPrincipal.ExceptionDigitarCategoria();
                    }
                }

                rodando = true;
                while (rodando)
                {
                    menuPrincipal.PedirStatus();
                    status = Console.ReadLine();

                    if (status.ToLower() == "disponivel" || status.ToLower() == "locado")
                    {
                        rodando = false;
                    }
                    else
                    {
                        menuPrincipal.ExceptionStatus();
                    }

                }

                Jogo jogo = new Jogo(novoNome, categoria, preco, id,status);

                dbXml.AlterarCamposDoJogo(jogo, jogoASerAlterado);
            }
        }