public void DoNotTraceStartEventWhenTracingDisabled() { var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All); var listener = new FakeTraceListener(); traceSource.Listeners.Add(listener); using (new LogicalOperationScope(traceSource, traceSource.Name, traceEnabled: false)) Assert.Equal(0, listener.Messages.Count(m => m.Trim() == $"Logical operation {traceSource.Name} started")); }
public void TraceStopEventWhenTracingEnabled() { var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All); var listener = new FakeTraceListener(); traceSource.Listeners.Add(listener); new LogicalOperationScope(traceSource, traceSource.Name, traceEnabled: true).Dispose(); Assert.Equal(1, listener.Messages.Count(m => m.Trim() == $"Logical operation {traceSource.Name} stopped")); }
public void DoNotLogMessageIfTraceDisabled(Expression <Action <ILog> > expression, String expectedMessage) { var logger = new Logger("MyTestLogger", SourceLevels.Off); var listener = new FakeTraceListener(); var testMethod = expression.Compile(); logger.TraceSource.Listeners.Add(listener); testMethod(logger); Assert.Equal(0, listener.Messages.Count(m => m == expectedMessage)); }
public void DoNotTraceTransferIfTracingDisabled() { var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All); var listener = new FakeTraceListener(); var activityId = Guid.NewGuid(); traceSource.Listeners.Add(listener); Trace.CorrelationManager.ActivityId = activityId; using (new ActivityScope(traceSource, Guid.NewGuid(), traceEnabled: false)) Assert.Equal(0, listener.Messages.Count(m => m == String.Format("Transfer from {0} to {1}, relatedActivityId={1}", activityId, activityId))); }
public void TraceTransferIfNewActivityId() { var traceSource = new TraceSource(MethodBase.GetCurrentMethod().Name, SourceLevels.All); var listener = new FakeTraceListener(); var activityId = Guid.NewGuid(); traceSource.Listeners.Add(listener); // NOTE: Although the default implementation of TraceListener.TraceTransfer will append `, relatedActivityId={1}`, the // TraceListener.TraceTransfer can be overriden and thus appending `, relatedActivityId={1}` is not guaranteed. // Explicitly include the new activity id in the message even though the activity id may be repeated. Trace.CorrelationManager.ActivityId = Guid.Empty; using (new ActivityScope(traceSource, activityId)) Assert.Equal(1, listener.Messages.Count(m => m == String.Format("Transfer from {0} to {1}, relatedActivityId={1}", Guid.Empty, activityId))); }
public void UpdateDependency() { var fakeOracleDependencyManager = A.Fake <IOracleDependencyManager>(); var fakeOracleDependencyManagerRegistryDepCall = A.CallTo(() => fakeOracleDependencyManager.RegisterDependency(null)).WithAnyArguments(); var fakeSignalrDbDependencyFactory = A.Fake <ISignalrDbDependencyFactory>(); var fakeSignalrDbDependencyFactoryCreateDepCall = A.CallTo(() => fakeSignalrDbDependencyFactory.CreateDbDependency(null, false, 0, false)) .WithAnyArguments(); var fakeSignalrDependency = new FakeSignalrDependency(); fakeSignalrDbDependencyFactoryCreateDepCall.Returns(fakeSignalrDependency); TraceSource trace = new TraceSource("Fault"); FakeTraceListener fakeListener = new FakeTraceListener(); trace.Listeners.Add(fakeListener); trace.Switch.Level = SourceLevels.All; ObservableDbOperation dbOperation = new ObservableDbOperation(string.Empty, string.Empty, trace, null, A.Fake <IDbProviderFactory>(), fakeOracleDependencyManager, fakeSignalrDbDependencyFactory, true); dbOperation.ExecuteReaderWithUpdates(A.Fake <Action <IDataRecord, IDbOperation> >()); fakeSignalrDependency.FireEvent(OracleNotificationType.Change, OracleNotificationInfo.Update); int counter = 0; dbOperation.Faulted += (ex) => { counter++; }; Assert.AreEqual(0, counter); Assert.IsTrue(fakeListener.Traces.Exists(item => item.StartsWith("Oracle notification details:"))); fakeSignalrDependency.FireEvent(OracleNotificationType.Change, OracleNotificationInfo.End); Assert.AreEqual(0, counter); Assert.IsTrue(fakeListener.Traces.Exists(item => item.StartsWith("Oracle notification timed out"))); fakeSignalrDependency.FireEvent(OracleNotificationType.Change, OracleNotificationInfo.Drop); Assert.AreEqual(1, counter); Assert.IsTrue(fakeListener.Traces.Exists(item => item.StartsWith("Unexpected Oracle notification details:"))); fakeOracleDependencyManagerRegistryDepCall.MustHaveHappened(Repeated.AtLeast.Once); fakeSignalrDbDependencyFactoryCreateDepCall.MustHaveHappened(Repeated.AtLeast.Once); }
public void CatchQLreceiveloop() { // Configure IDbBehaviour to issue OracleException during AddOracleDependency var fakeDbBehavior = A.Fake <IDbBehavior>(); A.CallTo(() => fakeDbBehavior.AddOracleDependency(null, null)) .WithAnyArguments() .Throws(new Exception("Hello, World!")); A.CallTo(() => fakeDbBehavior.UpdateLoopRetryDelays).Returns(_updateLoopRetryDelays); // Define trace source with our listener to collect trace messages var traceSource = new TraceSource("ss"); FakeTraceListener fakeListener = new FakeTraceListener(); traceSource.Listeners.Add(fakeListener); traceSource.Switch.Level = SourceLevels.All; var fakeOracleDependencyManager = A.Fake <IOracleDependencyManager>(); var fakeSignalrDbDependencyFactory = A.Fake <ISignalrDbDependencyFactory>(); var fakeDbProviderFactory = A.Fake <IDbProviderFactory>(); ObservableDbOperation dbOperation = new ObservableDbOperation(string.Empty, string.Empty, traceSource, fakeDbBehavior, fakeDbProviderFactory, fakeOracleDependencyManager, fakeSignalrDbDependencyFactory, useOracleDependency: true); Action <object> action = (object obj) => { dbOperation.ExecuteReaderWithUpdates(A.Fake <Action <IDataRecord, IDbOperation> >()); }; CancellationTokenSource source = new CancellationTokenSource(); CancellationToken token = source.Token; Task task = new Task(action, "ss", token); task.Start(); task.Wait(TimeSpan.FromMilliseconds(5000)); source.Cancel(); Assert.IsNull(task.Exception); // Don`t know why it is here // Assert.IsNotInstanceOfType(task.Exception, typeof(AggregateException)); Assert.IsTrue(fakeListener.Traces.Exists(item => item.StartsWith("Error in SQL receive loop"))); }
public void DoNotLogMessageIfTraceDisabled(Expression<Action<ILog>> expression, String expectedMessage) { var logger = new Logger("MyTestLogger", SourceLevels.Off); var listener = new FakeTraceListener(); var testMethod = expression.Compile(); logger.TraceSource.Listeners.Add(listener); testMethod(logger); Assert.Equal(0, listener.Messages.Count(m => m == expectedMessage)); }