Beispiel #1
0
        public void SampleTestEvent_ShouldRunWithNoException(int id)
        {
            var testEvent = new TestEvent
            {
                Id = id
            };

            Should.NotThrow(() => Micro.Publish(testEvent));
        }
        public async Task Handle(CustomerOrdered model)
        {
            var r = new Random();
            await Task.Delay(r.Next(1000, 10000));

            Console.WriteLine("Warehouse notified, ID: {0}, Customer Id: {1}", model.Command.Id, model.Command.CustomerId);
            var warehouseNotifiedEvent = new WarehouseNotifiedEvent
            {
                TimeHandled = DateTime.Now,
                Event       = model
            };

            Micro.Publish(warehouseNotifiedEvent);
        }
Beispiel #3
0
        private async Task RealAsyncTask(SampleCommand model)
        {
            Console.WriteLine("Start time: {0}", DateTime.Now.ToString());
            await Task.Delay(1000);

            Console.WriteLine("Handling Sample Command with Async - Id:{0}, Name:{1}, AccountNo:{2}", model.Id, model.Name, model.AccountNo);

            var sampleCommandHandledEvent =
                new SampleCommandHandledEvent {
                SampleCommandHandled = model, TimeHandled = DateTime.Now
            };

            Micro.Publish(sampleCommandHandledEvent);
        }
        public async Task Handle(CustomerRegistered model)
        {
            var r = new Random();
            await Task.Delay(r.Next(1000, 10000));

            Console.WriteLine("Password Created, ID: {0}, Name: {1}", model.Command.Id, model.Command.Name);
            var customerPasswordCreated = new CustomerPasswordCreated
            {
                TimeHandled = DateTime.Now,
                Command     = model
            };

            Micro.Publish(customerPasswordCreated);
        }
        private async Task AsyncValidation(CustomerOrderCommand model)
        {
            // Do some validations for this command here
            await Task.Delay(1000);

            Console.WriteLine("Handling CustomerOrderCommand - Id:{0}, Customer Id:{1}", model.Id, model.CustomerId);

            var sampleCommandHandledEvent =
                new CustomerOrdered {
                Command = model, TimeHandled = DateTime.Now
            };

            // Once validation is finished, we publish as a customer registered event.
            Micro.Publish(sampleCommandHandledEvent);
        }
        public async Task Handle(WarehouseNotifiedEvent model)
        {
            var r = new Random();
            await Task.Delay(r.Next(1000, 10000));

            var itemsToBePackaged = model.Event.Command.ItemsOrdered;

            foreach (var item in itemsToBePackaged)
            {
                Console.WriteLine("Items packaged, ID: {0}, Customer Id: {1}, Item: {2}", model.Event.Command.Id, model.Event.Command.CustomerId, item);
                var itemsPackagedEvent = new ItemsPackagedEvent
                {
                    TimeHandled  = DateTime.Now,
                    Event        = model,
                    PackagedItem = item
                };
                Micro.Publish(itemsPackagedEvent);
            }
        }