Exemple #1
0
        private static void TestSendCommandAndFillupReadmodel(ReadmodelPublisher queue,
                                                              FakeBus bus)
        {
            queue.Start(typeof(Program).Assembly);

            System.Console.WriteLine("Hit any to start. Ctrl+C to quit when running.");
            System.Console.ReadKey();

            var cancellationTokenSource = new CancellationTokenSource();

            var senderTask = new Action(async() =>
            {
                var orderId = Guid.NewGuid();

                var loopIterations = 0;
                while (loopIterations < 20)
                {
                    if (cancellationTokenSource.IsCancellationRequested)
                    {
                        break;
                    }

                    await bus.SendAsync(new CreateOrderCommand()
                    {
                        OrderId      = orderId,
                        CustomerName = "Joske"
                    });

                    await bus.SendAsync(new AddItemToCardCommand()
                    {
                        OrderId = orderId,
                        Card    = "test"
                    });

                    orderId = Guid.NewGuid();

                    await Task.Delay(1, cancellationTokenSource.Token);

                    loopIterations++;
                }
            });

            var tList = new List <Task>();

            for (int i = 0; i < 1; i++)
            {
                var t = new Task(senderTask, cancellationTokenSource.Token, TaskCreationOptions.LongRunning);
                t.Start();
                tList.Add(t);
            }


            Console.WriteLine("done");
            Console.ReadKey();
            // var summary = queue.Getsummary();
            //Console.WriteLine($"summary, send {intSequence} items, handled messages summary: {summary}");
            try
            {
                cancellationTokenSource.Cancel();
                queue.Stop();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }


            Console.ReadKey();
        }