public void DetectionIsEmulatorOnly_RequiredVariableIsNull(string required2Value)
            {
                var builder     = new FakeBuilder(EmulatorDetection.EmulatorOnly);
                var environment = CreateEnvironmentDictionary(Required1);

                environment[Required2] = required2Value;
                Assert.Throws <InvalidOperationException>(() => builder.GetEmulatorEnvironment(environment));
            }
            public async Task JsonCredentials_Valid()
            {
                var builder = new FakeBuilder(s_scopes, true)
                {
                    JsonCredentials = s_serviceAccountJson
                };

                await AssertCredentialAsync(builder, AssertBasicProperties);
            }
            public void DetectionIsEmulatorOrProduction_AllVariables()
            {
                var builder     = new FakeBuilder(EmulatorDetection.EmulatorOrProduction);
                var environment = CreateEnvironmentDictionary(Required1, Required2, Optional1, Optional2, OtherVariable);
                var result      = builder.GetEmulatorEnvironment(environment);
                var expected    = CreateEnvironmentDictionary(Required1, Required2, Optional1, Optional2);

                Assert.Equal(expected, result);
            }
            public async Task GoogleCredential_Valid()
            {
                var credential = GoogleCredential.FromJson(s_serviceAccountJson);
                var builder    = new FakeBuilder(s_scopes, true)
                {
                    GoogleCredential = credential
                };

                await AssertCredentialAsync(builder, AssertBasicProperties);
            }
Beispiel #5
0
            public void GrpcAdapter_NotSetBefore_SingleNonMatching()
            {
                var serviceCollection = new ServiceCollection();

                serviceCollection.AddRestGrpcAdapter();
                var builder = new FakeBuilder();

                builder.Configure(serviceCollection);
                Assert.Null(builder.GrpcAdapter);
            }
Beispiel #6
0
            public void GrpcAdapter_NotSetBefore_SingleMatching()
            {
                var serviceCollection = new ServiceCollection();

                serviceCollection.AddGrpcNetClientAdapter();
                var builder = new FakeBuilder();

                builder.Configure(serviceCollection);
                Assert.IsType <GrpcNetClientAdapter>(builder.GrpcAdapter);
            }
Beispiel #7
0
            public void GrpcChannelOptions_NotSetBefore()
            {
                var serviceCollection = new ServiceCollection();

                serviceCollection.AddSingleton(GrpcChannelOptions.Empty.WithMaxReceiveMessageSize(10));
                var builder = new FakeBuilder();

                builder.Configure(serviceCollection);
                Assert.Equal(10, builder.GrpcChannelOptions.MaxReceiveMessageSize);
            }
            public void DetectionIsEmulatorOnly_AllVariables_WithAdditionalSettings()
            {
                // With EmulatorOnly, it's invalid to specify credentials etc.
                var builder = new FakeBuilder(EmulatorDetection.EmulatorOnly)
                {
                    CredentialsPath = "foo"
                };
                var environment = CreateEnvironmentDictionary(Required1, Required2, Optional1, Optional2, OtherVariable);

                Assert.Throws <InvalidOperationException>(() => builder.GetEmulatorEnvironment(environment));
            }
Beispiel #9
0
            public void GrpcAdapter_NotSetBefore_MultipleFirstMatchUsed()
            {
                var serviceCollection = new ServiceCollection();

                serviceCollection.AddRestGrpcAdapter();
                serviceCollection.AddGrpcNetClientAdapter();
                var builder = new FakeBuilder();

                builder.Configure(serviceCollection);
                Assert.IsType <GrpcNetClientAdapter>(builder.GrpcAdapter);
            }
            public void DetectionIsEmulatorOnly_NullAndWhitespaceConvertedToNull(string optional2Value)
            {
                var builder     = new FakeBuilder(EmulatorDetection.EmulatorOnly);
                var environment = CreateEnvironmentDictionary(Required1, Required2, Optional1, Optional2);

                environment[Optional2] = optional2Value;
                var result = builder.GetEmulatorEnvironment(environment);

                // null, empty and whitespace are all converted to null in the returned environment.
                Assert.Null(result[Optional2]);
            }
            public async Task UseJwtAccessWithScopesFalse()
            {
                var credential = GoogleCredential.FromJson(s_serviceAccountJson);
                var builder    = new FakeBuilder(s_scopes, false)
                {
                    GoogleCredential = credential
                };

                await AssertCredentialAsync(builder,
                                            credential => Assert.False(((ServiceAccountCredential)credential.UnderlyingCredential).UseJwtAccessWithScopes));
            }
            public async Task QuotaProject()
            {
                var credential = GoogleCredential.FromJson(s_serviceAccountJson);
                var builder    = new FakeBuilder(s_scopes, true)
                {
                    GoogleCredential = credential,
                    QuotaProject     = "quota-project"
                };

                await AssertCredentialAsync(builder,
                                            credential => Assert.Equal("quota-project", ((ServiceAccountCredential)credential.UnderlyingCredential).QuotaProject));
            }
            public void DetectionIsEmulatorOnly_AllRequiredVariables()
            {
                var builder     = new FakeBuilder(EmulatorDetection.EmulatorOnly);
                var environment = CreateEnvironmentDictionary(Required1, Required2, Optional1);
                var result      = builder.GetEmulatorEnvironment(environment);

                var expected = CreateEnvironmentDictionary(Required1, Required2, Optional1, Optional2);

                // The Optional2 key should be present, but with a null value
                expected[Optional2] = null;
                Assert.Equal(expected, result);
            }
Beispiel #14
0
            public void GrpcAdapter_SetBefore()
            {
                var serviceCollection = new ServiceCollection();

                serviceCollection.AddGrpcNetClientAdapter();
                var builder = new FakeBuilder {
                    GrpcAdapter = RestGrpcAdapter.Default
                };

                builder.Configure(serviceCollection);
                Assert.IsType <RestGrpcAdapter>(builder.GrpcAdapter);
            }
Beispiel #15
0
            public void CallInvoker_NotSetBefore()
            {
                var serviceCollection = new ServiceCollection();

                serviceCollection.AddSingleton <CallInvoker>(new FakeCallInvoker());
                serviceCollection.AddGrpcNetClientAdapter();
                var builder = new FakeBuilder();

                builder.Configure(serviceCollection);
                Assert.IsType <FakeCallInvoker>(builder.CallInvoker);
                // Because the CallInvoker was set, nothing else was fetched.
                Assert.Null(builder.GrpcAdapter);
            }
Beispiel #16
0
            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.ChannelCredentials);
                Assert.Null(builder.Credential);
                Assert.Same(credential, builder.GoogleCredential);
            }
Beispiel #17
0
            public void Logger_NotSetBefore()
            {
                var serviceCollection = new ServiceCollection();

                serviceCollection.AddSingleton <CallInvoker>(new FakeCallInvoker());
                serviceCollection.AddLogging(builder => builder.AddProvider(new MemoryLoggerProvider()));
                var builder = new FakeBuilder();

                builder.Configure(serviceCollection);
                // The logger factory and CallInvoker can be injected independently
                Assert.NotNull(builder.Logger);
                Assert.IsType <FakeCallInvoker>(builder.CallInvoker);
            }
            public void DetectionIsEmulatorOrProduction_AllVariables_WithAdditionalSettings()
            {
                // With EmulatorOrProduction, it's valid to specify credentials etc.
                var builder = new FakeBuilder(EmulatorDetection.EmulatorOrProduction)
                {
                    CredentialsPath = "foo"
                };
                var environment = CreateEnvironmentDictionary(Required1, Required2, Optional1, Optional2, OtherVariable);
                var result      = builder.GetEmulatorEnvironment(environment);
                var expected    = CreateEnvironmentDictionary(Required1, Required2, Optional1, Optional2);

                Assert.Equal(expected, result);
            }
Beispiel #19
0
            public void CredentialsPrecedence_ChannelCredentials()
            {
                var serviceCollection = new ServiceCollection();

                serviceCollection.AddSingleton(ChannelCredentials.Insecure);
                serviceCollection.AddSingleton <ICredential>(GoogleCredential.FromJson(s_serviceAccountJson));
                serviceCollection.AddSingleton(GoogleCredential.FromJson(s_serviceAccountJson));
                var builder = new FakeBuilder();

                builder.Configure(serviceCollection);
                Assert.Same(ChannelCredentials.Insecure, builder.ChannelCredentials);
                Assert.Null(builder.Credential);
                Assert.Null(builder.GoogleCredential);
            }
Beispiel #20
0
            public void GrpcChannelOptions_SetBefore()
            {
                var serviceCollection = new ServiceCollection();

                serviceCollection.AddSingleton(GrpcChannelOptions.Empty.WithMaxReceiveMessageSize(10));
                var builder = new FakeBuilder {
                    GrpcChannelOptions = GrpcChannelOptions.Empty.WithMaxSendMessageSize(20)
                };

                builder.Configure(serviceCollection);
                // The manually-set option is present
                Assert.Equal(20, builder.GrpcChannelOptions.MaxSendMessageSize);
                // The injected option isn't present - we don't merge
                Assert.Null(builder.GrpcChannelOptions.MaxReceiveMessageSize);
            }
Beispiel #21
0
            public void Logger_SetBefore()
            {
                var manual            = new MemoryLogger <string>();
                var injected          = new MemoryLogger <string>();
                var serviceCollection = new ServiceCollection();

                serviceCollection.AddSingleton <ILogger <string> >(injected);
                serviceCollection.AddGrpcNetClientAdapter();
                var builder = new FakeBuilder {
                    Logger = manual
                };

                builder.Configure(serviceCollection);
                Assert.Same(manual, builder.Logger);
            }
            public async Task CredentialsPath_Valid()
            {
                var path = Path.GetTempFileName();

                File.WriteAllText(path, s_serviceAccountJson);

                var builder = new FakeBuilder(s_scopes, true)
                {
                    CredentialsPath = path
                };

                await AssertCredentialAsync(builder, AssertBasicProperties);

                File.Delete(path);
            }
Beispiel #23
0
            public void CallInvoker_SetBefore()
            {
                var manual            = new FakeCallInvoker();
                var injected          = new FakeCallInvoker();
                var serviceCollection = new ServiceCollection();

                serviceCollection.AddSingleton <CallInvoker>(injected);
                serviceCollection.AddGrpcNetClientAdapter();
                var builder = new FakeBuilder {
                    CallInvoker = manual
                };

                builder.Configure(serviceCollection);
                Assert.Same(manual, builder.CallInvoker);
                // Because the CallInvoker was set, the gRPC adapter wasn't injected
                Assert.Null(builder.GrpcAdapter);
            }
            private async Task AssertCredentialAsync(FakeBuilder builder, Action <GoogleCredential> assertion)
            {
                var cred1 = builder.GetGoogleCredential();

                assertion(cred1);
                var cred2 = await builder.GetGoogleCredentialAsync(default);