コード例 #1
0
        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());
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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());
            }
        }