Example #1
0
        public void ShouldInstantiateConfigurationProvider()
        {
            var mockGrpcClient = new Mock <SecretManagerServiceClient>();

            mockGrpcClient
            .Setup(e => e.ListSecretsAsync(new ProjectName(PROJECT_NAME), null, null, null))
            .Returns(new MockPagedEnumerable());


            var secretResponse = new AccessSecretVersionResponse()
            {
                Payload = new SecretPayload {
                    Data = ByteString.FromBase64(System.Convert.ToBase64String(Encoding.UTF8.GetBytes("value")))
                }
            };

            mockGrpcClient
            .Setup(e => e.AccessSecretVersionAsync(new SecretVersionName(PROJECT_NAME, "param1", "latest"), null))
            .Returns(Task.FromResult(secretResponse));

            var configurationOptions = new SecretManagerConfigurationOptions {
                ProjectName = PROJECT_NAME
            };
            var configurationSource = new SecretManagerConfigurationSource(configurationOptions);

            var provider = new SecretManagerConfigurationProvider(mockGrpcClient.Object, configurationSource);

            provider.Load();

            Assert.True(provider.TryGet("param1", out var value));
            Assert.Equal("value", value);
        }
        public void Should_ThrowArgumentNullException_When_ProjectIdIsNull()
        {
            var options = new SecretManagerConfigurationOptions();

            var configurationSource = new SecretManagerConfigurationSource(options, _mockServiceClientHelper.Object);

            Assert.Throws <ArgumentNullException>(() => configurationSource.Build(_mockConfigurationBuilder.Object));
        }
        public void Should_CreateProviderWithoutCredentialPath_When_CredentialsPathIsNull()
        {
            _mockServiceClientHelper.Setup(x => x.Create()).Returns <SecretManagerServiceClient>(null);
            var options = new SecretManagerConfigurationOptions
            {
                ProjectId = "ProjectId"
            };

            var configurationSource = new SecretManagerConfigurationSource(options, _mockServiceClientHelper.Object);
            var provider            = configurationSource.Build(_mockConfigurationBuilder.Object);

            _mockServiceClientHelper.Verify(x => x.Create(), Times.Once);
        }