Beispiel #1
0
        public void Handler_ShouldNotThrow_WhenSubscriptionForDualEvent_IsImplementedProperly()
        {
            //Arrange
            var timesDispatched = 0;
            var handler         = new Handler();
            var context         = new DualContext();
            var subs            = new ValidDualSubscription(() => { timesDispatched++; });

            handler.Subscribe <DualEvent>(subs);

            //Act
            //Assert
            try
            {
                handler.Dispatch <DualEvent, DualContext>(context);
                handler.Dispatch <DualEvent>();
            }
            catch (Exception e)
            {
                Assert.Fail($"Expected no exception, but got {e.Message}");
            }
            Assert.AreEqual(timesDispatched, 2);
        }
Beispiel #2
0
        public void Handler_ShouldNotify_ContexlessSubscribe()
        {
            //Arrange
            var handler          = new Handler();
            var subscriptionMock = new Mock <ContextlessSubscription>();

            subscriptionMock.Setup(m => m.Handle());
            handler.Subscribe(subscriptionMock.Object);

            //Act
            handler.Dispatch <ContextlessEvent>();

            //Assert
            subscriptionMock.Verify(x => x.Handle(), Times.Once());
        }
Beispiel #3
0
        public void Handler_ShouldNotify_ContexlessLambda()
        {
            //Arrange
            var subscriptionCalled = false;
            var handler            = new Handler();

            handler.Subscribe <ContextlessEvent>(() => {
                subscriptionCalled = true;
            });

            //Act
            handler.Dispatch <ContextlessEvent>();

            //Assert
            Assert.IsTrue(subscriptionCalled);
        }
Beispiel #4
0
        public void Handler_ShouldNotNotify_WhenSubscriptionRemoved()
        {
            //Arrange
            var subscriptionCalled = false;
            var handler            = new Handler();
            var subscription       = handler.Subscribe <ContextlessEvent>(() => {
                subscriptionCalled = true;
            });

            handler.Unsubscribe(subscription);

            //Act
            handler.Dispatch <ContextlessEvent>();

            //Assert
            Assert.IsFalse(subscriptionCalled);
        }
Beispiel #5
0
        public void Handler_ShouldNotify_ContexfulSubscribe()
        {
            //Arrange
            var handler          = new Handler();
            var subscriptionMock = new Mock <ContextfulSubscription>();
            var context          = new Context()
            {
                Data = 42
            };

            subscriptionMock.Setup(m => m.Handle(It.IsAny <Context>()));
            handler.Subscribe(subscriptionMock.Object);

            //Act
            handler.Dispatch <ContextfulEvent, Context>(context);

            //Assert
            subscriptionMock.Verify(x => x.Handle(context), Times.Once());
        }
Beispiel #6
0
        public void Handler_ShouldNotify_ContexfulLambda()
        {
            //Arrange
            var subscriptionCalled = false;
            var handler            = new Handler();
            var context            = new Context()
            {
                Data = 42
            };

            handler.Subscribe <ContextfulEvent, Context>((ctx) => {
                subscriptionCalled = true;
            });

            //Act
            handler.Dispatch <ContextfulEvent, Context>(context);

            //Assert
            Assert.IsTrue(subscriptionCalled);
        }
Beispiel #7
0
        public void Handler_ShouldNotify_AllSubscriptions()
        {
            //Arrange
            var subscriptionsHandled = 0;
            var handler = new Handler();

            handler.Subscribe <ContextlessEvent>(() => {
                subscriptionsHandled++;
            });
            handler.Subscribe <ContextlessEvent>(() => {
                subscriptionsHandled++;
            });
            handler.Subscribe <ContextlessEvent>(() => {
                subscriptionsHandled++;
            });

            //Act
            handler.Dispatch <ContextlessEvent>();

            //Assert
            Assert.AreEqual(subscriptionsHandled, 3);
        }