Example #1
0
        public ActionResult <IActionResult> Delete(int id)
        {
            Envelope envelope = new Envelope();

            try
            {
                // apagar
                BusContato bContato = new BusContato();
                bContato.Apagar(id);

                // retorno da API
                envelope.Infos.Add("Sucesso ao APAGAR contato");
            }
            catch (Exception e)
            {
                envelope.AddExcecao("Erro ao APAGAR contato", e);
            }
            return(Ok(envelope));
        }
Example #2
0
        public void CriarUmApagarOmesmo()
        {
            Contato oContatoMOQ = new Contato
            {
                Nome           = "Teste Criar Apagar " + DateTime.Now.Ticks.ToString(),
                Sexo           = "X",
                DataNascimento = DateTime.Now.AddYears(-6)
            };

            BusContato bContato = new BusContato();

            bContato.Salvar(oContatoMOQ);

            // recuperar o id do novo registro no banco.
            int novoId = oContatoMOQ.IdContato;

            // apagar
            bContato = new BusContato();
            bContato.Apagar(novoId);

            /*
             * usando TRY CATCH para falhar ou passar no teste:
             */

            try
            {
                // tentar carregar
                Contato contato = bContato.Carregar(novoId);
                if (contato != null)
                {
                    Assert.Fail("Objeto não foi apagado");
                }
            }
            catch (InvalidOperationException)
            {
                Assert.IsTrue(true);
            }
        }