private void AssertTimerIntervalChanges(AsyncWrapperTarget asyncWrapperTarget, TargetMock targetMock, AutoResetEvent flag, int internalTargetLatency)
 {
     var loggingEvents = new[] { new LoggingEvent() };
     targetMock.SleepFor = internalTargetLatency;
     asyncWrapperTarget.Push(loggingEvents);
     flag.WaitOne();
     Debug.Print("TimerInterval is {0} ms", asyncWrapperTarget.TimerInterval);
     var diff = Math.Abs(asyncWrapperTarget.TimerInterval - internalTargetLatency);
     Assert.LessOrEqual(diff, 10, "The TimerInterval was not adjusted properly.");
 }
        public void WhenInternalTargetTakesMoreOrLessTheTimerIntervalIsAdjustedAutomatically()
        {
            var flag = new AutoResetEvent(false);
            var targetMock = new TargetMock();

            var asyncWrapperTarget = new AsyncWrapperTarget(targetMock);
            asyncWrapperTarget.TimerIntervalChanged += x => flag.Set();

            AssertTimerIntervalChanges(asyncWrapperTarget, targetMock, flag, 200);
            AssertTimerIntervalChanges(asyncWrapperTarget, targetMock, flag, 500);
            AssertTimerIntervalChanges(asyncWrapperTarget, targetMock, flag, 100);
        }
 protected virtual Target WrapWithAsyncWrapperTarget(Target target)
 {
     var asyncTargetWrapper = new AsyncWrapperTarget(target);
     PulsusDebugger.Write("Wrapped target '{0}' with AsyncWrapperTarget", asyncTargetWrapper.Name);
     return asyncTargetWrapper;
 }