internal static bool FindMatch(this MemoryTarget events, DispatcherId dispatcherId, DispatcherActivity activity)
 {
     var dispatcherEntries = events.GetDispatcherEvents(dispatcherId);
     return dispatcherEntries.Any(e => e.Activity == activity);
 }
 internal static DispatcherActivityLogEntry Find(this MemoryTarget events, DispatcherId dispatcherId, DispatcherActivity activity)
 {
     var dispatcherEntries = events.GetDispatcherEvents(dispatcherId);
     return dispatcherEntries.SingleOrDefault(e => e.Activity == activity);
 }
        internal static void DispatcherActivity(this Logger log, DispatcherId dispatcherId, DispatcherActivity activity, PoisonPill poisonPill = null, Exception exception = null, bool logAsError = true)
        {
            var logEntry = new DispatcherActivityLogEntry
            {
                DispatcherId = dispatcherId,
                Activity = activity,
                PoisonPill = poisonPill,
                Exception = exception
            };

            if (exception == null)
            {
                if (activity == Dispatching.DispatcherActivity.CheckingForUnfinishedJobs)
                    log.Debug(logEntry);
                else
                    log.Info(logEntry);
            }
            else if (logAsError)
                log.Error(exception, logEntry.ToString());
            else
                log.Info(exception, logEntry.ToString());
        }
        internal static void DispatcherActivity(this Logger log, DispatcherId dispatcherId, DispatcherActivity activity, Job job, JobStatus oldStatus, JobStatus? newStatus = null)
        {
            var logEntry = new DispatcherActivityLogEntry
            {
                DispatcherId = dispatcherId,
                Activity = activity,
                Job = job,
                OldStatus = oldStatus,
                NewStatus = newStatus ?? oldStatus
            };

            log.Info(logEntry);
        }
        internal static DispatcherActivityLogEntry Find(this MemoryTarget events, DispatcherId dispatcherId, DispatcherActivity activity, JobStatus newStatus)
        {
            var dispatcherEntries = events.GetDispatcherEvents(dispatcherId);

            return dispatcherEntries.SingleOrDefault(
                e => (e.Activity == activity) &&
                     (e.NewStatus == newStatus)
            );
        }
 internal void AssertOnASingleWorkDispatcherThatTheDummyJobPassedThrough(DispatcherActivity thisActivity)
 {
     var dispatcherLogs = WorkDispatcher.Repository.GetDispatcherEvents();
     var containsActivity = dispatcherLogs.Any(e => e.Activity == thisActivity);
     var containsAnotherActivity = AnotherWorkDispatcher.Repository.GetDispatcherEvents().Any(e => e.Activity == thisActivity);
     (containsActivity | containsAnotherActivity).Should().BeTrue();
 }
        //internal void DisposeWorkDispatcher()
        //{
        //    Thread.Sleep(1000);
        //    WorkDispatcher.Dispose();
        //}

        //internal void AssertOnWorkDispatcherThatJobHasDispatchedTheDummyJobForTheDummyWorker()
        //{
        //    var containsActivity = WorkDispatcher.Repository.GetDispatcherEvents().Any(e => e.Activity == DispatcherActivity.JobWasDispatched);
        //    containsActivity.Should().BeTrue();
        //}

        //internal void AssertOnWorkDispatcherThatJobHasHasBeenRejected()
        //{
        //    var containsActivity = WorkDispatcher.Repository.GetDispatcherEvents().Any(e => e.Activity == DispatcherActivity.JobWasRejected);
        //    containsActivity.Should().BeTrue();
        //}

        internal void AssertOnWorkDispatcherThatTheDummyJobPassedThrough(DispatcherActivity activity)
        {
            var dispatcherLogs = WorkDispatcher.Repository.GetDispatcherEvents();
            var containsActivity = dispatcherLogs.Any(e => e.Activity == activity);
            containsActivity.Should().BeTrue();
        }