Пример #1
0
        public static async Task CorrectDurationForStatInAsyncFunction()
        {
            var publisher = new FakeStatsPublisher();
            await publisher.Time("stat", async t => await DelayedAnswerAsync());

            PublisherAssertions.LastDurationIs(publisher, TimingConstants.DelayMilliseconds);
        }
Пример #2
0
        public static async Task CanRecordStatInAsyncAction()
        {
            var publisher = new FakeStatsPublisher();
            await publisher.Time("statOverAsyncAction", async t => await DelayAsync());

            PublisherAssertions.SingleStatNameIs(publisher, "statOverAsyncAction");
        }
Пример #3
0
        public static async Task CanRecordStatInAsyncFunction()
        {
            var publisher = new FakeStatsPublisher();
            var answer    = await publisher.Time("statOverAsyncFunc", async t => await DelayedAnswerAsync());

            answer.ShouldBe(42);
            PublisherAssertions.SingleStatNameIs(publisher, "statOverAsyncFunc");
        }
        public static void SingleStatNameIs(FakeStatsPublisher publisher, string statName)
        {
            publisher.CallCount.ShouldBe(1);
            publisher.DisposeCount.ShouldBe(0);

            publisher.BucketNames.Count.ShouldBe(1);
            publisher.BucketNames[0].ShouldBe(statName);
        }
Пример #5
0
        public static void StatWithoutNameAtStartThrows()
        {
            var publisher = new FakeStatsPublisher();

            Assert.Throws <ArgumentNullException>(() => publisher.StartTimer(string.Empty));

            publisher.CallCount.ShouldBe(0);
            publisher.BucketNames.ShouldBeEmpty();
        }
Пример #6
0
        public static void CanRecordStatInFunction()
        {
            var publisher = new FakeStatsPublisher();
            var answer    = publisher.Time("statOverFunc", t => DelayedAnswer());

            answer.ShouldBe(42);
            PublisherAssertions.SingleStatNameIs(publisher, "statOverFunc");
            PublisherAssertions.LastDurationIs(publisher, TimingConstants.DelayMilliseconds);
        }
Пример #7
0
        public static void CanRecordStatInAction()
        {
            var publisher = new FakeStatsPublisher();

            publisher.Time("statOverAction", t => Delay());

            PublisherAssertions.SingleStatNameIs(publisher, "statOverAction");
            PublisherAssertions.LastDurationIs(publisher, TimingConstants.DelayMilliseconds);
        }
Пример #8
0
        public static void DefaultIsToKeepStatName()
        {
            var publisher = new FakeStatsPublisher();

            using (var timer = publisher.StartTimer("initialStat"))
            {
                Delay();
            }

            PublisherAssertions.SingleStatNameIs(publisher, "initialStat");
        }
Пример #9
0
        public static void ShouldNotDisposePublisherAfterStatSent()
        {
            var publisher = new FakeStatsPublisher();

            using (publisher.StartTimer("stat"))
            {
                Delay();
            }

            publisher.DisposeCount.ShouldBe(0);
        }
Пример #10
0
        public static async Task CanRecordStatAsync()
        {
            var publisher = new FakeStatsPublisher();

            using (publisher.StartTimer("statWithAsync"))
            {
                await DelayAsync();
            }

            PublisherAssertions.SingleStatNameIs(publisher, "statWithAsync");
            PublisherAssertions.LastDurationIs(publisher, TimingConstants.DelayMilliseconds);
        }
Пример #11
0
        public static void CanRecordStat()
        {
            var publisher = new FakeStatsPublisher();

            using (publisher.StartTimer("stat"))
            {
                Delay();
            }

            PublisherAssertions.SingleStatNameIs(publisher, "stat");
            PublisherAssertions.LastDurationIs(publisher, TimingConstants.DelayMilliseconds);
        }
Пример #12
0
        public static async Task CanChangeStatNameInAsyncFunction()
        {
            var publisher = new FakeStatsPublisher();
            await publisher.Time("defaultName", async t =>
            {
                var result = await DelayedAnswerAsync();
                t.StatName = "afterTheAwait";
                return(result);
            });

            PublisherAssertions.SingleStatNameIs(publisher, "afterTheAwait");
        }
Пример #13
0
        public static void StatNameCanBeAppended()
        {
            var publisher = new FakeStatsPublisher();

            using (var timer = publisher.StartTimer("Some."))
            {
                Delay();
                timer.StatName += "More";
            }

            PublisherAssertions.SingleStatNameIs(publisher, "Some.More");
        }
Пример #14
0
        public static void CanChangeStatNameDuringOperation()
        {
            var publisher = new FakeStatsPublisher();

            using (var timer = publisher.StartTimer("initialStat"))
            {
                Delay();
                timer.StatName = "changedValue";
            }

            PublisherAssertions.SingleStatNameIs(publisher, "changedValue");
        }
Пример #15
0
        public static void CanChangeStatName()
        {
            var publisher = new FakeStatsPublisher();

            using (var timer = publisher.StartTimer("defaultName"))
            {
                Delay();
                timer.StatName = "otherStat";
            }

            PublisherAssertions.SingleStatNameIs(publisher, "otherStat");
            PublisherAssertions.LastDurationIs(publisher, TimingConstants.DelayMilliseconds);
        }
Пример #16
0
        public static void CanChangeStatNameInAction()
        {
            var publisher = new FakeStatsPublisher();

            publisher.Time("defaultName", t =>
            {
                Delay();
                t.StatName = "otherStat";
            });

            PublisherAssertions.SingleStatNameIs(publisher, "otherStat");
            PublisherAssertions.LastDurationIs(publisher, TimingConstants.DelayMilliseconds);
        }
Пример #17
0
        public static void StatWithoutNameAtEndThrows()
        {
            var publisher = new FakeStatsPublisher();

            Assert.Throws <InvalidOperationException>(() =>
            {
                using (var timer = publisher.StartTimer("valid.Stat"))
                {
                    Delay();
                    timer.StatName = null;
                }
            });

            publisher.CallCount.ShouldBe(0);
            publisher.BucketNames.ShouldBeEmpty();
        }
Пример #18
0
        public static async Task CanRecordTwoStatsAsync()
        {
            var publisher = new FakeStatsPublisher();

            using (publisher.StartTimer("stat1"))
            {
                await DelayAsync();
            }

            using (publisher.StartTimer("stat2"))
            {
                await DelayAsync();
            }

            publisher.CallCount.ShouldBe(2);
            publisher.BucketNames.ShouldBe(new[] { "stat1", "stat2" });
            PublisherAssertions.LastDurationIs(publisher, TimingConstants.DelayMilliseconds);
        }
Пример #19
0
        public static void StatNameIsInitialValueWhenExceptionIsThrown()
        {
            var publisher = new FakeStatsPublisher();
            var failCount = 0;

            try
            {
                using (var timer = publisher.StartTimer("initialStat"))
                {
                    Fail();
                    timer.StatName = "changedValue";
                }
            }
            catch (Exception)
            {
                failCount++;
            }

            failCount.ShouldBe(1);
            PublisherAssertions.SingleStatNameIs(publisher, "initialStat");
        }
        public static void StatNameIsInitialValueWhenExceptionIsThrown()
        {
            var publisher = new FakeStatsPublisher();
            var failCount = 0;

            try
            {
                using var timer = publisher.StartTimer("initialStat");

                Fail();

                timer.Bucket = "changedValue";
            }
#pragma warning disable CA1031
            catch (InvalidOperationException)
#pragma warning restore CA1031
            {
                failCount++;
            }

            failCount.ShouldBe(1);
            PublisherAssertions.SingleStatNameIs(publisher, "initialStat");
        }
 public static void LastDurationIs(FakeStatsPublisher publisher, int expectedMillis)
 {
     DurationIsMoreOrLess(publisher.LastDuration, TimeSpan.FromMilliseconds(expectedMillis));
 }