public TestClientWithCredentials(Uri uri, TokenCredential credential, TestClientOptions options) : base(uri, options) { if (credential == null) { throw new ArgumentNullException(nameof(credential)); } Credential = credential; }
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)); }
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); }
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); }
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); }
public TestClient(string connectionString, TestClientOptions options) { if (connectionString == "throw") { throw new ArgumentException("Throwing"); } ConnectionString = connectionString; Options = options; }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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) { }
public TestClient(CompositeObject composite, TestClientOptions options) { Composite = composite; Options = options; }
public TestClient(Uri uri, CompositeObject composite, TestClientOptions options) { Uri = uri; Composite = composite; Options = options; }
public TestClient(Uri uri, TestClientOptions options) { Uri = uri; Options = options; }
public TestClient(Guid guid, TestClientOptions options) { Guid = guid; Options = options; }