public void TestGetAll() { ContactInformation contactInformation1 = new ContactInformation() { Phone = "phone", Email = "*****@*****.**" }; ContactInformation contactInformation2 = new ContactInformation() { Phone = "phone", Email = "*****@*****.**" }; var customers = new List <Customer> { new Customer() { Name = "Customer1", ContactInformation = contactInformation1 }, new Customer() { Name = "Customer2", ContactInformation = contactInformation2 }, }; customerRepository.AddRange(customers); customerRepository.UnitOfWork.Commit(); var customersRepo = customerRepository.Set(); customersRepo.Should().NotBeEmpty() .And.HaveCount(2) .And.Equal(customers, (c1, c2) => c1.Name == c2.Name) .And.NotContain((c) => c.CustomerId == 0); }
public void TestQuery() { ContactInformation contactInformation1 = new ContactInformation() { Phone = "phone1", Email = "*****@*****.**" }; var customer1 = new Customer() { Name = "Customer1", ContactInformation = contactInformation1 }; ContactInformation contactInformation2 = new ContactInformation() { Phone = "phone2", Email = "*****@*****.**" }; var customer2 = new Customer() { Name = "Customer2", ContactInformation = contactInformation2 }; var customers = new List <Customer>() { customer1, customer2 }; customerRepository.AddRange(customers); customerRepository.UnitOfWork.Commit(); var customerRepos = customerRepository.UnitOfWork.ExecuteQuery <Customer>("SELECT CUSTOMER_ID as CustomerId, NAME as Name, PHONE as Phone, EMAIL as email FROM CUSTOMERS"); customerRepos.Should().NotBeEmpty() .And.HaveCount(2) .And.ContainItemsAssignableTo <Customer>() .And.Equal(customers, (c1, c2) => c1.Name == c2.Name); }
public Pagination() { ContactInformation contactInformation1 = new ContactInformation() { Phone = "phone", Email = "*****@*****.**" }; ContactInformation contactInformation2 = new ContactInformation() { Phone = "phone", Email = "*****@*****.**" }; ContactInformation contactInformation3 = new ContactInformation() { Phone = "phone", Email = "*****@*****.**" }; ContactInformation contactInformation4 = new ContactInformation() { Phone = "phone", Email = "*****@*****.**" }; ContactInformation contactInformation5 = new ContactInformation() { Phone = "phone", Email = "*****@*****.**" }; customers = new List <Customer> { new Customer() { Name = "Customer1", ContactInformation = contactInformation1 }, new Customer() { Name = "Customer2", ContactInformation = contactInformation2 }, new Customer() { Name = "Customer3", ContactInformation = contactInformation3 }, new Customer() { Name = "Customer4", ContactInformation = contactInformation4 }, new Customer() { Name = "Customer5", ContactInformation = contactInformation5 } }; customerRepository = new CustomerRepository(new ProjectsContext(dbContextOptions)); customerRepository.AddRange(customers); customerRepository.UnitOfWork.Commit(); }
public IHttpActionResult ResetApiData() { // Delete all data: shoppingCartProductRepository.RemoveRange(shoppingCartProductRepository.GetAll()); shoppingCartProductRepository.SaveChanges(); shoppingCartRepository.RemoveRange(shoppingCartRepository.GetAll()); shoppingCartRepository.SaveChanges(); customerRepository.RemoveRange(customerRepository.GetAll()); customerRepository.SaveChanges(); productRepository.RemoveRange(productRepository.GetAll()); productRepository.SaveChanges(); brandRepository.RemoveRange(brandRepository.GetAll()); brandRepository.SaveChanges(); categoryRepository.RemoveRange(categoryRepository.GetAll()); categoryRepository.SaveChanges(); // Create brands: List <Brand> brands = new List <Brand>(); brands.Add(new Brand() { Name = "Samsung" }); brands.Add(new Brand() { Name = "Lenovo" }); brands.Add(new Brand() { Name = "Dell" }); brands.Add(new Brand() { Name = "Asus" }); brands.Add(new Brand() { Name = "HP" }); brands.Add(new Brand() { Name = "Acer" }); brands.Add(new Brand() { Name = "Sony" }); brands.Add(new Brand() { Name = "Microsoft" }); brandRepository.AddRange(brands); brandRepository.SaveChanges(); // Create categories: List <Category> categories = new List <Category>(); categories.Add(new Category() { Name = "Cellphones" }); categories.Add(new Category() { Name = "Computers" }); categories.Add(new Category() { Name = "Tablets" }); categories.Add(new Category() { Name = "Video Games" }); categories.Add(new Category() { Name = "Accessories" }); categoryRepository.AddRange(categories); categoryRepository.SaveChanges(); // Create products: List <Product> products = new List <Product>(); products.Add(new Product() { Name = "Samsung Galaxy S8", BrandId = brands[0].Id, CategoryId = categories[0].Id, Price = Convert.ToDecimal(789.99) }); products.Add(new Product() { Name = "Dell XPS 13", BrandId = brands[2].Id, CategoryId = categories[1].Id, Price = Convert.ToDecimal(1144.99) }); products.Add(new Product() { Name = "Samsung Galaxy Tab", BrandId = brands[0].Id, CategoryId = categories[2].Id, Price = Convert.ToDecimal(989.59) }); products.Add(new Product() { Name = "Playstation 4", BrandId = brands[6].Id, CategoryId = categories[3].Id, Price = Convert.ToDecimal(299.99) }); products.Add(new Product() { Name = "Microsoft Surface Mouse", BrandId = brands[7].Id, CategoryId = categories[4].Id, Price = Convert.ToDecimal(64.99) }); productRepository.AddRange(products); productRepository.SaveChanges(); // Create customers: List <Customer> customers = new List <Customer>(); customers.Add(new Customer() { FirstName = "Adam", LastName = "Smith", EmailAddress = "*****@*****.**" }); customers.Add(new Customer() { FirstName = "Arnold", LastName = "Jordan", EmailAddress = "*****@*****.**" }); customers.Add(new Customer() { FirstName = "Calvin", LastName = "Williams", EmailAddress = "*****@*****.**" }); customers.Add(new Customer() { FirstName = "Emma", LastName = "Jones", EmailAddress = "*****@*****.**" }); customers.Add(new Customer() { FirstName = "Sophia", LastName = "Wilson", EmailAddress = "*****@*****.**" }); customerRepository.AddRange(customers); customerRepository.SaveChanges(); return(Ok("Api data reseted.")); }