Пример #1
0
        public void DoNotRaiseEvent_AfterCommandIsExecuted_WhenCommandHasRaiseEventAttributeAndEnabledFalse()
        {
            var command = new FakeCommandWithoutValidator();

            Assert.IsAssignableFrom <ICommand>(command);

            var eventProcessor = new Mock <IProcessEvents>(MockBehavior.Strict);

            eventProcessor.Setup(x => x.Raise(command));

            var attribute = new RaiseEventAttribute
            {
                Enabled = false
            };

            var decorated = new Mock <IHandleCommand <FakeCommandWithoutValidator> >(MockBehavior.Strict);

            TypeDescriptor.AddAttributes(decorated.Object.GetType(), attribute);
            decorated.Setup(x => x.Handle(command));

            var decorator = new CommandEventProcessingDecorator <FakeCommandWithoutValidator>(eventProcessor.Object, () => decorated.Object);

            decorator.Handle(command);

            decorated.Verify(x => x.Handle(command), Times.Once);
            eventProcessor.Verify(x => x.Raise(It.IsAny <IEvent>()), Times.Never);
        }
        public void DoNotRaiseEvent_AfterCommandIsExecuted_WhenCommandDoesNotHaveRaiseEventAttribute()
        {
            var command = new FakeCommandWithoutValidator();
            Assert.IsAssignableFrom<ICommand>(command);

            var eventProcessor = new Mock<IProcessEvents>(MockBehavior.Strict);
            eventProcessor.Setup(x => x.Raise(command));

            var decorated = new Mock<IHandleCommand<FakeCommandWithoutValidator>>(MockBehavior.Strict);
            decorated.Setup(x => x.Handle(command));

            var decorator = new CommandEventProcessingDecorator<FakeCommandWithoutValidator>(eventProcessor.Object, () => decorated.Object);
            decorator.Handle(command);

            decorated.Verify(x => x.Handle(command), Times.Once);
            eventProcessor.Verify(x => x.Raise(It.IsAny<IEvent>()), Times.Never);
        }
Пример #3
0
        public void DoNotRaiseEvent_AfterCommandIsExecuted_WhenCommandDoesNotHaveRaiseEventAttribute()
        {
            var command = new FakeCommandWithoutValidator();

            Assert.IsAssignableFrom <ICommand>(command);

            var eventProcessor = new Mock <IProcessEvents>(MockBehavior.Strict);

            eventProcessor.Setup(x => x.Raise(command));

            var decorated = new Mock <IHandleCommand <FakeCommandWithoutValidator> >(MockBehavior.Strict);

            decorated.Setup(x => x.Handle(command));

            var decorator = new CommandEventProcessingDecorator <FakeCommandWithoutValidator>(eventProcessor.Object, () => decorated.Object);

            decorator.Handle(command);

            decorated.Verify(x => x.Handle(command), Times.Once);
            eventProcessor.Verify(x => x.Raise(It.IsAny <IEvent>()), Times.Never);
        }
        public void RaiseEvent_AfterCommandIsExecuted_WhenCommandHasRaiseEventAttributeAndEnabledTrue()
        {
            var command = new FakeCommandWithoutValidator();
            Assert.IsAssignableFrom<ICommand>(command);

            var eventProcessor = new Mock<IProcessEvents>(MockBehavior.Strict);
            eventProcessor.Setup(x => x.Raise(command));

            var attribute = new RaiseEventAttribute
            {
                Enabled = true
            };

            var decorated = new Mock<IHandleCommand<FakeCommandWithoutValidator>>(MockBehavior.Strict);
            TypeDescriptor.AddAttributes(decorated.Object.GetType(), attribute);
            decorated.Setup(x => x.Handle(command));

            var decorator = new CommandEventProcessingDecorator<FakeCommandWithoutValidator>(eventProcessor.Object, () => decorated.Object);
            decorator.Handle(command);

            decorated.Verify(x => x.Handle(command), Times.Once);
            eventProcessor.Verify(x => x.Raise(command), Times.Once);
        }