public List <ShoppingCart> GetAll() { using (var _shoppingCarts = new ShoppingCartRepository()) { return(_shoppingCarts.GetAll().ToList()); } }
public void Test_GetAll_ReturnsShoppingCartIdOfAllAvailableCartItems_WhenCalled() { //Arrange var expected = new List <ShoppingCart> { new ShoppingCart { ShoppingCartID = 1 }, new ShoppingCart { ShoppingCartID = 2 } }.AsQueryable(); var mockSet = new Mock <IDbSet <ShoppingCart> >(); mockSet.As <IQueryable <ShoppingCart> >().Setup(m => m.Provider).Returns(expected.Provider); mockSet.As <IQueryable <ShoppingCart> >().Setup(m => m.Expression).Returns(expected.Expression); mockSet.As <IQueryable <ShoppingCart> >().Setup(m => m.ElementType).Returns(expected.ElementType); mockSet.As <IQueryable <ShoppingCart> >().Setup(m => m.GetEnumerator()).Returns(expected.GetEnumerator()); var mockContext = new Mock <ECommerceEntities>(); mockContext.Setup(m => m.ShoppingCart).Returns(mockSet.Object); var testClass = new ShoppingCartRepository(mockContext.Object); //Act var actual = testClass.GetAll(); //Assert CollectionAssert.AreEqual(expected, actual); }
public void ShoppingCartRepositoryTests_GetAllTest() { ShoppingCartRepository repository = new ShoppingCartRepository(); var result = repository.GetAll(); Assert.IsTrue(result.Count() == 2); }
static void Main(string[] args) { Console.WriteLine("Shopping Cart coding test by Scott K. Fraley"); Console.WriteLine(); Console.WriteLine("OUTPUT:"); // Set the tax rate to be used TaxRate oTaxRate = new TaxRate(10.0); // instantiate the repository (which contains the data, and is // 'built' during construction.) ShoppingCartRepository repository = new ShoppingCartRepository(oTaxRate); // Since the calculations take place as the Shopping Carts are // created, all we need to do now is print the receipts! foreach (ShoppingCart shoppingCart in repository.GetAll()) { shoppingCart.PrintReceipt(); } Console.WriteLine(); Console.Write("Press any key to continue (or exit the Cmd window in this case)..."); Console.ReadLine(); }
public void ShoppingCartRepositoryTests_Delete() { ShoppingCartRepository repository = new ShoppingCartRepository(); var model = new Shopping_Cart() { Shopping_Cart_ID = 3 }; repository.Delete(3); var result = repository.GetAll(); var test = result.Where(x => x.Shopping_Cart_ID == 3); foreach (var item in test) { Assert.IsTrue(item.Shopping_Cart_ID == 3); } }
public void ShoppingCartRepositoryTests_Create() { ShoppingCartRepository repository = new ShoppingCartRepository(); var model = new Shopping_Cart() { Account = "Bill", Product_ID = 1, Quantity = 5, size = "M" }; repository.Create(model); var result = repository.GetAll(); var test = result.Where(x => x.Account == "Bill"); foreach (var item in test) { Assert.IsTrue(item.Account == "Bill"); } }
public void Test_GetAll_ReturnProductInCart_WhenCalled() { //Arrange Product Book = new Product(); var expected = new List <ShoppingCart> { new ShoppingCart { Title = Book } }; var testData = new List <ShoppingCart> { new ShoppingCart { Title = Book } }.AsQueryable(); var mockSet = new Mock <IDbSet <ShoppingCart> >(); mockSet.As <IQueryable <ShoppingCart> >().Setup(m => m.Provider).Returns(testData.Provider); mockSet.As <IQueryable <ShoppingCart> >().Setup(m => m.Expression).Returns(testData.Expression); mockSet.As <IQueryable <ShoppingCart> >().Setup(m => m.ElementType).Returns(testData.ElementType); mockSet.As <IQueryable <ShoppingCart> >().Setup(m => m.GetEnumerator()).Returns(testData.GetEnumerator()); var mockContext = new Mock <BookSaleEntities>(); mockContext.Setup(m => m.ShoppingCart).Returns(mockSet.Object); var testClass = new ShoppingCartRepository(mockContext.Object); //Act var actual = testClass.GetAll(); //Assert CollectionAssert.AreEqual(testData, actual); }
public void ShoppingCartRepositoryTests_Update() { ShoppingCartRepository repository = new ShoppingCartRepository(); var model = new Shopping_Cart() { Shopping_Cart_ID = 3, Account = "Bill", Product_ID = 3, Quantity = 3, UnitPrice = 150, Discount = 0, size = "s" }; repository.Update(3, 5); var result = repository.GetAll(); var test = result.Where(x => x.Quantity == 3); foreach (var item in test) { Assert.IsTrue(item.Quantity == 3); } }
public ActionResult <ICollection <ShoppingCart> > GetAll() { return(Ok(_shopppingCartRepository.GetAll <ShoppingCart>())); }
public List <ShoppingCart> CartGetAll() { List <ShoppingCart> allproducts = cartRepository.GetAll(); return(allproducts); }
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.")); }
public IHttpActionResult GetAll() { var shoppingCarts = shoppingCartRepository.GetAll(includes); return(Ok(shoppingCarts)); }