public async Task CanRecordStatInAsyncAction() { var publisher = new FakeStatsPublisher(); await publisher.Time("statOverAsyncAction", async() => await DelayAsync()); PublisherAssertions.SingleStatNameIs(publisher, "statOverAsyncAction"); }
public async Task CorrectDurationForStatInAsyncFunction() { var publisher = new FakeStatsPublisher(); await publisher.Time("stat", async() => await DelayedAnswerAsync()); PublisherAssertions.LastDurationIs(publisher, StandardDelayMillis); }
public static void SingleStatNameIs(FakeStatsPublisher publisher, string statName) { Assert.That(publisher.CallCount, Is.EqualTo(1)); Assert.That(publisher.DisposeCount, Is.EqualTo(0)); Assert.That(publisher.BucketNames.Count, Is.EqualTo(1)); Assert.That(publisher.BucketNames[0], Is.EqualTo(statName)); }
public async Task CanRecordStatInAsyncFunction() { var publisher = new FakeStatsPublisher(); var answer = await publisher.Time("statOverAsyncFunc", async() => await DelayedAnswerAsync()); Assert.That(answer, Is.EqualTo(42)); PublisherAssertions.SingleStatNameIs(publisher, "statOverAsyncFunc"); }
public void CanRecordStatInFunction() { var publisher = new FakeStatsPublisher(); var answer = publisher.Time("statOverFunc", () => DelayedAnswer()); Assert.That(answer, Is.EqualTo(42)); PublisherAssertions.SingleStatNameIs(publisher, "statOverFunc"); PublisherAssertions.LastDurationIs(publisher, StandardDelayMillis); }
public void StatWithoutNameAtStartThrows() { var publisher = new FakeStatsPublisher(); Assert.Throws<ArgumentNullException>(() => publisher.StartTimer(string.Empty)); Assert.That(publisher.CallCount, Is.EqualTo(0)); Assert.That(publisher.BucketNames, Is.Empty); }
public void StatWithoutNameAtStartThrows() { var publisher = new FakeStatsPublisher(); Assert.Throws <ArgumentNullException>(() => publisher.StartTimer(string.Empty)); Assert.That(publisher.CallCount, Is.EqualTo(0)); Assert.That(publisher.BucketNames, Is.Empty); }
public void CanRecordStatInAction() { var publisher = new FakeStatsPublisher(); publisher.Time("statOverAction", () => Delay()); PublisherAssertions.SingleStatNameIs(publisher, "statOverAction"); PublisherAssertions.LastDurationIs(publisher, StandardDelayMillis); }
public void DefaultIsToKeepStatName() { var publisher = new FakeStatsPublisher(); using (var timer = publisher.StartTimer("initialStat")) { Delay(); } PublisherAssertions.SingleStatNameIs(publisher, "initialStat"); }
public void ShouldNotDisposePublisherAfterStatSent() { var publisher = new FakeStatsPublisher(); using (publisher.StartTimer("stat")) { Delay(); } Assert.That(publisher.DisposeCount, Is.EqualTo(0)); }
public void CanRecordStat() { var publisher = new FakeStatsPublisher(); using (publisher.StartTimer("stat")) { Delay(); } PublisherAssertions.SingleStatNameIs(publisher, "stat"); PublisherAssertions.LastDurationIs(publisher, StandardDelayMillis); }
public void StatNameCanBeAppended() { var publisher = new FakeStatsPublisher(); using (var timer = publisher.StartTimer("Some.")) { Delay(); timer.StatName += "More"; } PublisherAssertions.SingleStatNameIs(publisher, "Some.More"); }
public async Task CanRecordStatAsync() { var publisher = new FakeStatsPublisher(); using (publisher.StartTimer("statWithAsync")) { await DelayAsync(); } PublisherAssertions.SingleStatNameIs(publisher, "statWithAsync"); PublisherAssertions.LastDurationIs(publisher, StandardDelayMillis); }
public void CanChangeStatNameDuringOperation() { var publisher = new FakeStatsPublisher(); using (var timer = publisher.StartTimer("initialStat")) { Delay(); timer.StatName = "changedValue"; } PublisherAssertions.SingleStatNameIs(publisher, "changedValue"); }
public void StatWithoutNameAtEndThrows() { var publisher = new FakeStatsPublisher(); Assert.Throws <InvalidOperationException>(() => { using (var timer = publisher.StartTimer("valid.Stat")) { Delay(); timer.StatName = null; } }); Assert.That(publisher.CallCount, Is.EqualTo(0)); Assert.That(publisher.BucketNames, Is.Empty); }
public void StatWithoutNameAtEndThrows() { var publisher = new FakeStatsPublisher(); Assert.Throws<InvalidOperationException>(() => { using (var timer = publisher.StartTimer("valid.Stat")) { Delay(); timer.StatName = null; } }); Assert.That(publisher.CallCount, Is.EqualTo(0)); Assert.That(publisher.BucketNames, Is.Empty); }
public async Task CanRecordTwoStatsAsync() { var publisher = new FakeStatsPublisher(); using (publisher.StartTimer("stat1")) { await DelayAsync(); } using (publisher.StartTimer("stat2")) { await DelayAsync(); } Assert.That(publisher.CallCount, Is.EqualTo(2)); Assert.That(publisher.BucketNames, Is.EquivalentTo(new List<string> { "stat1", "stat2" })); PublisherAssertions.LastDurationIs(publisher, StandardDelayMillis); }
public void StatNameIsInitialValueWhenExceptionIsThrown() { var publisher = new FakeStatsPublisher(); var failCount = 0; try { using (var timer = publisher.StartTimer("initialStat")) { Fail(); timer.StatName = "changedValue"; } } catch (Exception) { failCount++; } Assert.That(failCount, Is.EqualTo(1)); PublisherAssertions.SingleStatNameIs(publisher, "initialStat"); }
public async Task CanRecordTwoStatsAsync() { var publisher = new FakeStatsPublisher(); using (publisher.StartTimer("stat1")) { await DelayAsync(); } using (publisher.StartTimer("stat2")) { await DelayAsync(); } Assert.That(publisher.CallCount, Is.EqualTo(2)); Assert.That(publisher.BucketNames, Is.EquivalentTo(new List <string> { "stat1", "stat2" })); PublisherAssertions.LastDurationIs(publisher, StandardDelayMillis); }
public async Task CanRecordStatInAsyncAction() { var publisher = new FakeStatsPublisher(); await publisher.Time("statOverAsyncAction", async () => await DelayAsync()); PublisherAssertions.SingleStatNameIs(publisher, "statOverAsyncAction"); }
public async Task CorrectDurationForStatInAsyncFunction() { var publisher = new FakeStatsPublisher(); await publisher.Time("stat", async () => await DelayedAnswerAsync()); PublisherAssertions.LastDurationIs(publisher, StandardDelayMillis); }
public async Task CanRecordStatInAsyncFunction() { var publisher = new FakeStatsPublisher(); var answer = await publisher.Time("statOverAsyncFunc", async () => await DelayedAnswerAsync()); Assert.That(answer, Is.EqualTo(42)); PublisherAssertions.SingleStatNameIs(publisher, "statOverAsyncFunc"); }
public static void LastDurationIs(FakeStatsPublisher publisher, int expectedMillis) { DurationIsMoreOrLess(publisher.LastDuration, TimeSpan.FromMilliseconds(expectedMillis)); }