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

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

            PublisherAssertions.SingleStatNameIs(publisher, "statOverAsyncAction");
        }
Exemple #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");
        }
Exemple #4
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);
        }
Exemple #5
0
        public static void CanRecordStatInAction()
        {
            var publisher = new FakeStatsPublisher();

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

            PublisherAssertions.SingleStatNameIs(publisher, "statOverAction");
            PublisherAssertions.LastDurationIs(publisher, TimingConstants.DelayMilliseconds);
        }
Exemple #6
0
        public static void DefaultIsToKeepStatName()
        {
            var publisher = new FakeStatsPublisher();

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

            PublisherAssertions.SingleStatNameIs(publisher, "initialStat");
        }
Exemple #7
0
        public static void StatNameCanBeAppended()
        {
            var publisher = new FakeStatsPublisher();

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

            PublisherAssertions.SingleStatNameIs(publisher, "Some.More");
        }
Exemple #8
0
        public static void CanChangeStatNameDuringOperation()
        {
            var publisher = new FakeStatsPublisher();

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

            PublisherAssertions.SingleStatNameIs(publisher, "changedValue");
        }
Exemple #9
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);
        }
Exemple #10
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");
        }
Exemple #11
0
        public static void CanRecordStat()
        {
            var publisher = new FakeStatsPublisher();

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

            PublisherAssertions.SingleStatNameIs(publisher, "stat");
            PublisherAssertions.LastDurationIs(publisher, TimingConstants.DelayMilliseconds);
        }
Exemple #12
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);
        }
Exemple #13
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);
        }
Exemple #14
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);
        }
Exemple #15
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");
        }