public void DefaultTransportIsHttpWebRequestTransport()
        {
            var options = new TestClientOptions();

            Assert.IsInstanceOf <HttpWebRequestTransport>(options.Transport);
            Assert.IsFalse(options.IsCustomTransportSet);
        }
示例#2
0
 public async Task HasValidVersion()
 {
     var testClientOptions = new TestClientOptions(_version)
     {
         Transport = new MockTransport(new MockResponse(200))
     };
     var client = InstrumentClient(new TestClient(InstrumentClientOptions(testClientOptions)));
     await client.GetAsync(default);
        public void IsCustomTransportSetIsTrueAfterCallingTransportSetter()
        {
            var options = new TestClientOptions();

            options.Transport = new MockTransport();

            Assert.IsTrue(options.IsCustomTransportSet);
        }
        public void GlobalConfigurationIsApplied(Func <ClientOptions, object> set, Func <ClientOptions, object> get)
        {
            var initial     = get(Core.ClientOptions.Default);
            var expected    = set(Core.ClientOptions.Default);
            var testOptions = new TestClientOptions();

            Assert.AreNotEqual(initial, expected);
            Assert.AreEqual(expected, get(testOptions));
        }
        public void UsesDefaultApplicationId()
        {
            try
            {
                DiagnosticsOptions.DefaultApplicationId = "Global-application-id";

                var testOptions = new TestClientOptions();
                Assert.AreEqual("Global-application-id", testOptions.Diagnostics.ApplicationId);
            }
            finally
            {
                DiagnosticsOptions.DefaultApplicationId = null;
            }
        }
        public void CanDisableTelemetryWithEnvironmentVariable(string value)
        {
            try
            {
                Environment.SetEnvironmentVariable("AZURE_TELEMETRY_DISABLED", value);

                Core.ClientOptions.ResetDefaultOptions();

                var testOptions = new TestClientOptions();
                Assert.False(testOptions.Diagnostics.IsTelemetryEnabled);
            }
            finally
            {
                Environment.SetEnvironmentVariable("AZURE_TELEMETRY_DISABLED", null);
            }
        }
        public void CanDisableDistributedTracingWithEnvironmentVariable(string value)
        {
            try
            {
                Environment.SetEnvironmentVariable("AZURE_TRACING_DISABLED", value);

                Core.ClientOptions.ResetDefaultOptions();

                var testOptions = new TestClientOptions();
                Assert.False(testOptions.Diagnostics.IsDistributedTracingEnabled);
            }
            finally
            {
                Environment.SetEnvironmentVariable("AZURE_TRACING_DISABLED", null);
            }
        }
示例#8
0
        public void DefaultTransportIsHttpClientTransportIfSwitchIsSet()
        {
            AppContext.TryGetSwitch("Azure.Core.Pipeline.DisableHttpWebRequestTransport", out bool oldSwitch);

            try
            {
                AppContext.SetSwitch("Azure.Core.Pipeline.DisableHttpWebRequestTransport", true);

                var options = new TestClientOptions();

                Assert.IsInstanceOf <HttpClientTransport>(options.Transport);
            }
            finally
            {
                AppContext.SetSwitch("Azure.Core.Pipeline.DisableHttpWebRequestTransport", oldSwitch);
            }
        }
示例#9
0
        public void DefaultTransportIsHttpClientTransportIfEnvVarSet()
        {
            string oldValue = Environment.GetEnvironmentVariable("AZURE_CORE_DISABLE_HTTPWEBREQUESTTRANSPORT");

            try
            {
                Environment.SetEnvironmentVariable("AZURE_CORE_DISABLE_HTTPWEBREQUESTTRANSPORT", "true");

                var options = new TestClientOptions();

                Assert.IsInstanceOf <HttpClientTransport>(options.Transport);
            }
            finally
            {
                Environment.SetEnvironmentVariable("AZURE_CORE_DISABLE_HTTPWEBREQUESTTRANSPORT", oldValue);
            }
        }
示例#10
0
        private async Task Test(string scenario, Func <Uri, HttpPipeline, Task> test, bool ignoreScenario = false, bool useSimplePipeline = false)
        {
            var scenarioParameter = ignoreScenario ? new string[0] : new[] { scenario };
            var server            = TestServerSession.Start(scenario, _version, false, scenarioParameter);

            try
            {
                var testClientOptions = new TestClientOptions
                {
                    Transport = new HttpClientTransport(server.Server.Client),
                    Retry     = { Delay = TimeSpan.FromMilliseconds(50) },
                };
                testClientOptions.AddPolicy(new CustomClientRequestIdPolicy(), HttpPipelinePosition.PerCall);

                var pipeline = useSimplePipeline
                    ? new HttpPipeline(new HttpClientTransport(server.Server.Client))
                    : HttpPipelineBuilder.Build(testClientOptions);

                await test(server.Host, pipeline);
            }
            catch (Exception ex)
            {
                try
                {
                    await server.DisposeAsync();
                }
                catch (Exception disposeException)
                {
                    throw new AggregateException(ex, disposeException);
                }

                throw;
            }

            await server.DisposeAsync();
        }
示例#11
0
        public void DefaultTransportIsHttpClientTransport()
        {
            var options = new TestClientOptions();

            Assert.IsInstanceOf <HttpClientTransport>(options.Transport);
        }
 public TestRestClient(TestClientOptions exchangeOptions) : base("Test", exchangeOptions)
 {
     Api1           = new TestRestApi1Client(exchangeOptions);
     Api2           = new TestRestApi2Client(exchangeOptions);
     RequestFactory = new Mock <IRequestFactory>().Object;
 }
示例#13
0
 public TestClient(TestClientOptions options)
 {
     options ??= new TestClientOptions();
     _diagnostics = new ClientDiagnostics(options);
 }
示例#14
0
 public TestClient(Uri endpoint, TestClientOptions options)
 {
     Uri     = endpoint;
     Options = options;
 }
示例#15
0
 public TestClient(string connectionString, TestClientOptions options)
 {
     ConnectionString = connectionString;
     Options          = options;
 }