public void FindWithBrandAndCategoryAndPriceShouldReturnAllProductswithThosePropertiesOrderedDescendingByPrice() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: $"FindWithBrandAndCategoryAndPriceShouldReturnAllProductswithThosePropertiesOrderedDescendingByPrice_Shop_Database") .Options; var dbContext = new ApplicationDbContext(options); var mapper = this.SetUpAutoMapper(); var productsService = new ProductsService(dbContext, mapper); var shopService = new ShopService(dbContext, productsService, mapper); this.SeedDbWithProductsAndBrandsAndCategories(dbContext, "brandYaah", "categoryYaah", "productYaah"); var products = productsService.FindAllProducts(); var model = this.CreateShopViewModel("brandYaah", "categoryYaah", 1, 0M, 10M, 12, "pDESC"); var result = shopService.Find(model); var highestPricedProduct = result[0]; var sortedResult = result.OrderByDescending(x => x.Price).ToList(); for (int i = 0; i < result.Count; i++) { Assert.Equal(result[i], sortedResult[i]); } }
public void FindWithBrandAndCategoryAndPriceShouldReturnAllProductswithThosePropertiesOrderedAscendingByPrice() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: $"FindWithBrandAndCategoryAndPriceShouldReturnAllProductswithThoseProperties_Shop_Database") .Options; var dbContext = new ApplicationDbContext(options); var mapper = this.SetUpAutoMapper(); var productsService = new ProductsService(dbContext, mapper); var shopService = new ShopService(dbContext, productsService, mapper); this.SeedDbWithProductsAndBrandsAndCategories(dbContext, "brandYaah", "categoryYaah", "productYaah"); var products = productsService.FindAllProducts(); var model = this.CreateShopViewModel("brandYaah", "categoryYaah", 1, 0M, 10M, 12, "pASC"); var result = shopService.Find(model); var lowestPricedProduct = result[0]; foreach (var item in result) { Assert.Equal(item.Brand.Name, model.Brand); Assert.Equal(item.Category.Name, model.Category); Assert.True(item.Price >= lowestPricedProduct.Price && item.Price <= model.PriceUpper); } }
public void FindAllUserOrdersShouldReturnAllUserOrders() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: $"FindAllUserOrdersShouldReturnAllUserOrders_Orders_Database") .Options; var dbContext = new ApplicationDbContext(options); var mapper = this.SetUpAutoMapper(); var brandService = new BrandsService(dbContext, mapper); var categoriesService = new CategoriesService(dbContext, mapper); var usersService = new UsersService(dbContext, mapper); var productsService = new ProductsService(dbContext, mapper); var shoppingCartsService = new ShoppingCartsService(dbContext, productsService, usersService, mapper); var ordersService = new OrdersService(dbContext, shoppingCartsService, mapper); var favouritesService = new FavouritesService(dbContext, productsService, usersService, mapper); this.SeeDbdWithBrands(dbContext); this.SeedDbWithCategories(dbContext); var brands = brandService.FindAllBrands(); var categories = categoriesService.FindAllCategories(); var image = new Mock <IFormFile>(); this.SeedDbWithCountries(dbContext); this.SeedDbWithUserAndProduct(dbContext, productsService, mapper.Map <Category>(categories[0]), mapper.Map <Brand>(brands[0]), image.Object); var user = dbContext.Users.FirstOrDefault(x => x.UserName == "1"); var products = productsService.FindAllProducts(); var shoppingCarts = dbContext.ShoppingCarts; var shoppingCartss = dbContext.ShoppingCartProducts; var cart = this.SeedDbShoppingCartWithProducts(dbContext, user.UserName, products[0].Id); var model = this.CreateOrderCreateBindingModel(); var orderId = ordersService.CreateOrder(model, mapper.Map <ApplicationUserDTO>(user)); var orders = ordersService.FindAllUserOrders(mapper.Map <ApplicationUserDTO>(user)); Assert.True(orders.Count == 1); }
public void GetAllProducts_Success() { // Arrange var mapperMock = new Mock <IMapper>(); mapperMock.Setup(m => m.Map <ProductItemDTO>(It.IsAny <ProductItem>())).Returns(new ProductItemDTO()); var mockDb = new Mock <IProductRepository>(); List <ProductItem> result = CreateProductItemsList(); mockDb.Setup(x => x.GetProducts()).Returns(result.AsQueryable()); IProductService service = new ProductsService(mockDb.Object, null, mapperMock.Object); //Act List <ProductItemDTO> list = service.FindAllProducts().Result; // Assert Assert.AreEqual(2, list.Count()); }