Example #1
0
        public async Task ExecutionAuditorsCalledInRegistrationOrder()
        {
            // 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.RegisterExecutionAuditor <FirstAuditor>(true);
            pipeline.RegisterExecutionAuditor <SecondAuditor>(true);

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

            // Assert
            Assert.Equal("FirstAuditor", auditItems[0]);
            Assert.Equal("SecondAuditor", auditItems[1]);
            Assert.Equal(2, auditItems.Count);
        }
Example #2
0
        public async Task RegisteredExecutionAuditorIsCalled()
        {
            // 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.RegisterExecutionAuditor <FirstAuditor>(true);

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

            // Assert
            Assert.Equal("FirstAuditor", auditItems.Single());
        }
Example #3
0
        public async Task RegisteredExecutionAuditorIsOnlyCalledForRootWhenConfiguredAsSuch()
        {
            // 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.RegisterExecutionAuditor <FirstAuditor>(true);
            ICommandDispatchContext commandDispatchContext = new CommandDispatchContext("someid", new Dictionary <string, object>());

            commandDispatchContext.Increment();

            // Act
            await pipeline.AuditExecution(new SimpleCommand(), commandDispatchContext, 350, true, default(CancellationToken));

            // Assert
            Assert.Empty(auditItems);
        }
Example #4
0
        public async Task ExecutionAuditorPipelineExtractsCommandId()
        {
            // 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.RegisterExecutionAuditor <FirstAuditor>(true);
            SimpleIdentifiableCommand command = new SimpleIdentifiableCommand
            {
                CommandId = "helloworld"
            };

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

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