public async Task Execute(string[] args) { // run to establish an initial connection. await Task.Run(() => { var id = Guid.NewGuid(); var shoppingCart = new ShoppingCart(id); var createShoppingCart = new CreateShoppingCart(Guid.NewGuid()); shoppingCart.Execute(createShoppingCart); return(_repository.Save(shoppingCart)); }); Console.WriteLine("=====================================\n"); Console.WriteLine("Starting repository throughtput test.\n"); var stopWatch = new Stopwatch(); var tasks = new List <Task>(); var max = 10000; Console.WriteLine($"Testing {max} events.\n"); stopWatch.Start(); for (var x = 0; x < max; x++) { tasks.Add(Task.Run(() => { var id = Guid.NewGuid(); var shoppingCart = new ShoppingCart(id); var createShoppingCart = new CreateShoppingCart(Guid.NewGuid()); shoppingCart.Execute(createShoppingCart); return(_repository.Save(shoppingCart)); })); } var masterTask = Task.WhenAll(tasks); while (!masterTask.IsCompleted) { var numberCompleted = tasks.Where(e => e.IsCompleted).Count(); Console.Write($"\r{numberCompleted}"); } stopWatch.Stop(); var time = stopWatch.Elapsed; Console.WriteLine($" shopping carts took {time.TotalSeconds:#.##} seconds.\n"); Console.WriteLine($"Throughput: {max / time.TotalSeconds:#.##} per second.\n"); Console.WriteLine("=====================================\n"); }
public void Handle(CreateShoppingCart message) { var cart = new ShoppingCart(message.AggregateId); _repository.Save(cart, message.ExpectedVersion); }