Пример #1
0
        public static IEnumerable <object[]> SubscribersToThisEvent()
        {
            var fakeSubscriber1 = FakeSubscriber <FakeEvent1>();
            var fakeSubscriber2 = FakeSubscriber <FakeEvent2>();
            var fakeSubscriber3 = FakeSubscriber <FakeEvent3>();
            var fakeSubscriber4 = FakeSubscriber <FakeEvent3>();
            var publisher       = new DomainEventPublisher();

            publisher.Subscribe(fakeSubscriber1);
            publisher.Subscribe(fakeSubscriber2);
            publisher.Subscribe(fakeSubscriber3);
            publisher.Subscribe(fakeSubscriber4);
            yield return(new object[]
            {
                publisher,
                new FakeEvent1(),
                new IDomainEventHandler[] { fakeSubscriber1 }
            });

            yield return(new object[]
            {
                publisher,
                new FakeEvent2(),
                new IDomainEventHandler[] { fakeSubscriber1, fakeSubscriber2 }
            });

            yield return(new object[]
            {
                publisher,
                new FakeEvent3(),
                new IDomainEventHandler[] { fakeSubscriber3, fakeSubscriber4 }
            });
        }
Пример #2
0
 public void Publish_WhenCalled_DoesNotCallUnSubscribersToThisEvent(DomainEventPublisher publisher,
                                                                    IDomainEvent @event,
                                                                    IEnumerable <IDomainEventHandler> unSubscribersToThisEvent)
 {
     // Arrange
     unSubscribersToThisEvent.ForEach(s => s.ClearReceivedCalls());
     // Act
     publisher.Publish(@event);
     // Assert
     Assert.All(unSubscribersToThisEvent, s => s.DidNotReceive().Handle(Arg.Any <IDomainEvent>()));
 }
Пример #3
0
 public void Publish_WhenCalled_DoesNotCallSubscribersToOtherEvents(DomainEventPublisher publisher,
                                                                    IDomainEvent @event,
                                                                    IEnumerable <IDomainEventHandler> subscribersToOtherEvents)
 {
     // Arrange
     subscribersToOtherEvents.ForEach(s => s.ClearReceivedCalls());
     // Act
     publisher.Publish(@event);
     // Assert
     Assert.All(subscribersToOtherEvents, s => s.DidNotReceive().Handle(Arg.Any <IDomainEvent>()));
 }
Пример #4
0
 public void Publish_WhenCalled_CallsSubscribersToThisEvent(DomainEventPublisher publisher,
                                                            IDomainEvent @event,
                                                            IEnumerable <IDomainEventHandler> subscribersToThisEvent)
 {
     // Arrange
     subscribersToThisEvent.ForEach(s => s.ClearReceivedCalls());
     // Act
     publisher.Publish(@event);
     // Assert
     Assert.All(subscribersToThisEvent, s => s.Received(1).Handle(@event));
 }