public async Task NoRegisteredPostDispatchAuditorCausesNoError() { // 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.AuditPostDispatch(new SimpleCommand(), new CommandDispatchContext("someid", new Dictionary <string, object>()), 200, default(CancellationToken)); // Assert - lack of exception is pass }
public async Task RegisteredPostDispatchAuditorIsCalled() { // 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.RegisterPostDispatchAuditor <FirstAuditor>(true); // Act await pipeline.AuditPostDispatch(new SimpleCommand(), new CommandDispatchContext("someid", new Dictionary <string, object>()), 100, default(CancellationToken)); // Assert Assert.Equal("FirstAuditor", auditItems.Single()); }
public async Task PostDispatchAuditorsCalledInRegistrationOrder() { // 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.RegisterPostDispatchAuditor <FirstAuditor>(true); pipeline.RegisterPostDispatchAuditor <SecondAuditor>(true); // Act await pipeline.AuditPostDispatch(new SimpleCommand(), new CommandDispatchContext("someid", new Dictionary <string, object>()), 150, default(CancellationToken)); // Assert Assert.Equal("FirstAuditor", auditItems[0]); Assert.Equal("SecondAuditor", auditItems[1]); Assert.Equal(2, auditItems.Count); }
public async Task RegisteredPostDispatchAuditorIsOnlyCalledForRootWhenConfiguredAsSuch() { // 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.RegisterPostDispatchAuditor <FirstAuditor>(true); ICommandDispatchContext commandDispatchContext = new CommandDispatchContext("someid", new Dictionary <string, object>()); commandDispatchContext.Increment(); // Act await pipeline.AuditPostDispatch(new SimpleCommand(), commandDispatchContext, 200, default(CancellationToken)); // Assert Assert.Empty(auditItems); }
public async Task PostDispatchAuditorPipelineExtractsCommandId() { // 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.RegisterPostDispatchAuditor <FirstAuditor>(true); SimpleIdentifiableCommand command = new SimpleIdentifiableCommand { CommandId = "helloworld" }; // Act await pipeline.AuditPostDispatch(command, new CommandDispatchContext("someid", new Dictionary <string, object>()), 300, default(CancellationToken)); // Assert Assert.Equal("helloworld", auditItems.Single().CommandId); }