public void Deve_Incluir_Novo_LogErro_Quando_Salvar() { var fakeContext = new FakeContext("SalvarLogErro"); var fakeLogErro = fakeContext.GetFakeData <LogErro>().FirstOrDefault(); fakeLogErro.Id = 0; using (var context = new ProjetoPraticoContext(fakeContext.FakeOptions)) { var service = new LogErroService(context); var actual = service.Salvar(fakeLogErro); Assert.NotEqual(0, actual.Id); } }
public void Deve_Carregar_LogErro_Certo_Quando_Pesquisar_Por_Id(int id) { var fakeContext = new FakeContext("BuscaLogErroPorId"); fakeContext.FillWith <LogErro>(); using (var context = new ProjetoPraticoContext(fakeContext.FakeOptions)) { var expected = fakeContext.GetFakeData <LogErro>().Find(x => x.Id == id); var service = new LogErroService(context); var actual = service.FindById(id); Assert.Equal(expected, actual, new LogErroComparer()); } }
public void Deve_Arquivar_Log(List <int> listaId) { if (listaId == null) { throw new ArgumentNullException(); } var fakeContext = new FakeContext("ArquivarLog"); fakeContext.FillWith <LogErro>(); using (var context = new ProjetoPraticoContext(fakeContext.FakeOptions)) { var service = new LogErroService(context); List <LogErro> before = new List <LogErro>(); foreach (int id in listaId) { var log = service.FindById(id); context.Entry(log).State = EntityState.Detached; before.Add(log); } foreach (int id in listaId) { service.Arquivar(id); } List <LogErro> after = new List <LogErro>(); foreach (int id in listaId) { var obj = service.FindById(id); if (obj != null) { after.Add(obj); } } Assert.NotEqual(before, after, new LogErroComparer()); } }
public void Deve_Excluir_Log(List <int> listaId) { if (listaId == null) { throw new ArgumentNullException(); } var fakeContext = new FakeContext("RemoverLog"); fakeContext.FillWith <LogErro>(); using (var context = new ProjetoPraticoContext(fakeContext.FakeOptions)) { var service = new LogErroService(context); List <LogErro> before = new List <LogErro>(); foreach (int id in listaId) { before.Add(service.FindById(id)); } foreach (int id in listaId) { service.Remover(id); } List <LogErro> after = new List <LogErro>(); foreach (int id in listaId) { var obj = service.FindById(id); if (obj != null) { after.Add(obj); } } Assert.NotEqual(before.Count, after.Count); } }
public void Deve_Retornar_Log_Por_Arquivados() { var fakeContext = new FakeContext("LocalizarPorArquivados"); fakeContext.FillWith <LogErro>(); using (var context = new ProjetoPraticoContext(fakeContext.FakeOptions)) { var dados = fakeContext.GetFakeData <LogErro>(); var expected = dados.Where(x => x.Arquivado == true) .ToList(); var service = new LogErroService(context); var actual = service.LocalizarArquivados(); Assert.NotEmpty(actual); Assert.NotEmpty(expected); Assert.Equal(expected, actual, new LogErroComparer()); } }
public void Deve_Retornar_Log_Por_Nivel_e_Ambiente(string nivel, string ambiente) { var fakeContext = new FakeContext("LocalizarPorNivelAmbiente"); fakeContext.FillWith <LogErro>(); using (var context = new ProjetoPraticoContext(fakeContext.FakeOptions)) { var dados = fakeContext.GetFakeData <LogErro>(); var expected = dados.Where(x => x.Nivel == nivel) .Where(x => x.Ambiente == ambiente) .Where(x => x.Arquivado == false) .ToList(); var service = new LogErroService(context); var actual = service.LocalizarPorNivelAmbiente(nivel, ambiente); Assert.NotEmpty(actual); Assert.NotEmpty(expected); Assert.Equal(expected, actual, new LogErroComparer()); } }