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); }
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); }