Пример #1
0
        public async Task PayloadSentWithProperUserAgent()
        {
            var isRequestFinished = new TaskCompletionSource <object>();

            HttpHeaderValueCollection <ProductInfoHeaderValue> userAgentHeader = null;
            var handler = new MockHttpMessageHandler((r, c) =>
            {
                userAgentHeader = r.Headers.UserAgent;
                isRequestFinished.SetResult(null);
                return(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)));
            });

            var logger        = new NoopLogger();
            var service       = Service.GetDefaultService(new TestAgentConfigurationReader(logger), logger);
            var payloadSender = new PayloadSenderV2(logger, new TestAgentConfigurationReader(logger),
                                                    service, new Api.System(), handler);

            using (var agent = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender)))
            {
                agent.PayloadSender.QueueTransaction(new Transaction(agent, "TestName", "TestType"));
            }

            await isRequestFinished.Task;

            userAgentHeader
            .Should()
            .NotBeEmpty()
            .And.HaveCount(3);

            userAgentHeader.First().Product.Name.Should().Be($"elasticapm-{Consts.AgentName}");
            userAgentHeader.First().Product.Version.Should().NotBeEmpty();

            userAgentHeader.Skip(1).First().Product.Name.Should().Be("System.Net.Http");
            userAgentHeader.Skip(1).First().Product.Version.Should().NotBeEmpty();

            userAgentHeader.Skip(2).First().Product.Name.Should().NotBeEmpty();
            userAgentHeader.Skip(2).First().Product.Version.Should().NotBeEmpty();
        }
Пример #2
0
        public void Header_classes_expose_headers_in_a_strongly_typed_way()
        {
            var request = new HttpRequestMessage();

            request.Headers.Add(
                "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");

            HttpHeaderValueCollection <MediaTypeWithQualityHeaderValue> accept = request.Headers.Accept;

            Assert.Equal(4, accept.Count);

            MediaTypeWithQualityHeaderValue third = accept.Skip(2).First();

            Assert.Equal("application/xml", third.MediaType);
            Assert.Equal(0.9, third.Quality);
            Assert.Null(third.CharSet);
            Assert.Equal(1, third.Parameters.Count);
            Assert.Equal("q", third.Parameters.First().Name);
            Assert.Equal("0.9", third.Parameters.First().Value);
        }