示例#1
0
        public async Task NoRegisteredPreDispatchAuditorCausesNoError()
        {
            // Arrange
            List <string> auditItems = new EditableList <string>();
            Mock <ICommandAuditSerializer>    serializer       = new Mock <ICommandAuditSerializer>();
            Mock <IAuditItemEnricherPipeline> enricherPipeline = new Mock <IAuditItemEnricherPipeline>();
            CommandAuditPipeline pipeline = new CommandAuditPipeline(t => new FirstAuditor(auditItems),
                                                                     () => serializer.Object,
                                                                     enricherPipeline.Object);

            // Act
            await pipeline.AuditPreDispatch(new SimpleCommand(), new CommandDispatchContext("someid", new Dictionary <string, object>()), default(CancellationToken));

            // Assert - lack of exception is pass
        }
示例#2
0
        public async Task RegisteredPreDispatchAuditorIsCalled()
        {
            // Arrange
            List <string> auditItems = new EditableList <string>();
            Mock <ICommandAuditSerializer>    serializer       = new Mock <ICommandAuditSerializer>();
            Mock <IAuditItemEnricherPipeline> enricherPipeline = new Mock <IAuditItemEnricherPipeline>();
            CommandAuditPipeline pipeline = new CommandAuditPipeline(t => new FirstAuditor(auditItems),
                                                                     () => serializer.Object,
                                                                     enricherPipeline.Object);

            pipeline.RegisterPreDispatchAuditor <FirstAuditor>(true);

            // Act
            await pipeline.AuditPreDispatch(new SimpleCommand(), new CommandDispatchContext("someid", new Dictionary <string, object>()), default(CancellationToken));

            // Assert
            Assert.Equal("FirstAuditor", auditItems.Single());
        }
示例#3
0
        public async Task RegisteredPreDispatchAuditorIsOnlyCalledForRootWhenConfiguredAsSuch()
        {
            // Arrange
            List <string> auditItems = new EditableList <string>();
            Mock <ICommandAuditSerializer>    serializer       = new Mock <ICommandAuditSerializer>();
            Mock <IAuditItemEnricherPipeline> enricherPipeline = new Mock <IAuditItemEnricherPipeline>();
            CommandAuditPipeline pipeline = new CommandAuditPipeline(t => new FirstAuditor(auditItems),
                                                                     () => serializer.Object,
                                                                     enricherPipeline.Object);

            pipeline.RegisterPreDispatchAuditor <FirstAuditor>(true);
            ICommandDispatchContext commandDispatchContext = new CommandDispatchContext("someid", new Dictionary <string, object>());

            commandDispatchContext.Increment();

            // Act
            await pipeline.AuditPreDispatch(new SimpleCommand(), commandDispatchContext, default(CancellationToken));

            // Assert
            Assert.Empty(auditItems);
        }
示例#4
0
        public async Task PreDispatchAuditorsCalledInRegistrationOrder()
        {
            // Arrange
            List <string> auditItems = new EditableList <string>();
            Mock <ICommandAuditSerializer>    serializer       = new Mock <ICommandAuditSerializer>();
            Mock <IAuditItemEnricherPipeline> enricherPipeline = new Mock <IAuditItemEnricherPipeline>();
            CommandAuditPipeline pipeline = new CommandAuditPipeline(t => t == typeof(FirstAuditor) ? (ICommandAuditor) new FirstAuditor(auditItems) : new SecondAuditor(auditItems),
                                                                     () => serializer.Object,
                                                                     enricherPipeline.Object);

            pipeline.RegisterPreDispatchAuditor <FirstAuditor>(true);
            pipeline.RegisterPreDispatchAuditor <SecondAuditor>(true);

            // Act
            await pipeline.AuditPreDispatch(new SimpleCommand(), new CommandDispatchContext("someid", new Dictionary <string, object>()), default(CancellationToken));

            // Assert
            Assert.Equal("FirstAuditor", auditItems[0]);
            Assert.Equal("SecondAuditor", auditItems[1]);
            Assert.Equal(2, auditItems.Count);
        }
示例#5
0
        public async Task PreDispatchAuditorPipelineExtractsCommandId()
        {
            // Arrange
            List <string>    auditors   = new EditableList <string>();
            List <AuditItem> auditItems = new List <AuditItem>();
            Mock <ICommandAuditSerializer>    serializer       = new Mock <ICommandAuditSerializer>();
            Mock <IAuditItemEnricherPipeline> enricherPipeline = new Mock <IAuditItemEnricherPipeline>();
            CommandAuditPipeline pipeline = new CommandAuditPipeline(t => new FirstAuditor(auditors, auditItems),
                                                                     () => serializer.Object,
                                                                     enricherPipeline.Object);

            pipeline.RegisterPreDispatchAuditor <FirstAuditor>(true);
            SimpleIdentifiableCommand command = new SimpleIdentifiableCommand
            {
                CommandId = "helloworld"
            };

            // Act
            await pipeline.AuditPreDispatch(command, new CommandDispatchContext("someid", new Dictionary <string, object>()), default(CancellationToken));

            // Assert
            Assert.Equal("helloworld", auditItems.Single().CommandId);
        }