private bool IsNotServerLifeCheck(MockTracerAgent.Span span)
        {
            var url = SpanExpectation.GetTag(span, Tags.HttpUrl);

            if (url == null)
            {
                return(true);
            }

            return(!url.Contains("alive-check"));
        }
        protected AspNetCoreMvcTestBase(string sampleAppName, ITestOutputHelper output, string serviceVersion)
            : base(sampleAppName, output)
        {
            ServiceVersion = serviceVersion;
            HttpClient     = new HttpClient();
            HttpClient.DefaultRequestHeaders.Add(HeaderName1, HeaderValue1);
            SetEnvironmentVariable(ConfigurationKeys.HeaderTags, $"{HeaderName1Upper}:{HeaderTagName1}");

            SetServiceVersion(ServiceVersion);

            CreateTopLevelExpectation(url: "/", httpMethod: "GET", httpStatus: "200", resourceUrl: "Home/Index", serviceVersion: ServiceVersion);
            CreateTopLevelExpectation(url: "/delay/0", httpMethod: "GET", httpStatus: "200", resourceUrl: "delay/{seconds}", serviceVersion: ServiceVersion);
            CreateTopLevelExpectation(url: "/api/delay/0", httpMethod: "GET", httpStatus: "200", resourceUrl: "api/delay/{seconds}", serviceVersion: ServiceVersion);
            CreateTopLevelExpectation(url: "/not-found", httpMethod: "GET", httpStatus: "404", resourceUrl: "/not-found", serviceVersion: ServiceVersion);
            CreateTopLevelExpectation(url: "/status-code/203", httpMethod: "GET", httpStatus: "203", resourceUrl: "status-code/{statusCode}", serviceVersion: ServiceVersion);

            CreateTopLevelExpectation(
                url: "/bad-request",
                httpMethod: "GET",
                httpStatus: "500",
                resourceUrl: "bad-request",
                serviceVersion: ServiceVersion,
                additionalCheck: span =>
            {
                var failures = new List <string>();

                if (span.Error == 0)
                {
                    failures.Add($"Expected Error flag set within {span.Resource}");
                }

                if (SpanExpectation.GetTag(span, Tags.ErrorType) != "System.Exception")
                {
                    failures.Add($"Expected specific exception within {span.Resource}");
                }

                var errorMessage = SpanExpectation.GetTag(span, Tags.ErrorMsg);

                if (errorMessage != "This was a bad request.")
                {
                    failures.Add($"Expected specific error message within {span.Resource}. Found \"{errorMessage}\"");
                }

                return(failures);
            });
        }
Example #3
0
        protected List <AspNetCoreMvcSpanExpectation> CreateExpectations(bool addClientIpExpectation)
        {
            return(new List <AspNetCoreMvcSpanExpectation>()
            {
                CreateSingleExpectation(operationName: "home.index", url: "/", httpMethod: "GET", httpStatus: "200", resourceName: "/", addClientIpExpectation),
                CreateSingleExpectation(operationName: "delay/{seconds}", url: "/delay/0", httpMethod: "GET", httpStatus: "200", resourceName: "/delay/?", addClientIpExpectation),
                CreateSingleExpectation(operationName: "api/delay/{seconds}", url: "/api/delay/0", httpMethod: "GET", httpStatus: "200", resourceName: "/api/delay/?", addClientIpExpectation),
                CreateSingleExpectation(operationName: "/not-found", url: "/not-found", httpMethod: "GET", httpStatus: "404", resourceName: "/not-found", addClientIpExpectation),
                CreateSingleExpectation(operationName: "status-code/{statusCode}", url: "/status-code/203", httpMethod: "GET", httpStatus: "203", resourceName: "/status-code/?", addClientIpExpectation),
                CreateSingleExpectation(
                    operationName: "bad-request",
                    url: "/bad-request",
                    httpMethod: "GET",
                    httpStatus: "500",
                    resourceName: "/bad-request",
                    addClientIpExpectation,
                    additionalCheck: span =>
                {
                    var failures = new List <string>();

                    if (span.Error == 0)
                    {
                        failures.Add($"Expected Error flag set within {span.Resource}");
                    }

                    if (SpanExpectation.GetTag(span, Tags.ErrorKind) != "System.Exception")
                    {
                        failures.Add($"Expected specific exception within {span.Resource}");
                    }

                    var errorMessage = SpanExpectation.GetTag(span, Tags.ErrorMsg);

                    if (errorMessage != "This was a bad request.")
                    {
                        failures.Add($"Expected specific error message within {span.Resource}. Found \"{errorMessage}\"");
                    }

                    return failures;
                }),
            });
        }
        protected AspNetCoreMvcTestBase(string sampleAppName, ITestOutputHelper output)
            : base(sampleAppName, output)
        {
            CreateTopLevelExpectation(url: "/", httpMethod: "GET", httpStatus: "200", resourceUrl: "/");
            CreateTopLevelExpectation(url: "/delay/0", httpMethod: "GET", httpStatus: "200", resourceUrl: "delay/{seconds}");
            CreateTopLevelExpectation(url: "/api/delay/0", httpMethod: "GET", httpStatus: "200", resourceUrl: "api/delay/{seconds}");
            CreateTopLevelExpectation(url: "/status-code/203", httpMethod: "GET", httpStatus: "203", resourceUrl: "status-code/{statusCode}");
            CreateTopLevelExpectation(
                url: "/bad-request",
                httpMethod: "GET",
                httpStatus: null, // TODO: Enable status code tests
                resourceUrl: "bad-request",
                additionalCheck: span =>
            {
                var failures = new List <string>();
                if (SpanExpectation.GetTag(span, Tags.ErrorMsg) != "This was a bad request.")
                {
                    failures.Add($"Expected specific exception within {span.Resource}");
                }

                return(failures);
            });
        }
        protected AspNetCoreMvcTestBase(string sampleAppName, ITestOutputHelper output)
            : base(sampleAppName, output)
        {
            CreateTopLevelExpectation(url: "/", httpMethod: "GET", httpStatus: "200", resourceUrl: "Home/Index");
            CreateTopLevelExpectation(url: "/delay/0", httpMethod: "GET", httpStatus: "200", resourceUrl: "delay/{seconds}");
            CreateTopLevelExpectation(url: "/api/delay/0", httpMethod: "GET", httpStatus: "200", resourceUrl: "api/delay/{seconds}");
            CreateTopLevelExpectation(url: "/not-found", httpMethod: "GET", httpStatus: "404", resourceUrl: "/not-found");
            CreateTopLevelExpectation(url: "/status-code/203", httpMethod: "GET", httpStatus: "203", resourceUrl: "status-code/{statusCode}");
            CreateTopLevelExpectation(
                url: "/bad-request",
                httpMethod: "GET",
                httpStatus: "500",
                resourceUrl: "bad-request",
                additionalCheck: span =>
            {
                var failures = new List <string>();

                if (span.Error == 0)
                {
                    failures.Add($"Expected Error flag set within {span.Resource}");
                }

                if (SpanExpectation.GetTag(span, Tags.ErrorType) != "System.Exception")
                {
                    failures.Add($"Expected specific exception within {span.Resource}");
                }

                var errorMessage = SpanExpectation.GetTag(span, Tags.ErrorMsg);

                if (errorMessage != "This was a bad request.")
                {
                    failures.Add($"Expected specific error message within {span.Resource}. Found \"{errorMessage}\"");
                }

                return(failures);
            });
        }