public void SetUp()
        {
            configurationSource = new DictionaryConfigurationSourceWithHandlersQuery();

            InstrumentationConfigurationSection instrumentationConfig = new InstrumentationConfigurationSection(true, true);
            configurationSource.Add(InstrumentationConfigurationSection.SectionName, instrumentationConfig);

            settings = new LoggingSettings();
            configurationSource.Add(LoggingSettings.SectionName, settings);

            settings.SpecialTraceSources.ErrorsTraceSource
                = new TraceSourceData("error", SourceLevels.Off);

            TraceSourceData traceSourceData = new TraceSourceData("blocking", SourceLevels.All);
            traceSourceData.TraceListeners.Add(new TraceListenerReferenceData("listener1"));
            settings.TraceSources.Add(traceSourceData);
            traceSourceData = new TraceSourceData("nonblocking", SourceLevels.All);
            traceSourceData.TraceListeners.Add(new TraceListenerReferenceData("listener2"));
            settings.TraceSources.Add(traceSourceData);

            TraceListenerData traceListenerData = new CustomTraceListenerData("listener1", typeof(MockBlockingCustomTraceListener), "init 1");
            settings.TraceListeners.Add(traceListenerData);
            traceListenerData = new MockTraceListenerData("listener2");
            settings.TraceListeners.Add(traceListenerData);

            MockTraceListener.Reset();
            MockBlockingCustomTraceListener.Reset();
        }
        public void CreatesAynchronousTraceListenerWithTimeoutWhenOverridden()
        {
            var data = new MockTraceListenerData() { Asynchronous = true, AsynchronousDisposeTimeout = TimeSpan.FromSeconds(10), Filter = SourceLevels.Warning, TraceOutputOptions = TraceOptions.ProcessId };

            var listener = data.BuildTraceListener(new LoggingSettings());

            Assert.IsInstanceOfType(listener, typeof(AsynchronousTraceListenerWrapper));
            Assert.AreEqual(SourceLevels.Warning, ((EventTypeFilter)listener.Filter).EventType);
        }
        public void CreatesSynchronousTraceListenerByDefault()
        {
            var data = new MockTraceListenerData() { Filter = SourceLevels.Warning, TraceOutputOptions = TraceOptions.ProcessId };

            var listener = data.BuildTraceListener(new LoggingSettings());

            Assert.IsInstanceOfType(listener, typeof(MockTraceListener));
            Assert.AreEqual(SourceLevels.Warning, ((EventTypeFilter)listener.Filter).EventType);
        }
        public void CreatedPoliciesIncludeContainerLifetime()
        {
            TraceListenerData listenerData = new MockTraceListenerData("listener");
            loggingSettings.TraceListeners.Add(listenerData);

            MockTraceListener listener = null;

            using (IUnityContainer newContainer = new UnityContainer())
            {
                newContainer.AddExtension(new EnterpriseLibraryCoreExtension(configurationSource));

                listener = 
                    (MockTraceListener)((ReconfigurableTraceListenerWrapper)newContainer.Resolve<TraceListener>("listener")).InnerTraceListener;

                Assert.IsNotNull(listener);
                Assert.AreSame(
                    listener,
                    ((ReconfigurableTraceListenerWrapper)newContainer.Resolve<TraceListener>("listener")).InnerTraceListener);	// lifetime managed?

                Assert.IsFalse(listener.wasDisposed);
            }

            Assert.IsTrue(listener.wasDisposed);	// lifetime managed by the container?
        }