public void CredentialsNotUsedWhenAlreadySet() { var serviceCollection = new ServiceCollection(); var dependencyCredential = GoogleCredential.FromJson(s_serviceAccountJson); serviceCollection.AddSingleton(dependencyCredential); #pragma warning disable CS0618 // Type or member is obsolete Action <FakeBuilder>[] actions = new Action <FakeBuilder>[] { builder => builder.JsonCredentials = "{}", builder => builder.CredentialsPath = "abc", builder => builder.Credential = GoogleCredential.FromJson(s_serviceAccountJson), builder => builder.GoogleCredential = GoogleCredential.FromJson(s_serviceAccountJson), }; #pragma warning restore CS0618 // Type or member is obsolete foreach (var action in actions) { var builder = new FakeBuilder(); action(builder); builder.Configure(serviceCollection); // Note that in one test we'll set the GoogleCredential to a non-null value, but // it won't be the same object. Assert.NotSame(dependencyCredential, builder.GoogleCredential); } }
public void HttpClientFactory_NotSetBefore() { var factory = new HttpClientFactory(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton <IHttpClientFactory>(factory); var builder = new FakeBuilder(); builder.Configure(serviceCollection); Assert.Same(factory, builder.HttpClientFactory); }
public void CredentialsPrecedence_GoogleCredential() { var credential = GoogleCredential.FromJson(s_serviceAccountJson); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(credential); var builder = new FakeBuilder(); builder.Configure(serviceCollection); Assert.Null(builder.Credential); Assert.Same(credential, builder.GoogleCredential); }
public void HttpClientFactory_SetBefore() { var manual = new HttpClientFactory(); var dependency = new HttpClientFactory(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton <IHttpClientFactory>(dependency); var builder = new FakeBuilder { HttpClientFactory = manual }; builder.Configure(serviceCollection); Assert.Same(manual, builder.HttpClientFactory); }