public async Task SubscribesMultipleEvents()
            {
                // Given
                IEventCollection eventCollection = new EventCollection();

                eventCollection.Subscribe <TestEvent>(async args =>
                {
                    args.Foo++;
                    await Task.CompletedTask;
                });
                eventCollection.Subscribe <TestEvent>(async args =>
                {
                    args.Foo++;
                    await Task.CompletedTask;
                });
                eventCollection.Subscribe <TestEvent>(args =>
                {
                    args.Foo++;
                });
                TestEvent args = new TestEvent {
                    Foo = 3
                };

                // When
                await eventCollection.RaiseAsync(args);

                // Then
                args.Foo.ShouldBe(6);
            }
Ejemplo n.º 2
0
 static void InitEvent()
 {
     //初始化领域事件
     EventCollection.Subscribe(new WxOrderShippingEventHandle());
     EventCollection.Subscribe(new SmsOrderShippingEventHandle());
     EventCollection.Subscribe(new WxPaymentSucessEventHandle());
 }
            public async Task SubscribesSyncEvent()
            {
                // Given
                IEventCollection eventCollection = new EventCollection();

                eventCollection.Subscribe <TestEvent>(args =>
                {
                    args.Foo = 4;
                });
                TestEvent args = new TestEvent {
                    Foo = 1
                };

                // When
                await eventCollection.RaiseAsync(args);

                // Then
                args.Foo.ShouldBe(4);
            }