Exemple #1
0
        public void SetTransportOptions([Values(true, false)] bool isCustomTransportSet)
        {
            using var testListener = new TestEventListener();
            testListener.EnableEvents(AzureCoreEventSource.Singleton, EventLevel.Verbose);

            var transport = new MockTransport(new MockResponse(503), new MockResponse(200));
            var options   = new TestOptions();

            if (isCustomTransportSet)
            {
                options.Transport = transport;
            }

            List <EventWrittenEventArgs> events = new();

            using var listener = new AzureEventSourceListener(
                      (args, s) =>
            {
                events.Add(args);
            },
                      EventLevel.Verbose);

            var pipeline = HttpPipelineBuilder.Build(
                options,
                Array.Empty <HttpPipelinePolicy>(),
                Array.Empty <HttpPipelinePolicy>(),
                new HttpPipelineTransportOptions(),
                ResponseClassifier.Shared);

            HttpPipelineTransport transportField = pipeline.GetType().GetField("_transport", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField).GetValue(pipeline) as HttpPipelineTransport;

            if (isCustomTransportSet)
            {
                Assert.That(transportField, Is.TypeOf <MockTransport>());
                events.Any(
                    e => e.EventId == 23 &&
                    e.EventName == "PipelineTransportOptionsNotApplied" &&
                    e.GetProperty <string>("optionsType") == options.GetType().FullName);
            }
            else
            {
                Assert.That(transportField, Is.Not.TypeOf <MockTransport>());
            }
        }