public void AoAcessarACadaDeAcessoADadosParaConsultarSeDeterminadoEmailJaEstaCadastrado_DeveRetornarFalsoCasoNaoExitaOEmail()
        {
            var user = new User
            {
                Name = "Daniel Silva Moreira",
                Email = "*****@*****.**",
                Phone = "3133333333",
                CellPhone = "3188888888",
                Address = "Rua Teste",
                Number = 123,
                District = "Centro",
                City = "Belo Horizonte",
                ZipCode = 30246130,
                State = "MG",
                Password = "******",
                UserType = "user"
            };

            const string email = "*****@*****.**";

            var auxContext = new LivrariaTDDContext();

            auxContext.Users.Add(user);

            auxContext.SaveChanges();

            var mockContext = new LivrariaTDDContext();

            _repository = new AccountRepository(mockContext);

            var result = _repository.CheckEmail(email);

            Assert.False(result);
        }
        public void AoAcessarACamadaDeAcessoADadosParaSalvarUmLivro_DeveSalvarOLivroERetornarVerdadeiro()
        {
            var novoLivro = new Product
            {
                Name = "Torre Negra",
                Author = "Stephen King",
                Publishing = "Universal",
                Year = 1995,
                Category = Categories.LiteraturaEstrangeira,
                Stock = 5,
                Price = 150.0M,
                Photo = ""
            };

            var auxContext = new LivrariaTDDContext();

            var mockContext = new LivrariaTDDContext();

            _repository = new ProdutoRepository(mockContext);

            var countAntes = auxContext.Products.Count();

            var result = _repository.SalvarLivro(novoLivro);

            var countDepois = auxContext.Products.Count();

            Assert.NotNull(result);
            Assert.AreEqual(0,countAntes);
            Assert.AreEqual(1,countDepois);
        }
        public void AoAcessarACamadaDeAcessoADadosParaExcluirUmLivroNaoExistente_OMetodoDeveRetornarFalso()
        {
            var usuario = new User
            {
                District = "Centro",
                CellPhone = "3188888888",
                ZipCode = 30625130,
                City = "Belo Horizonte",
                State = "MG",
                Name = "Jô Soares",
                Email = "*****@*****.**",
                Number = 456,
                Address = "Afonso Pena",
                Password = "******",
                Phone = "313333333",
                UserType = "Cliente"
            };

            using (var livrariaContext = new LivrariaTDDContext())
            {
                usuario = livrariaContext.Users.Add(usuario);
                livrariaContext.SaveChanges();
            }

            var pedido = new Order
            {
                User = usuario,
                PaymentType = null,
                Products = new List<Product> { null, null },
                OrderValue = 0M,
                FreightValue = 10.00M,
                TotalValue = 0M + 10.00M
            };

            const int userId = -34;
            var listaIdProducts = new List<int> { -15, -10 };
            const int formaPagamentoId = -5;

            using (var auxContext = new LivrariaTDDContext())
            {
                var countAntes = auxContext.Orders.Count();
                Assert.AreEqual(0, countAntes);
            }

            using (var livrariaContext = new LivrariaTDDContext())
            {
                _repository = new PedidoRepository(livrariaContext);

                var result = _repository.SalvarPedido(pedido, userId, listaIdProducts, formaPagamentoId);

                Assert.False(result);
            }

            using (var auxContext = new LivrariaTDDContext())
            {
                var countDepois = auxContext.Orders.Count();
                Assert.AreEqual(0, countDepois);
            }
        }
        public void AoAcessarACamadaDeAcessoADadosDaPaginaDeListagemDaPaginaDeListagemEOcorreUmaExcecao_AExcecaoDeveSerLancadaParaCamadaSuperior()
        {
            var mockContext = new LivrariaTDDContext("server=./SQLServerStringErrada");

            //mockContext.Setup(x => x.Produtos).Throws<Exception>();

            _repository = new ProdutoRepository(mockContext);

            Assert.Throws<System.Data.DataException>(() => _repository.RecuperarTodosProdutos());
        }
        public void AoAcessarACamadaDeAcessoADadosDaPaginaDeVisualizacaoDeProdutoEOcorrerUmaExcecao_AExcecaoDeveSerLancadaParaCamadaSuperior()
        {
            const int id = 1;

            var mockContext = new LivrariaTDDContext("server=./SQLServerStringErrada");

            //mockContext.Setup(x => x.Produtos).Throws<Exception>();

            _repository = new ProdutoRepository(mockContext);

            Assert.Throws<System.Data.DataException>(() => _repository.RecuperarInformacoesDoLivro(id));
        }
        public void AoAcessarACamadaDeAcessoADadosParaExcluirUmLivroNaoExistente_OMetodoDeveRetornarFalso()
        {
            const int idFalso = -10;

            var novoLivro = new Product
            {
                Name = "Torre Negra",
                Author = "Stephen King",
                Publishing = "Universal",
                Year = 1995,
                Category = Categories.LiteraturaEstrangeira,
                Stock = 5,
                Price = 150.0M,
                Photo = "",
                Status = ProductStatus.Active
            };

            using (var livrariaContext = new LivrariaTDDContext())
            {
                novoLivro = livrariaContext.Products.Add(novoLivro);
                livrariaContext.SaveChanges();
            }

            using (var auxContext = new LivrariaTDDContext())
            {
                var firstOrDefault = auxContext.Products.FirstOrDefault(x => x.ProductId == novoLivro.ProductId);
                if (firstOrDefault != null)
                {
                    var statusAntes = firstOrDefault.Status;
                    Assert.AreEqual(ProductStatus.Active, statusAntes);
                }
            }

            using (var livrariaContext = new LivrariaTDDContext())
            {
                _repository = new ProdutoRepository(livrariaContext);

                var result = _repository.ExcluirLivro(idFalso);

                Assert.False(result);
            }

            using (var auxContext = new LivrariaTDDContext())
            {
                var firstOrDefault = auxContext.Products.FirstOrDefault(x => x.ProductId == novoLivro.ProductId);
                if (firstOrDefault != null)
                {
                    var statusDepois = firstOrDefault.Status;
                    Assert.AreEqual(ProductStatus.Active, statusDepois);
                }
            }
        }
        public void ACadamadaDeAcessoADadosDeveRecuperarUmUsuarioAtravesDoEmail_OUsuarioDeveSerRetornadoParaCamadaSuperior()
        {
            var mockContext = new LivrariaTDDContext();

            _repository = new AccountRepository(mockContext);

            const string email = "*****@*****.**";

            var result = _repository.RecuperarUsuario(email);

            Assert.IsInstanceOf<User>(result);
            StringAssert.AreEqualIgnoringCase(result.Email, email);
        }
        public void ACadamadaDeAcessoADadosDeveRecuperarUmUsuarioAtravesDoEmailQueNãoExista_ORetornoDeveSerNulo()
        {
            var mockContext = new LivrariaTDDContext();

            //mockContext.Setup(x => x.Usuarios).Returns(_listaDeUsuarios);

            _repository = new AccountRepository(mockContext);

            const string email = "não existe";

            var result = _repository.RecuperarUsuario(email);

            Assert.IsNull(result);
        }
        public void AoAcessarACamadaDeNegociosDaPaginaDeVisualizacaoDeLivro_OProdutoDeveSerRetornado()
        {
            var mockContext = new LivrariaTDDContext();

            //mockContext.Setup(x => x.Produtos).Returns(_listaDeProdutos);

            _repository = new ProdutoRepository(mockContext);

            var result = _repository.RecuperarInformacoesDoLivro(_livroFiccao.ProductId);

            Assert.IsNotNull(result);
            Assert.IsInstanceOf<Product>(result);
            Assert.AreEqual(result.ProductId, _livroFiccao.ProductId);
        }
        public void AoAcessarACamdadaDeAcessoADadosParaAlterarUmProduto_OProdutoDeveSerSalvoEUmResultadoBooleYearDeveSerRetornado()
        {
            var novosValores = new Product
            {
                ProductId = 3,
                Name = "Cinderela",
                Author = "Popular",
                Publishing = "Abril",
                Year = 2005,
                Category = Categories.InfantoJuvenis,
                Stock = 10,
                Price = 10.0M,
                Photo = ""
            };

            var mockContext = new LivrariaTDDContext();

            novosValores = mockContext.Products.Add(novosValores);
            mockContext.SaveChanges();

            //mockContext.Setup(x => x.Produtos).Returns(_listaDeProdutos);

            _repository = new ProdutoRepository(mockContext);

            var aux = _repository.RecuperarInformacoesDoLivro(novosValores.ProductId);

            var livroAntigo = new Product
                {
                    ProductId = aux.ProductId,
                    Name = aux.Name,
                    Author = aux.Author,
                    Publishing = aux.Publishing,
                    Year = aux.Year,
                    Category = aux.Category,
                    Stock = aux.Stock,
                    Price = aux.Price,
                    Photo = aux.Photo
                };

            novosValores.Name = "Name novo";

            var result = _repository.AlterarLivro(novosValores);

            var livroNovo = _repository.RecuperarInformacoesDoLivro(novosValores.ProductId);

            Assert.True(result);
            Assert.AreEqual(livroAntigo.ProductId, livroNovo.ProductId);
            StringAssert.AreNotEqualIgnoringCase(livroAntigo.Name, livroNovo.Name);
        }
        public void AoAcessarACamadaDeNegociosDaPaginaDeListagem_ComoFuncionarioDaLoja_OsProdutosDevemVirDaCamadaDeAcessoADados()
        {
            var mockContext = new LivrariaTDDContext();

            //mockContext.Setup(x => x.Produtos).Returns(_listaDeProdutos);

            _repository = new ProdutoRepository(mockContext);

            var result = _repository.RecuperarTodosProdutos();

            Assert.IsNotNull(result);
            Assert.IsInstanceOf<List<Product>>(result);
            CollectionAssert.AllItemsAreNotNull(result);
            CollectionAssert.IsNotEmpty(result);
        }
        public void AoAcessarACamadaDeNegociosDaPaginaDeListagem_ComoFuncionarioDaLoja_OsProdutosDevemVirSomenteLivrosComStatus1Ativo()
        {
            using (var livrariaContext = new LivrariaTDDContext())
            {
                var novoLivro = new Product
                {
                    Name = "Torre Negra",
                    Author = "Stephen King",
                    Publishing = "Universal",
                    Year = 1995,
                    Category = Categories.LiteraturaEstrangeira,
                    Stock = 5,
                    Price = 150.0M,
                    Photo = "",
                    Status = ProductStatus.Active
                };

                var novoLivro2 = new Product
                    {
                        Name = "Torre Negra Volume 2",
                        Author = "Stephen King",
                        Publishing = "Universal",
                        Year = 1998,
                        Category = Categories.LiteraturaEstrangeira,
                        Stock = 8,
                        Price = 170.0M,
                        Photo = "",
                        Status = ProductStatus.Inative
                    };

                livrariaContext.Products.Add(novoLivro);
                livrariaContext.Products.Add(novoLivro2);
                livrariaContext.SaveChanges();
            }

            var mockContext = new LivrariaTDDContext();

            _repository = new ProdutoRepository(mockContext);

            var result = _repository.GetActiveProducts();

            Assert.IsNotNull(result);
            Assert.AreEqual(3, mockContext.Products.Count());
            Assert.AreEqual(2, result.Count);
            Assert.IsInstanceOf<List<Product>>(result);
            CollectionAssert.AllItemsAreNotNull(result);
            CollectionAssert.IsNotEmpty(result);
        }
        public void SetUp()
        {
            using (var db = new LivrariaTDDContext())
            {
                foreach (var item in db.Products.ToList())
                {
                    db.Products.Remove(item);
                }

                db.SaveChanges();
            }
        }
        public void AoAcessarACamadaDeAcessoADadosParaSalvarUmLivro_OLivroDeveSerCadastradoComStatus1Ativo()
        {
            var novoLivro = new Product
            {
                Name = "Torre Negra",
                Author = "Stephen King",
                Publishing = "Universal",
                Year = 1995,
                Category = Categories.LiteraturaEstrangeira,
                Stock = 5,
                Price = 150.0M,
                Photo = ""
            };

            var mockContext = new LivrariaTDDContext();

            _repository = new ProdutoRepository(mockContext);

            _repository.SalvarLivro(novoLivro);

            var result = mockContext.Products.FirstOrDefault().Status;

            Assert.AreEqual(ProductStatus.Active, result);
        }
        public void SetUp()
        {
            using (var db = new LivrariaTDDContext())
            {
                foreach (var item in db.Products.ToList())
                {
                    db.Products.Remove(item);
                }

                db.SaveChanges();

                var produto = new Product
                {
                    Name = "TDD desenvolvimento guiado por testes",
                    Author = "Kent Beck",
                    Publishing = "Bookman",
                    Year = 2010,
                    Category = Categories.LiteraturaEstrangeira,
                    Stock = 0,
                    Price = 50.0M,
                    Photo = "",
                    Status = ProductStatus.Active
                };

                db.Products.Add(produto);
                db.SaveChanges();
            }
        }
        public void SetUp()
        {
            using (var db = new LivrariaTDDContext())
            {
                foreach (var item in db.Orders.ToList())
                {
                    db.Orders.Remove(item);
                }

                foreach (var item in db.Users.ToList())
                {
                    db.Users.Remove(item);
                }

                foreach (var item in db.Products.ToList())
                {
                    db.Products.Remove(item);
                }

                foreach (var item in db.PaymentTypes.ToList())
                {
                    db.PaymentTypes.Remove(item);
                }
                var cliente = new User
                    {
                        Name = "Cliente da Loja",
                        Email = "*****@*****.**",
                        Phone = "3133333333",
                        CellPhone = "3188888888",
                        Address = "Rua Teste",
                        Number = 123,
                        District = "Centro",
                        City = "Belo Horizonte",
                        ZipCode = 30246130,
                        State = "MG",
                        Password = "******", //123456
                        UserType = "user"
                    };
                var funcionario = new User
                    {
                        Name = "Funcionario da Loja",
                        Email = "*****@*****.**",
                        Phone = "3133333333",
                        CellPhone = "3188888888",
                        Address = "Rua Teste",
                        District = "Centro",
                        Number = 123,
                        City = "Belo Horizonte",
                        ZipCode = 30246130,
                        State = "MG",
                        Password = "******", //654321
                        UserType = "admin"
                    };

                db.Users.Add(cliente);
                db.Users.Add(funcionario);
                db.SaveChanges();
            }
        }
        public void AoAcessarACamadaDeAcessoADadosParaSalvarUmUsuarioValido_DeveSalvarOUsuarioERetornarVerdadeiro()
        {
            var user = new User
            {
                Name = "Daniel Silva Moreira",
                Email = "*****@*****.**",
                Phone = "3133333333",
                CellPhone = "3188888888",
                Address = "Rua Teste",
                Number = 123,
                District = "Centro",
                City = "Belo Horizonte",
                ZipCode = 30246130,
                State = "MG",
                Password = "******",
                UserType = "user"
            };

            var auxContext = new LivrariaTDDContext();

            var mockContext = new LivrariaTDDContext();

            _repository = new AccountRepository(mockContext);

            var countAntes = auxContext.Users.Count();

            var result = _repository.SaveUser(user);

            var countDepois = auxContext.Users.Count();

            Assert.True(result);
            Assert.AreEqual(2, countAntes);
            Assert.AreEqual(3, countDepois);
        }
        public void AoAcessarACamadaDeAcessoADadosParaSalvarUmUsuarioInvalido_NaoDeveSalvarOUsuarioERetonarFalso()
        {
            var user = new User
            {
                Name = "",
                Email = "",
                Phone = "",
                CellPhone = "",
                Address = "",
                Number = 0,
                District = "",
                City = "",
                ZipCode = 0,
                State = "",
                Password = "",
                UserType = ""
            };

            var auxContext = new LivrariaTDDContext();

            var mockContext = new LivrariaTDDContext();

            _repository = new AccountRepository(mockContext);

            var countAntes = auxContext.Users.Count();

            var result = _repository.SaveUser(user);

            var countDepois = auxContext.Users.Count();

            Assert.False(result);
            Assert.AreEqual(2, countAntes);
            Assert.AreEqual(2, countDepois);
        }
 public AccountRepository(LivrariaTDDContext livrariaTDDContext)
 {
     _context = livrariaTDDContext;
 }
        public void SetUp()
        {
            _livroTDD = new Product
            {
                ProductId = 1,
                Name = "TDD desenvolvimento guiado por testes",
                Author = "Kent Beck",
                Publishing = "Bookman",
                Year = 2010,
                Category = Categories.LiteraturaEstrangeira,
                Stock = 0,
                Price = 50.0M,
                Photo = ""
            };

            _livroRomance = new Product
            {
                ProductId = 2,
                Name = "O Amor",
                Author = "Escritora Romance",
                Publishing = "Bookman",
                Year = 2007,
                Category = Categories.LiteraturaBrasileira,
                Stock = 0,
                Price = 30.0M,
                Photo = ""
            };

            _livroFiccao = new Product
            {
                ProductId = 3,
                Name = "O Senhor Dos Aneis",
                Author = "Tolken J.R.",
                Publishing = "Abril",
                Year = 2005,
                Category = Categories.LiteraturaEstrangeira,
                Stock = 0,
                Price = 100.0M,
                Photo = ""
            };

            using (var db = new LivrariaTDDContext())
            {
                _livroTDD = db.Products.Add(_livroTDD);
                _livroRomance = db.Products.Add(_livroRomance);
                _livroFiccao = db.Products.Add(_livroFiccao);
                db.SaveChanges();
            }
        }
        public void TearDown()
        {
            using (var db = new LivrariaTDDContext())
            {
                foreach (var item in db.Orders)
                {
                    db.Orders.Remove(item);
                }

                foreach (var item in db.Products)
                {
                    db.Products.Remove(item);
                }

                foreach (var item in db.Users)
                {
                    db.Users.Remove(item);
                }

                foreach (var item in db.PaymentTypes)
                {
                    db.PaymentTypes.Remove(item);
                }

                db.SaveChanges();
            }
        }
Пример #22
0
 public PedidoRepository(LivrariaTDDContext livrariaContext)
 {
     _context = livrariaContext;
 }
        public void AoAcessarACamadaDeAcessoADadosParaSalvarUmaCompra_ACompraDeSerSalvaEOMetodoDeveRetornarVerdadeiro()
        {
            var novoLivro1 = new Product
            {
                Name = "Torre Negra",
                Author = "Stephen King",
                Publishing = "Universal",
                Year = 1995,
                Category = Categories.LiteraturaEstrangeira,
                Stock = 5,
                Price = 150.0M,
                Photo = "",
                Status = ProductStatus.Active
            };

            var novoLivro2 = new Product
            {
                Name = "Torre Negra Segunda edição",
                Author = "Stephen King",
                Publishing = "Universal",
                Year = 1998,
                Category = Categories.LiteraturaEstrangeira,
                Stock = 8,
                Price = 170.0M,
                Photo = "",
                Status = ProductStatus.Active
            };

            var formaPagamento = new PaymentType
                {
                    PaymentTypeName = "Boleto Bancário",
                    Icon = ""
                };

            var usuario = new User
                {
                    District = "Centro",
                    CellPhone = "3188888888",
                    ZipCode = 30625130,
                    City = "Belo Horizonte",
                    State = "MG",
                    Name = "Jô Soares",
                    Email = "*****@*****.**",
                    Number = 456,
                    Address = "Afonso Pena",
                    Password = "******",
                    Phone = "313333333",
                    UserType = "Cliente"
                };

            using (var livrariaContext = new LivrariaTDDContext())
            {
                novoLivro1 = livrariaContext.Products.Add(novoLivro1);
                novoLivro2 = livrariaContext.Products.Add(novoLivro2);
                formaPagamento = livrariaContext.PaymentTypes.Add(formaPagamento);
                usuario = livrariaContext.Users.Add(usuario);
                livrariaContext.SaveChanges();
            }

            var pedido = new Order
                {
                    User = usuario,
                    PaymentType = formaPagamento,
                    Products = new List<Product> {novoLivro1, novoLivro2},
                    OrderValue = novoLivro1.Price + novoLivro2.Price,
                    FreightValue = 10.00M,
                    TotalValue = novoLivro1.Price + novoLivro2.Price + 10.00M
                };

            int userId = usuario.UserId;
            var listaIdProducts = new List<int>{ novoLivro1.ProductId, novoLivro2.ProductId };
            int formaPagamentoId = formaPagamento.PaymentTypeId;

            using (var auxContext = new LivrariaTDDContext())
            {
                var countAntes = auxContext.Orders.Count();
                Assert.AreEqual(0, countAntes);
            }

            using (var livrariaContext = new LivrariaTDDContext())
            {
                _repository = new PedidoRepository(livrariaContext);

                var result = _repository.SalvarPedido(pedido, userId, listaIdProducts, formaPagamentoId);

                Assert.True(result);
            }

            using (var auxContext = new LivrariaTDDContext())
            {
                var countDepois = auxContext.Orders.Count();
                Assert.AreEqual(1, countDepois);
            }
        }
 public ProdutoRepository(LivrariaTDDContext context)
 {
     _context = context;
 }