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 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 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 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 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 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(); } }
public void SetUp() { using (var db = new LivrariaTDDContext()) { foreach (var item in db.Products.ToList()) { db.Products.Remove(item); } 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 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 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(); 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(); } }