예제 #1
0
 public void BeginScope_NoTrace_ScopeIsNull()
 {
     using (var scope = TimeTrace.BeginScope("TestScope"))
     {
         scope.Should().BeNull();
     }
 }
예제 #2
0
        public void BeginScope_NameIsNullEmptyOrWhiteSpace_ThrowsException(string name)
        {
            Action act = () => TimeTrace.BeginScope(name);

            var exception = act.Should().Throw <ArgumentException>();

            exception.Which.ParamName.Should().Be("name");
        }
예제 #3
0
 public void BeginScope_TraceExists_ScopeIsCreatedWithCorrectName()
 {
     using (var trace = new TimeTrace())
     {
         using (var scope = TimeTrace.BeginScope("Foo"))
         {
             scope.Should().NotBeNull();
             scope.Name.Should().Be("Foo");
         }
     }
 }
예제 #4
0
        public void Scope_Disposed_MetricsAddedToTrace()
        {
            using (var trace = new TimeTrace())
            {
                using (var scope = TimeTrace.BeginScope("Foo"))
                {
                    Thread.Sleep(500);
                }

                var metric = trace.Metrics.Single();

                metric.Count.Should().Be(1);
                metric.TotalDuration.Should().BeCloseTo(TimeSpan.FromMilliseconds(500), precision: 1);
            }
        }
예제 #5
0
        public void Scope_NestedScope_NamedCorrectly()
        {
            using (var trace = new TimeTrace())
            {
                using (var scope1 = TimeTrace.BeginScope("Foo"))
                {
                    scope1.Name.Should().Be("Foo");

                    using (var scope2 = TimeTrace.BeginScope("Bar"))
                        using (var scope3 = TimeTrace.BeginScope("Baz"))
                        {
                            scope2.Name.Should().Be("Foo/Bar");
                            scope3.Name.Should().Be("Foo/Bar/Baz");
                        }

                    using (var scope4 = TimeTrace.BeginScope("Ping"))
                    {
                        scope4.Name.Should().Be("Foo/Ping");
                    }
                }
            }
        }