protected override void Arrange()
        {
            this.traceListener = new MockTraceListener();
            var logWriter =
                new LogWriter(
                    new ILogFilter[0],
                    new LogSource[0],
                    new LogSource("all", new TraceListener[] { this.traceListener }, SourceLevels.All),
                    new LogSource(""),
                    new LogSource(""),
                    "default",
                    false,
                    false);

            Logger.SetLogWriter(logWriter, false);
        }
コード例 #2
0
 public void Setup()
 {
     this.traceListener = new MockTraceListener("original");
     this.logWriter =
         new LogWriter(
             new LogWriterStructureHolder(
                 new ILogFilter[0],
                 new Dictionary<string, LogSource>(),
                 new LogSource("all", new[] { traceListener }, SourceLevels.All),
                 new LogSource("not processed"),
                 new LogSource("error"),
                 "default",
                 false,
                 false,
                 false));
 }
コード例 #3
0
        public void TraceListenerFilterOnSingleElementCollectionReturnsHasSingleElement()
        {
            TraceListenerFilter filter = new TraceListenerFilter();

            TraceListener listener1 = new MockTraceListener();
            IEnumerable<TraceListener> traceListenersCollection = new TraceListener[] { listener1 };

            int i = 0;
            Dictionary<TraceListener, int> listeners = new Dictionary<TraceListener, int>();
            foreach (TraceListener listener in filter.GetAvailableTraceListeners(traceListenersCollection))
            {
                i++;
                listeners[listener] = (listeners.ContainsKey(listener) ? listeners[listener] : 0) + 1;
            }

            Assert.AreEqual(1, i);
            Assert.AreEqual(1, listeners[listener1]);
        }
 public void Setup()
 {
     this.traceListener = new MockTraceListener("mock");
     this.coordinator = new MockLoggingUpdateCoordinator();
     this.wrapperTraceListener = new ReconfigurableTraceListenerWrapper(this.traceListener, this.coordinator);
 }
 public void Setup()
 {
     this.traceListener = new MockTraceListener("mock");
     this.eventSource = new MockLoggingUpdateCoordinator();
 }
 public void Setup()
 {
     this.traceListener = new MockTraceListener("mock");
     this.eventSource = null;
 }
        public void WhenTheLoggingUpdateEventIsTriggered_ThenThePreviousTraceListenerIsDisposed()
        {
            var newTraceListener = new MockTraceListener("mock");
            var container = new UnityContainer().RegisterInstance<TraceListener>("mock", newTraceListener);

            this.coordinator.RaiseLoggingUpdate(new UnityServiceLocator(container));

            Assert.IsTrue(this.traceListener.wasDisposed);
        }
        public void WhenTheLoggingUpdateEventIsTriggered_ThenTheWrapperStartsUsingANewTraceListenerResolvedFromTheLocatorInTheEventArguments()
        {
            var newTraceListener = new MockTraceListener("mock");
            var container = new UnityContainer().RegisterInstance<TraceListener>("mock", newTraceListener);

            this.coordinator.RaiseLoggingUpdate(new UnityServiceLocator(container));

            var cache = new TraceEventCache();
            var data = new object();

            this.wrapperTraceListener.TraceData(cache, "source", TraceEventType.Critical, 100, data);

            Assert.IsNull(this.traceListener.tracedData);
            Assert.IsNull(this.traceListener.tracedSource);
            Assert.IsNull(this.traceListener.tracedEventType);
            Assert.AreSame(data, newTraceListener.tracedData);
            Assert.AreEqual("source", newTraceListener.tracedSource);
            Assert.AreEqual(TraceEventType.Critical, newTraceListener.tracedEventType);
        }
コード例 #9
0
        public void CanGetAllTraceListeners()
        {
            var listener1 = new MockTraceListener();
            var listener2 = new MockTraceListener();
            var listener3 = new MockTraceListener();
            var listener4 = new MockTraceListener();

            var config = new LoggingConfiguration();

            config.AddLogSource("source1", listener1, listener2);
            config.AddLogSource("source2", listener2);
            config.AddLogSource("source3", listener1, listener3);
            config.AddLogSource("source4");

            config.SpecialSources.Unprocessed.AddTraceListener(listener2);
            config.SpecialSources.Unprocessed.AddTraceListener(listener4);

            var allListeners = config.AllTraceListeners.ToArray();

            Assert.AreEqual(4, allListeners.Length);
            CollectionAssert.AreEquivalent(new TraceListener[] { listener1, listener2, listener3, listener4 }, allListeners);
        }
コード例 #10
0
        public void CanAddAsynchronousTraceListenerToSpecialSource()
        {
            var listener = new MockTraceListener { Name = "listener", Filter = new EventTypeFilter(SourceLevels.Critical) };

            var config = new LoggingConfiguration();

            config.SpecialSources.LoggingErrorsAndWarnings.AddAsynchronousTraceListener(listener);

            var addedListener = (AsynchronousTraceListenerWrapper)config.SpecialSources.LoggingErrorsAndWarnings.Listeners.First();

            Assert.AreSame(listener, addedListener.TraceListener);
            Assert.AreEqual("listener", addedListener.Name);
            Assert.AreEqual(SourceLevels.Critical, ((EventTypeFilter)addedListener.Filter).EventType);
        }
コード例 #11
0
        public void Setup()
        {
            MockTraceListener.Reset();
            this.traceListener = new MockTraceListener();

            var logWriter =
                new LogWriter(
                    new ILogFilter[0],
                    new LogSource[0],
                    new LogSource("all", new TraceListener[] { traceListener }, SourceLevels.All),
                    new LogSource("not processed"),
                    new LogSource("errors"),
                    "default",
                    true,
                    false);

            Logger.SetLogWriter(logWriter, false);
        }
コード例 #12
0
        public void TraceListenerFilterOnMultipleCollectionsWithDisjointElementsDoesNotRepeatElements()
        {
            TraceListenerFilter filter = new TraceListenerFilter();

            TraceListener listener1 = new MockTraceListener();
            TraceListener listener2 = new MockTraceListener();
            IEnumerable<TraceListener> traceListenersCollection1 = new TraceListener[] { listener1, listener2 };
            TraceListener listener3 = new MockTraceListener();
            TraceListener listener4 = new MockTraceListener();
            IEnumerable<TraceListener> traceListenersCollection2 = new TraceListener[] { listener3, listener4 };

            int i = 0;
            Dictionary<TraceListener, int> listeners = new Dictionary<TraceListener, int>();
            foreach (TraceListener listener in filter.GetAvailableTraceListeners(traceListenersCollection1))
            {
                i++;
                listeners[listener] = (listeners.ContainsKey(listener) ? listeners[listener] : 0) + 1;
            }
            foreach (TraceListener listener in filter.GetAvailableTraceListeners(traceListenersCollection2))
            {
                i++;
                listeners[listener] = (listeners.ContainsKey(listener) ? listeners[listener] : 0) + 1;
            }

            Assert.AreEqual(4, i);
            Assert.AreEqual(1, listeners[listener1]);
            Assert.AreEqual(1, listeners[listener2]);
            Assert.AreEqual(1, listeners[listener3]);
            Assert.AreEqual(1, listeners[listener4]);
        }