Beispiel #1
0
        public void WithGoogleRequestParam()
        {
            CallSettings syncCallSettings  = null;
            CallSettings asyncCallSettings = null;
            var          call0             = new ApiCall <SimpleRequest, SimpleResponse>(
                (req, cs) => { asyncCallSettings = cs; return(null); },
                (req, cs) => { syncCallSettings = cs; return(null); },
                null);

            var call1 = call0.WithGoogleRequestParam("parent", request => request.Name);

            call1.Sync(new SimpleRequest {
                Name = "test"
            }, null);
            call1.Async(new SimpleRequest {
                Name = "test"
            }, null);

            CallSettingsTest.AssertSingleHeader(syncCallSettings, CallSettings.RequestParamsHeader, "parent=test");
            CallSettingsTest.AssertSingleHeader(asyncCallSettings, CallSettings.RequestParamsHeader, "parent=test");
        }
        public void WithExtractedGoogleRequestParam_MultipleFields(string tableNameValue, string appProfileIdValue, string subName, string expectedHeader)
        {
            CallSettings syncCallSettings  = null;
            CallSettings asyncCallSettings = null;
            var          call0             = new ApiServerStreamingCall <ApiCallTest.ExtractedRequestParamRequest, SimpleResponse>(
                "Method",
                (req, cs) => { asyncCallSettings = cs; return(null); },
                (req, cs) => { syncCallSettings = cs; return(null); },
                null);

            // call corresponding to the following routing parameters:
            // { field: "table_name", path_template: "{project_id=projects/*}/**" }
            // { field: "sub_name", path_template: "subs/{sub.sub_name}" }
            // { field: "app_profile_id", path_template: "{legacy.routing_id=**}" }
            var call1 = call0
                        .WithExtractedGoogleRequestParam(
                new RoutingHeaderExtractor <ApiCallTest.ExtractedRequestParamRequest>()
                .WithExtractedParameter("project_id",
                                        "^(projects/[^/]+)(?:/.*)?$", request => request.TableName)
                .WithExtractedParameter("sub_name",
                                        "^subs/([^/]+)/?$", request => request.Sub.TableName)
                .WithExtractedParameter("legacy.routing_id",
                                        "^(.*)$", request => request.AppProfileId));
            var request = new ApiCallTest.ExtractedRequestParamRequest
            {
                TableName = tableNameValue, AppProfileId = appProfileIdValue,
                Sub       = new ApiCallTest.ExtractedRequestParamRequest {
                    TableName = subName
                }
            };

            call1.Call(request, null);
            call1.CallAsync(request, null);

            CallSettingsTest.AssertRoutingHeader(syncCallSettings, expectedHeader);
            CallSettingsTest.AssertRoutingHeader(asyncCallSettings, expectedHeader);
        }
Beispiel #3
0
        public void WithGoogleRequestParam()
        {
            CallSettings syncCallSettings  = null;
            CallSettings asyncCallSettings = null;
            var          call0             = new ApiCall <SimpleRequest, SimpleResponse>(
                "Method",
                (req, cs) => { asyncCallSettings = cs; return(null); },
                (req, cs) => { syncCallSettings = cs; return(null); },
                null);

            var call1 = call0.WithGoogleRequestParam("parent", request => request.Name);

            call1.Sync(new SimpleRequest {
                Name = "test"
            }, null);
            call1.Async(new SimpleRequest {
                Name = "test"
            }, null);

            var expectedHeader = "parent=test";

            CallSettingsTest.AssertRoutingHeader(syncCallSettings, expectedHeader);
            CallSettingsTest.AssertRoutingHeader(asyncCallSettings, expectedHeader);
        }