private static void SubscribeLogExceptionHandler(IEventBus eventBus, IServiceProvider sp, IEnumerable <EntityConfigRecord> entityConfigRecords) { var handlers = new ExceptionsLoggingEventHandlers(sp); foreach (var ecr in entityConfigRecords) { eventBus.Subscribe(ecr.EventKeys.Create, handlers.CreateEventHandler, $"{ecr.Name.ToLower()}-domain-entity-handler-created"); eventBus.Subscribe(ecr.EventKeys.Read, handlers.ReadEventHandler, $"{ecr.Name.ToLower()}-domain-entity-handler-read"); eventBus.Subscribe(ecr.EventKeys.Update, handlers.UpdateEventHandler, $"{ecr.Name.ToLower()}-domain-entity-handler-updated"); eventBus.Subscribe(ecr.EventKeys.Delete, handlers.DeleteEventHandler, $"{ecr.Name.ToLower()}-domain-entity-handler-deleted"); } }
public void AllHandlersReturnsOnMissingInfo() { var logger = new Mock <ILogger <ExceptionsLoggingEventHandlers> >(); var sp = MockServiceProvider(logger); var h = new ExceptionsLoggingEventHandlers(sp.Object); var e = new DomainEvent(); h.CreateEventHandler(e); h.ReadEventHandler(e); h.UpdateEventHandler(e); h.DeleteEventHandler(e); logger.Verify(l => l.Log( It.Is <LogLevel>(level => level == LogLevel.Error), It.IsAny <EventId>(), It.IsAny <object>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()), Times.Never); }
public void AllHandlersLogErrorOnException() { var logger = new Mock <ILogger <ExceptionsLoggingEventHandlers> >(); var sp = MockServiceProvider(logger); var h = new ExceptionsLoggingEventHandlers(sp.Object); var expEx = new Exception(); var e = new DomainEvent { Data = new { exception = expEx, logRecord = new LogRecord { TraceId = "some-ex-id" }, } }; h.CreateEventHandler(e); VerifyLogger(); h.ReadEventHandler(e); VerifyLogger(); h.UpdateEventHandler(e); VerifyLogger(); h.DeleteEventHandler(e); VerifyLogger(); void VerifyLogger() { logger.Verify(l => l.Log( It.Is <LogLevel>(level => level == LogLevel.Error), It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Once); logger.Reset(); } }