public void raises_OnError_when_failing_to_add_performance_counter() { var onError = new EventSpy<ErrorEventArgs>(); Agent.OnError += onError; Check.That( () => Agent.AddPerformanceCounter("PerfC", @"\Bougs(_Total)\Metric") == false, () => onError.HasBeenCalled); }
public void gracefully_handles_OnError_raisng_exceptions() { var onError = new EventSpy<ErrorEventArgs>(); Agent.OnError += (_,e) => { throw new Exception(); }; Agent.OnError += onError; //force a failure Agent.AddPerformanceCounter("PerfC", @"\Bougs(_Total)\Metric"); Check.That(() => onError.HasBeenCalled); }
public void RunOnceTest() { Schedule schedule = new Schedule(); EventSpy requiredEvent = new EventSpy(); EventSpy forbiddenEvent = new EventSpy(); schedule.Add(requiredEvent, 100); schedule.Add(forbiddenEvent, 200); schedule.RunOnce(); Assert.IsTrue(requiredEvent.happened); Assert.IsFalse(forbiddenEvent.happened); }
public void handles_flush_error() { var error = new InvalidOperationException(); var onError = new EventSpy <System.IO.ErrorEventArgs>((_, x) => Check.That(() => x.GetException() == error)); var agent = new SampleAgent(); agent.OnError += onError; agent.Flushed += _ => throw error; agent.Flush(DateTime.Now); Check.That(() => onError.HasBeenCalled); }
public void records_number_of_invocations() { var target = new TestTarget(); var fooSpy = new EventSpy<EventArgs>(); target.OnFoo += fooSpy; target.Foo(); Check.That(() => fooSpy.HasBeenCalled); fooSpy.Then((s, e) => Check.That( () => Object.ReferenceEquals(s, target), () => e == EventArgs.Empty)); }
public void raises_BeginRequest() { var beginRequest = new EventSpy<MvcRequestHandlerEventArgs>(); ConfigureHost = host => { host.RequestHandler.BeginRequest += beginRequest; }; WithResponseFrom("http://localhost:8080", response => { }); Verify.That(() => beginRequest.HasBeenCalled); Verify.Guard(() => beginRequest.Then((s, e) => Verify.That(() => e.Request.Url.ToString() == "http://localhost:8080/")) ); }
public void RunForTest() { Schedule schedule = new Schedule(); EventSpy requiredEvent = new EventSpy(); EventSpy requiredEvent2 = new EventSpy(); EventSpy forbiddenEvent = new EventSpy(); schedule.Add(forbiddenEvent, 300); schedule.Add(requiredEvent, 100); schedule.Add(requiredEvent2, 200); Assert.IsTrue(schedule.RunFor(250)); Assert.IsTrue(requiredEvent.happened); Assert.IsTrue(requiredEvent2.happened); Assert.IsFalse(forbiddenEvent.happened); }