Example #1
0
        public async Task Interceptor_Captures_Async_Exception()
        {
            ApmResult.Clear();
            DependencyReplacement.SetResolver <IQuotientCalculator>(() => new QuotientImplementationFake(ResultTypeEnum.AsyncException));

            // Act
            var response = await ApiClient.PostAsync(CALCULATOR_URL, ContentHelper.GetStringContent(new { dividend = 1, divisor = 999 }));

            response.StatusCode.Should().Be(500);
            var responseBody = await response.Content.ReadAsStringAsync();

            System.Threading.Thread.Sleep(12000);

            // Assert
            responseBody.Should().Contain("System.InvalidOperationException: Fake Async exception");
            ApmResult.Transactions.Should().HaveCount(1);
            ApmResult.Transactions.First().Name.Should().Be("POST Calculator/Division");
            ApmResult.Spans.Should().HaveCount(2);

            ApmResult.Spans[1].Name.Should().Be("CalculatorService.Quotient");
            ApmResult.Spans[1].Outcome.Should().Be(Outcome.Failure);
            ApmResult.Spans[1].TryGetLabel <string>("AsyncTask", out var label).Should().BeTrue();
            label.Should().Be("Faulted");

            ApmResult.Errors.Should().HaveCount(1);
            ApmResult.Errors.First().Exception.Type.Should().Be("System.InvalidOperationException");
        }
Example #2
0
        public async Task Interceptor_Captures_Async_Success()
        {
            ApmResult.Clear();
            DependencyReplacement.SetResolver <IQuotientCalculator>(() => new QuotientImplementationFake(ResultTypeEnum.SyncSuccess));

            // Act
            var response = await ApiClient.PostAsync(CALCULATOR_URL, ContentHelper.GetStringContent(new { dividend = 1, divisor = 100 }));

            response.EnsureSuccessStatusCode();
            var responseBody = await response.Content.ReadAsStringAsync();

            System.Threading.Thread.Sleep(2000);

            // Assert
            responseBody.Should().Be("{\"quotient\":0}");
            ApmResult.Transactions.Should().HaveCount(1);
            ApmResult.Transactions.First().Name.Should().Be("POST Calculator/Division");
            ApmResult.Spans.Should().HaveCount(2);
            ApmResult.Spans[0].Name.Should().Be("ValidationService.IsValidDivision");
            ApmResult.Spans[0].Outcome.Should().Be(Outcome.Success);

            ApmResult.Spans[1].Name.Should().Be("CalculatorService.Quotient");
            ApmResult.Spans[1].Outcome.Should().Be(Outcome.Success);
            ApmResult.Errors.Should().HaveCount(0);
        }