public TestClientWithCredentials(Uri uri, TokenCredential credential, TestClientOptions options) : base(uri, options)
 {
     if (credential == null)
     {
         throw new ArgumentNullException(nameof(credential));
     }
     Credential = credential;
 }
Пример #2
0
        public void FailsToConvertInvalidGuidConfiguration()
        {
            IConfiguration configuration = GetConfiguration(new KeyValuePair <string, string>("guid", "no it its not"));

            var clientOptions = new TestClientOptions();

            Assert.Throws <FormatException>(() => ClientFactory.CreateClient(typeof(TestClient), typeof(TestClientOptions), clientOptions, configuration, null));
        }
Пример #3
0
        public void SelectsConstructorBaseOnConfiguration()
        {
            IConfiguration configuration = GetConfiguration(new KeyValuePair <string, string>("connectionstring", "CS"));

            var clientOptions = new TestClientOptions();
            var client        = (TestClient)ClientFactory.CreateClient(typeof(TestClient), typeof(TestClientOptions), clientOptions, configuration, null);

            Assert.AreEqual("CS", client.ConnectionString);
            Assert.AreSame(clientOptions, client.Options);
        }
Пример #4
0
        public void IgnoresConstructorWhenCredentialsNull()
        {
            IConfiguration configuration = GetConfiguration(new KeyValuePair <string, string>("uri", "http://localhost"));

            var clientOptions = new TestClientOptions();
            var client        = (TestClientWithCredentials)ClientFactory.CreateClient(typeof(TestClientWithCredentials), typeof(TestClientOptions), clientOptions, configuration, null);

            Assert.AreEqual("http://localhost/", client.Uri.ToString());
            Assert.AreSame(clientOptions, client.Options);
        }
Пример #5
0
        public void ConvertsCompositeObjectsConstructorParameters()
        {
            IConfiguration configuration = GetConfiguration(new KeyValuePair <string, string>("composite:c", "http://localhost"));

            var clientOptions = new TestClientOptions();
            var client        = (TestClient)ClientFactory.CreateClient(typeof(TestClient), typeof(TestClientOptions), clientOptions, configuration, null);

            Assert.AreEqual("http://localhost/", client.Composite.C.ToString());
            Assert.AreSame(clientOptions, client.Options);
        }
Пример #6
0
        public TestClient(string connectionString, TestClientOptions options)
        {
            if (connectionString == "throw")
            {
                throw new ArgumentException("Throwing");
            }

            ConnectionString = connectionString;
            Options          = options;
        }
Пример #7
0
        public void ThrowsWhenUnableToReadCompositeObject()
        {
            IConfiguration configuration = GetConfiguration(
                new KeyValuePair <string, string>("composite:non-existent", "_"));

            var clientOptions = new TestClientOptions();
            var exception     = Assert.Throws <InvalidOperationException>(() => ClientFactory.CreateClient(typeof(TestClient), typeof(TestClientOptions), clientOptions, configuration, null));

            Assert.AreEqual("Unable to convert section 'composite' to parameter type 'Azure.Core.Extensions.Tests.TestClient+CompositeObject', unable to find matching constructor.", exception.Message);
        }
Пример #8
0
        public void ConvertsUriConstructorParameters()
        {
            IConfiguration configuration = GetConfiguration(new KeyValuePair <string, string>("uri", "http://localhost"));

            var factory       = new ConfigurationClientFactory();
            var clientOptions = new TestClientOptions();
            var client        = (TestClient)factory.CreateClient(typeof(TestClient), typeof(TestClientOptions), clientOptions, configuration);

            Assert.AreEqual("http://localhost/", client.Uri.ToString());
            Assert.AreSame(clientOptions, client.Options);
        }
Пример #9
0
        public void ConvertsGuidConstructorParameters()
        {
            var            guidValue     = Guid.NewGuid().ToString();
            IConfiguration configuration = GetConfiguration(new KeyValuePair <string, string>("guid", guidValue));

            var clientOptions = new TestClientOptions();
            var client        = (TestClient)ClientFactory.CreateClient(typeof(TestClient), typeof(TestClientOptions), clientOptions, configuration, null);

            Assert.AreEqual(guidValue, client.Guid.ToString());
            Assert.AreSame(clientOptions, client.Options);
        }
Пример #10
0
        public void ThrowsExceptionWithInformationAboutArguments()
        {
            IConfiguration configuration = GetConfiguration();

            var clientOptions = new TestClientOptions();
            var exception     = Assert.Throws <InvalidOperationException>(() => ConfigurationClientFactory.CreateClient(typeof(TestClient), typeof(TestClientOptions), clientOptions, configuration));

            Assert.AreEqual("Unable to find matching constructor. Define one of the follow sets of configuration parameters:" + Environment.NewLine +
                            "1. connectionString" + Environment.NewLine +
                            "2. uri" + Environment.NewLine,
                            exception.Message);
        }
Пример #11
0
        public void ConvertsCompositeObjectsConstructorParameters2()
        {
            IConfiguration configuration = GetConfiguration(
                new KeyValuePair <string, string>("composite:a", "a"),
                new KeyValuePair <string, string>("composite:b", "b"));

            var clientOptions = new TestClientOptions();
            var client        = (TestClient)ClientFactory.CreateClient(typeof(TestClient), typeof(TestClientOptions), clientOptions, configuration, null);

            Assert.AreEqual("a", client.Composite.A);
            Assert.AreEqual("b", client.Composite.B);
            Assert.AreSame(clientOptions, client.Options);
        }
Пример #12
0
        public void UsesLongestConstructor()
        {
            IConfiguration configuration = GetConfiguration(
                new KeyValuePair <string, string>("composite:c", "http://localhost"),
                new KeyValuePair <string, string>("uri", "http://otherhost")
                );

            var clientOptions = new TestClientOptions();
            var client        = (TestClient)ClientFactory.CreateClient(typeof(TestClient), typeof(TestClientOptions), clientOptions, configuration, null);

            Assert.AreEqual("http://localhost/", client.Composite.C.ToString());
            Assert.AreEqual("http://otherhost/", client.Uri.ToString());
            Assert.AreSame(clientOptions, client.Options);
        }
Пример #13
0
        public void GlobalOptionsAppliedToAzureComponentFactoryCreateClientOptions()
        {
            var configuration = GetConfiguration();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => builder.ConfigureDefaults(clientOptions => clientOptions.Diagnostics.ApplicationId = "AppId"));

            ServiceProvider       provider = serviceCollection.BuildServiceProvider();
            AzureComponentFactory factory  = provider.GetService <AzureComponentFactory>();
            TestClientOptions     options  = (TestClientOptions)factory.CreateClientOptions(typeof(TestClientOptions), configuration["TestClient"], null);

            Assert.AreEqual("AppId", options.Diagnostics.ApplicationId);
        }
Пример #14
0
        public void IgnoresNonTokenCredentialConstructors()
        {
            IConfiguration configuration = GetConfiguration(
                new KeyValuePair <string, string>("uri", "http://localhost"),
                new KeyValuePair <string, string>("credential", "managedidentity"),
                new KeyValuePair <string, string>("clientId", "secret")
                );

            var clientOptions = new TestClientOptions();
            var client        = (TestClientWithCredentials)ClientFactory.CreateClient(typeof(TestClientWithCredentials), typeof(TestClientOptions), clientOptions, configuration, new DefaultAzureCredential());

            Assert.AreEqual("http://localhost/", client.Uri.ToString());
            Assert.AreSame(clientOptions, client.Options);
            Assert.NotNull(client.Credential);
        }
Пример #15
0
        public void CanUseAzureSasCredential()
        {
            IConfiguration configuration = GetConfiguration(
                new KeyValuePair <string, string>("uri", "http://localhost"),
                new KeyValuePair <string, string>("credential:signature", "key"),
                new KeyValuePair <string, string>("clientId", "secret")
                );

            var clientOptions = new TestClientOptions();
            var client        = (TestClientWithCredentials)ClientFactory.CreateClient(typeof(TestClientWithCredentials), typeof(TestClientOptions), clientOptions, configuration, new DefaultAzureCredential());

            Assert.AreEqual("http://localhost/", client.Uri.ToString());
            Assert.AreSame(clientOptions, client.Options);
            Assert.AreEqual("key", client.AzureSasCredential.Signature);
        }
Пример #16
0
        public void CanReadClientOptionsFromConfiguration()
        {
            var configuration = GetConfiguration(
                new KeyValuePair <string, string>("TestClient:Property", "client option value"));

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClientsCore();

            ServiceProvider       provider = serviceCollection.BuildServiceProvider();
            AzureComponentFactory factory  = provider.GetService <AzureComponentFactory>();
            TestClientOptions     options  = (TestClientOptions)factory.CreateClientOptions(typeof(TestClientOptions), null, configuration.GetSection("TestClient"));

            Assert.AreEqual("client option value", options.Property);
        }
Пример #17
0
        public void ThrowsExceptionWithInformationAboutArguments()
        {
            IConfiguration configuration = GetConfiguration(
                new KeyValuePair <string, string>("some section:a", "a"),
                new KeyValuePair <string, string>("some section:b:c", "b")
                ).GetSection("some section");

            var clientOptions = new TestClientOptions();
            var exception     = Assert.Throws <InvalidOperationException>(() => ClientFactory.CreateClient(typeof(TestClientWithCredentials), typeof(TestClientOptions), clientOptions, configuration, null));

            Assert.AreEqual("Unable to find matching constructor while trying to create an instance of TestClientWithCredentials." + Environment.NewLine +
                            "Expected one of the follow sets of configuration parameters:" + Environment.NewLine +
                            "1. uri" + Environment.NewLine +
                            "2. uri, credential:key" + Environment.NewLine +
                            "3. uri, credential:signature" + Environment.NewLine +
                            "4. uri" + Environment.NewLine +
                            "" + Environment.NewLine +
                            "Found the following configuration keys: b, b:c, a",
                            exception.Message);
        }
 public TestClientWithCredentials(Uri uri, TokenCredential credential, TestClientOptions options) : base(uri, options)
 {
     Credential = credential;
 }
 public TestClientWithCredentials(Uri uri, TestClientOptions options) : base(uri, options)
 {
 }
Пример #20
0
 public TestClient(CompositeObject composite, TestClientOptions options)
 {
     Composite = composite;
     Options   = options;
 }
Пример #21
0
 public TestClient(Uri uri, CompositeObject composite, TestClientOptions options)
 {
     Uri       = uri;
     Composite = composite;
     Options   = options;
 }
Пример #22
0
 public TestClient(Uri uri, TestClientOptions options)
 {
     Uri     = uri;
     Options = options;
 }
Пример #23
0
 public TestClient(Guid guid, TestClientOptions options)
 {
     Guid    = guid;
     Options = options;
 }