public void MockEtwProcessorStopsProcessingOnQueueEmptyAndStopProcessingWhenQueueEmptyFlagIsSet()
 {
     const string anySessionName = "session";
     int eventsProcessed = 0;
     int numEventsInjectedAfterProcess = 10;
     int numEventsInjectedBeforeProcess = 10;
     using (var processor = new MockETWProcessor(anySessionName))
     {
         processor.StopProcessingWhenQueueEmpty = true;
         for (int i = 0; i < numEventsInjectedBeforeProcess; i++)
         {
             processor.InjectEvent(new ETWEvent(new DateTime(), new Guid(), "", ushort.MaxValue, "", new byte(),
                                                EventKeywords.AuditFailure, EventLevel.Critical,
                                                EventOpcode.DataCollectionStart, new Guid(), 1, 1,
                                                new OrderedDictionary()));
         }
         processor.EventProcessed += ev => eventsProcessed++;
         processor.Process();
         for (int i = 0; i < numEventsInjectedAfterProcess; i++)
         {
             processor.InjectEvent(new ETWEvent(new DateTime(), new Guid(), "", ushort.MaxValue, "", new byte(),
                                                EventKeywords.AuditFailure, EventLevel.Critical,
                                                EventOpcode.DataCollectionStart, new Guid(), 1, 1,
                                                new OrderedDictionary()));
         }
     }
     Assert.AreEqual(numEventsInjectedBeforeProcess, eventsProcessed);
 }
        public void MockETWProcessorTriggersEndEventWithSessionNameAndEventCount()
        {
            const string anySessionName = "session";
            const long anyEventCount = 42;
            bool eventTriggered = false;

            using (var processor = new MockETWProcessor(anySessionName))
            {
                processor.EventProcessed += ev => { };
                processor.SessionEnd += (name, end, count, lostCount, unreadableCount) =>
                                        {
                                            Assert.AreEqual(anySessionName, name);
                                            Assert.AreEqual(anyEventCount, count);
                                            eventTriggered = true;
                                        };
                processor.ProcessAsync();
                for (int i = 0; i < anyEventCount; ++i)
                {
                    processor.InjectEvent(new ETWEvent(DateTime.Now, Guid.Empty, string.Empty, 0, string.Empty, 0,
                                                       EventKeywords.None,
                                                       EventLevel.Verbose, EventOpcode.Info, Guid.Empty, 0, 0, null));
                }
                processor.StopProcessing();
                Assert.IsTrue(eventTriggered);
            }
        }
        public void MockETWProcessorTriggersEventProcessedWithSameETWEventObjectPassedToInjectEvent()
        {
            const string anySessionName = "session";
            var anyEvent = new ETWEvent(DateTime.Now, Guid.Empty, string.Empty, 0, string.Empty, 0, EventKeywords.None,
                                        EventLevel.Verbose, EventOpcode.Info, Guid.Empty, 0, 0, null);
            bool eventTriggered = false;

            using (var processor = new MockETWProcessor(anySessionName))
            {
                processor.EventProcessed += ev =>
                                            {
                                                Assert.AreSame(anyEvent, ev);
                                                eventTriggered = true;
                                            };
                processor.ProcessAsync();
                processor.InjectEvent(anyEvent);
                processor.StopProcessing();
                Assert.IsTrue(eventTriggered);
            }
        }