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); }
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()); }
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); }
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); }