private Task MixedWorkload(IEcommerceService service, Random rng) { return(Task.Run(async() => { //90% of workload is queries if (rng.NextDouble() < 0.9) { int productId = rng.Next(1, 100000); await service.GetProductById(productId); } else { var customer = rng.Next(1, 1000); await service.PlaceOrder(customer, DateTimeOffset.Now, await RandomItems(service, rng)); } })); }
private async Task <List <OrderItem> > RandomItems(IEcommerceService service, Random rng) { var numItems = rng.Next(1, 5); var items = new List <OrderItem>(); for (int i = 0; i < numItems; i++) { var productId = rng.Next(1, 100000); var randomItem = new OrderItem { Quantity = rng.Next(1, 5), UnitPrice = rng.Next(39, 21399), Product = await service.GetProductById(productId) }; items.Add(randomItem); } return(items); }