public void SubscriptionClientDropped_EnsureEventEntryIsGeneratedAndPassedThrough() { LogLevel recordedLogLevel = LogLevel.None; IGraphLogEntry recordedlogEntry = null; // fake a log to recieve the event generated on the extension method var mock = new Mock <IGraphEventLogger>(); mock.Setup(x => x.Log(It.IsAny <LogLevel>(), It.IsAny <Func <IGraphLogEntry> >())) .Callback((LogLevel logLevel, Func <IGraphLogEntry> entryMaker) => { recordedLogLevel = logLevel; recordedlogEntry = entryMaker(); }); var client = new Mock <ISubscriptionClientProxy <GraphSchema> >(); client.Setup(x => x.Id).Returns("clientId1"); mock.Object.SubscriptionClientDropped(client.Object); var entry = recordedlogEntry as SubscriptionClientDroppedLogEntry; Assert.IsNotNull(entry); Assert.AreEqual(LogLevel.Debug, recordedLogLevel); Assert.AreEqual(entry.ClientTypeName, client.Object.GetType().FriendlyName(true)); Assert.AreEqual(entry.ClientId, "clientId1"); Assert.AreNotEqual(entry.ToString(), entry.GetType().Name); }
public void SchemaSubscriptionRouteRegistered_EnsureEventEntryIsGeneratedAndPassedThrough() { LogLevel recordedLogLevel = LogLevel.None; IGraphLogEntry recordedlogEntry = null; // fake a log to recieve the event generated on the extension method var mock = new Mock <IGraphEventLogger>(); mock.Setup(x => x.Log(It.IsAny <LogLevel>(), It.IsAny <Func <IGraphLogEntry> >())) .Callback((LogLevel logLevel, Func <IGraphLogEntry> entryMaker) => { recordedLogLevel = logLevel; recordedlogEntry = entryMaker(); }); mock.Object.SchemaSubscriptionRouteRegistered <GraphSchema>("testPath"); var entry = recordedlogEntry as SchemaSubscriptionRouteRegisteredLogEntry <GraphSchema>; Assert.IsNotNull(entry); Assert.AreEqual(LogLevel.Debug, recordedLogLevel); Assert.AreEqual(entry.SchemaTypeName, typeof(GraphSchema).FriendlyName(true)); Assert.AreEqual(entry.SchemaSubscriptionRoutePath, "testPath"); Assert.AreNotEqual(entry.ToString(), entry.GetType().Name); }
/// <inheritdoc /> public virtual void Log(LogLevel logLevel, IGraphLogEntry logEntry) { if (logEntry == null || !this.IsEnabled(logLevel)) { return; } this.Log(logLevel, logEntry.EventId, logEntry, null, (state, _) => state.ToString()); }
public void UnHandledException_EnsureEventEntryIsGeneratedAndPassedThrough() { Exception exception = null; try { throw new InvalidCastException("test failure"); } catch (Exception ex) { // generate an exception witha stack trace exception = ex; } LogLevel recordedLogLevel = LogLevel.None; IGraphLogEntry recordedlogEntry = null; // fake a log to recieve the event generated on the extension method var mock = new Mock <IGraphLogger>(); mock.Setup(x => x.Log(It.IsAny <LogLevel>(), It.IsAny <IGraphLogEntry>())) .Callback((LogLevel logLevel, IGraphLogEntry logEntry) => { recordedLogLevel = logLevel; recordedlogEntry = logEntry; }); var factory = new Mock <ILoggerFactory>(); factory.Setup(x => x.CreateLogger(It.IsAny <string>())).Returns(null as ILogger); mock.Object.UnhandledExceptionEvent(exception); var entry = recordedlogEntry as UnhandledExceptionLogEntry; Assert.AreEqual(LogLevel.Critical, recordedLogLevel); Assert.AreEqual(exception.Message, entry.ExceptionMessage); Assert.AreEqual(exception.StackTrace, entry.StackTrace); Assert.AreEqual(exception.GetType().FriendlyName(true), entry.TypeName); }
public void SubscriptionEventPublished_EnsureEventEntryIsGeneratedAndPassedThrough() { LogLevel recordedLogLevel = LogLevel.None; IGraphLogEntry recordedlogEntry = null; // fake a log to recieve the event generated on the extension method var mock = new Mock <IGraphEventLogger>(); mock.Setup(x => x.Log(It.IsAny <LogLevel>(), It.IsAny <Func <IGraphLogEntry> >())) .Callback((LogLevel logLevel, Func <IGraphLogEntry> entryMaker) => { recordedLogLevel = logLevel; recordedlogEntry = entryMaker(); }); var eventData = new SubscriptionEvent() { Id = Guid.NewGuid().ToString(), SchemaTypeName = "someSchemaName", Data = new object(), DataTypeName = "someTypeName", EventName = "testEvent", }; mock.Object.SubscriptionEventPublished(eventData); var entry = recordedlogEntry as SubscriptionEventPublishedLogEntry; Assert.IsNotNull(entry); Assert.AreEqual(LogLevel.Debug, recordedLogLevel); Assert.AreEqual(entry.SubscriptionEventName, eventData.EventName); Assert.AreEqual(entry.DataType, eventData.DataTypeName); Assert.AreEqual(entry.SchemaType, eventData.SchemaTypeName); Assert.AreEqual(entry.SubscriptionEventId, eventData.Id); Assert.AreEqual(entry.MachineName, Environment.MachineName); Assert.AreNotEqual(entry.ToString(), entry.GetType().Name); }