protected override void Given()
        {
            this.formatter        = new MockFormatter();
            this.inMemoryListener = new InMemoryEventListener(this.formatter);
            var sink = new Lazy <IObserver <EventEntry> >(() => this.inMemoryListener);

            this.SourceSettingsConfig = this.SourceSettingsConfig ?? new EventSourceSettingsConfig(EventSource.GetName(typeof(MyCompanyEventSource)));
            this.eventSources         = new List <EventSourceSettingsConfig>()
            {
                { this.SourceSettingsConfig }
            };
            this.sinkSettings = new List <SinkSettings>()
            {
                { new SinkSettings("test", sink, this.eventSources) }
            };
            this.configuration = new TraceEventServiceConfiguration(sinkSettings, this.serviceSettings);

            try
            {
                this.Sut = new TraceEventService(configuration);
            }
            catch (UnauthorizedAccessException uae)
            {
                Assert.Inconclusive(uae.Message);
            }

            // Clean up any previous unclosed session to avoid collisions
            this.RemoveAnyExistingSession();
        }
        public void when_creating_instance_with_id_only()
        {
            var sut = new EventSourceSettingsConfig(eventSourceId: MyCompanyEventSource.Log.Guid);

            Assert.AreEqual(MyCompanyEventSource.Log.Guid.ToString(), sut.Name);
            Assert.AreEqual(MyCompanyEventSource.Log.Guid, sut.EventSourceId);
            Assert.AreEqual(EventLevel.LogAlways, sut.Level);
            Assert.AreEqual(EventKeywords.All, sut.MatchAnyKeyword);
        }
            public void then_session_is_updated_with_new_eventSources()
            {
                var currentEventSource = this.sinkSettings.EventSources.First();
                var newEventSource     = new EventSourceSettingsConfig(currentEventSource.Name, level: currentEventSource.Level, matchAnyKeyword: Tracing.EventKeywords.AuditSuccess);

                this.Sut.UpdateSession(new List <EventSourceSettingsConfig>()
                {
                    newEventSource
                });

                Assert.AreEqual(newEventSource.MatchAnyKeyword, currentEventSource.MatchAnyKeyword);
            }
            protected override void When()
            {
                // We expect 3 events, 2 for listener1(Level=LogAlways) and 1 for listener2 (Level=Warning)
                inMemoryListener.WaitSignalCondition = () => inMemoryListener.EventWrittenCount == 3;

                var sink           = new Lazy <IObserver <EventEntry> >(() => inMemoryListener);
                var sourceSettings = new EventSourceSettingsConfig(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Warning);
                var eventSources   = new List <EventSourceSettingsConfig>()
                {
                    { sourceSettings }
                };

                this.configuration.SinkSettings.Add(new SinkSettings("test2", sink, eventSources));
            }
            protected override void Given()
            {
                base.Given();
                inMemoryListener.WaitSignalCondition = () => inMemoryListener.EventWrittenCount == 2;
                var sink           = new Lazy <IObserver <EventEntry> >(() => inMemoryListener);
                var sourceSettings = new EventSourceSettingsConfig(EventSource.GetName(typeof(TestEventSource)));

                this.eventSources.Add(sourceSettings);
                sinkSettings = new List <SinkSettings>()
                {
                    { new SinkSettings("test", sink, eventSources) }
                };
                configuration = new TraceEventServiceConfiguration(sinkSettings);
                this.Sut      = new TraceEventService(configuration);
                this.Sut.Start();
            }
            protected override void Given()
            {
                RemoveAnyExistingSession(SessionName2);
                base.Given();

                inMemoryListener2 = new InMemoryEventListener(formatter);
                var sink           = new Lazy <IObserver <EventEntry> >(() => inMemoryListener2);
                var sourceSettings = new EventSourceSettingsConfig(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Informational, matchAnyKeyword: MyCompanyEventSource.Keywords.Page);
                var eventSources   = new List <EventSourceSettingsConfig>()
                {
                    { sourceSettings }
                };
                var sinkSettings = new List <SinkSettings>()
                {
                    { new SinkSettings("test", sink, eventSources) }
                };
                var configuration = new TraceEventServiceConfiguration(sinkSettings, new TraceEventServiceSettings()
                {
                    SessionNamePrefix = SessionName2
                });

                this.Sut2 = new TraceEventService(configuration);
            }