public SectionProductList GetProductList() { var productGenerator = new ProductGenerator(); var productList = new SectionProductList(); productList.SystemId = Guid.NewGuid(); productList.Title = "Products"; productList.Text = "Here are some products you may be interested in."; foreach (var i in Enumerable.Range(1, 4)) { productList.Products.Add(productGenerator.GenerateProduct()); } return(productList); }
public async Task Create_Order_Then_Update_Product_Then_Get_Order_Products_Test() { var product0 = await _productRepository.CreateProductAsync( ProductGenerator.GenerateProduct(), CancellationToken.None); var product1 = await _productRepository.CreateProductAsync( ProductGenerator.GenerateProduct(), CancellationToken.None); var product2 = await _productRepository.CreateProductAsync( ProductGenerator.GenerateProduct(), CancellationToken.None); var order = new OrderEntity { CreatedOn = DateTime.UtcNow, ProductIdCollection = new[] { Guid.NewGuid(), Guid.NewGuid(), product0.Id, Guid.NewGuid(), product1.Id, product2.Id, Guid.NewGuid(), } }; order = await _orderRepository.CreateOrderAsync(order, CancellationToken.None); Assert.IsNotNull(order); Assert.IsNotNull(order.Products); Assert.IsNotNull(order.ProductIdCollection); var products = order.Products.ToArray(); Assert.AreEqual(3, products.Length); Assert.IsTrue(products.Any(product => product.Id == product0.Id)); Assert.IsTrue(products.Any(product => product.Id == product1.Id)); Assert.IsTrue(products.Any(product => product.Id == product2.Id)); var productIdCollection = order.ProductIdCollection.ToArray(); Assert.AreEqual(3, productIdCollection.Length); Assert.IsTrue(productIdCollection.Any(id => id == product0.Id)); Assert.IsTrue(productIdCollection.Any(id => id == product1.Id)); Assert.IsTrue(productIdCollection.Any(id => id == product2.Id)); product0.Sku = ProductGenerator.GenerateToken(); await _productRepository.UpdateProducAsync(product0, CancellationToken.None); var productsForOrder = await _productRepository.GetProductsForOrderAsync( order.Id, OrderProductSortProperty.Sku, SortDirection.Descending, CancellationToken.None); Assert.IsNotNull(productsForOrder); var controlProductsForOrder = new[] { product0, product1, product2, } .OrderByDescending(product => product.Sku) .ToArray(); var testProductsForOrder = productsForOrder.ToArray(); Assert.AreEqual(controlProductsForOrder.Length, testProductsForOrder.Length); for (var i = 0; i < controlProductsForOrder.Length; ++i) { Assert.AreEqual(controlProductsForOrder[i].Id, testProductsForOrder[i].Id); Assert.AreEqual(controlProductsForOrder[i].Sku, testProductsForOrder[i].Sku); Assert.AreEqual(controlProductsForOrder[i].Name, testProductsForOrder[i].Name); Assert.AreEqual(controlProductsForOrder[i].Price, testProductsForOrder[i].Price); } var changeNotes = await _productChangeNoteRepository.GetProductChangeNotesAsync( product0.Id, CancellationToken.None); Assert.IsNotNull(changeNotes); Assert.AreEqual(2, changeNotes.Count()); Assert.IsTrue(changeNotes.Any(changeNote => changeNote is OrderCreatedProductChangeNoteEntity)); Assert.IsTrue(changeNotes.Any(changeNote => changeNote is ProductFieldChangedProductChangeNoteEntity)); }