示例#1
0
        public void Handler_ShouldThrow_WhenSubscriptionForDualEvent_IsNotImplementedProperly()
        {
            //Arrange
            var handler = new Handler();
            var context = new DualContext();
            var subs    = new InvalidDualSubscription();

            handler.Subscribe(subs);

            //Act
            handler.Dispatch <DualEvent, DualContext>(context);

            //Assert
            Assert.ThrowsException <InvalidOperationException>(() => handler.Dispatch <DualEvent>());
        }
示例#2
0
        public void Handler_ShouldDispatchAll_WhenSubscriptionForDualEvent_IsImplementedProperly()
        {
            //Arrange
            var subscriptionsHandled = 0;
            var handler = new Handler();
            var context = new DualContext();
            var subs    = new ValidDualSubscription(() => subscriptionsHandled++);

            handler.Subscribe <DualEvent>(subs);

            //Act
            handler.Dispatch <DualEvent, DualContext>(context);
            handler.Dispatch <DualEvent>();

            //Assert
            Assert.AreEqual(2, subscriptionsHandled);
        }
示例#3
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);
        }