Ejemplo n.º 1
0
        public void GetProductQuantitiesInBasketAsAJsonString()
        {
            // Arrange
            InMemoryProductDbContext ctx = CreateTestDatabase();
            BasketRepository         basketRepository = new BasketRepository(ctx);

            // Act
            List <Product> productsToAdd = new List <Product>()
            {
                new Product()
                {
                    Title    = "Product 1",
                    Quantity = 2
                }
            };

            foreach (var product in productsToAdd)
            {
                ctx.Products.Add(product);
            }
            ctx.SaveChanges();

            // Add new basket to database
            string ownerId = "george";

            basketRepository.CreateBasket(ownerId);

            // Add products to basket
            Basket basket = basketRepository.GetBasketByOwnerId(ownerId);

            foreach (var product in productsToAdd)
            {
                basketRepository.AddProductToBasket(product.ProductId, basket.OwnerID);
            }
            string productQuantitiesString = basketRepository.GetProductQuantitiesInBasketAsAJsonString(ownerId);

            //Assert
            string expectedString = "[{\"productId\":1,\"quantity\":1,\"product\":{\"ProductId\":1,\"OwnerID\":null,\"Title\":\"Product 1\",\"Description\":null,\"Seller\":null,\"Price\":0,\"Quantity\":2,\"ImageUrl\":null}}]";

            Assert.AreEqual(expectedString, productQuantitiesString);
        }