Esempio n. 1
0
        private async Task SendEmptyResponse(TestHttpClient.Entry entry, HttpStatusCode code = HttpStatusCode.OK)
        {
            var response      = new Autogenerated.GetSecretResponse();
            var streamContent = await GrpcUtils.CreateResponseContent(response);

            entry.Completion.SetResult(GrpcUtils.CreateResponse(code, streamContent));
        }
        public void LoadSecrets_FromSecretStoreThatCanReturnsMultipleValues()
        {
            // Configure Client
            var httpClient = new TestHttpClient()
            {
                Handler = async(entry) =>
                {
                    var secrets = new Dictionary <string, string>()
                    {
                        { "first_secret", "secret1" },
                        { "second_secret", "secret2" }
                    };
                    var secretResponse = new Autogenerated.GetSecretResponse();
                    secretResponse.Data.Add(secrets);

                    var streamContent = await GrpcUtils.CreateResponseContent(secretResponse);

                    var response = GrpcUtils.CreateResponse(HttpStatusCode.OK, streamContent);
                    entry.Completion.SetResult(response);
                }
            };

            var daprClient = new DaprClientBuilder()
                             .UseGrpcChannelOptions(new GrpcChannelOptions {
                HttpClient = httpClient
            })
                             .Build();

            var config = CreateBuilder()
                         .AddDaprSecretStore("store", new DaprSecretDescriptor[] { new DaprSecretDescriptor("secretName") }, daprClient)
                         .Build();

            config["first_secret"].Should().Be("secret1");
            config["second_secret"].Should().Be("secret2");
        }
Esempio n. 3
0
        public void AddDaprSecretStore_DuplicateSecret_ReportsError()
        {
            var httpClient = new TestHttpClient()
            {
                Handler = async(entry) =>
                {
                    var secrets = new Dictionary <string, string>()
                    {
                        { "secretName", "secret" }, { "SecretName", "secret" }
                    };
                    var secretResponse = new Autogenerated.GetSecretResponse();
                    secretResponse.Data.Add(secrets);

                    var streamContent = await GrpcUtils.CreateResponseContent(secretResponse);

                    var response = GrpcUtils.CreateResponse(HttpStatusCode.OK, streamContent);
                    entry.Completion.SetResult(response);
                }
            };

            var daprClient = new DaprClientBuilder()
                             .UseGrpcChannelOptions(new GrpcChannelOptions {
                HttpClient = httpClient
            })
                             .Build();

            var ex = Assert.Throws <InvalidOperationException>(() =>
            {
                var config = CreateBuilder()
                             .AddDaprSecretStore("store", new DaprSecretDescriptor[] { new DaprSecretDescriptor("secretName") }, daprClient)
                             .Build();
            });

            Assert.Contains("Please remove any duplicates from your secret store.", ex.Message);
        }
Esempio n. 4
0
        private async Task <TResponse> SendResponseWithSecrets <TResponse>(Dictionary <string, string> secrets, TestClient <DaprClient> .TestGrpcRequest <TResponse> request)
        {
            var secretResponse = new Autogenerated.GetSecretResponse();

            secretResponse.Data.Add(secrets);

            return(await request.CompleteWithMessageAsync(secretResponse));
        }
Esempio n. 5
0
        private async Task SendResponseWithSecrets(Dictionary <string, string> secrets, TestHttpClient.Entry entry)
        {
            var secretResponse = new Autogenerated.GetSecretResponse();

            secretResponse.Data.Add(secrets);

            var streamContent = await GrpcUtils.CreateResponseContent(secretResponse);

            var response = GrpcUtils.CreateResponse(HttpStatusCode.OK, streamContent);

            entry.Completion.SetResult(response);
        }