From 591f83df50bd3fbeed2c676c551a042a42ab768a Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 14 Apr 2022 09:48:30 +0100 Subject: [PATCH] tests: Added resource name proto test for loose resource pattern validation --- .../ResourceNames/ResourceNames.proto | 12 + .../ResourceNames/ResourceNamesFakes.cs | 7 + ...seValidationPatternMethodAsyncSnippet.g.cs | 41 +++ ...atternMethodRequestObjectAsyncSnippet.g.cs | 44 ++++ ...tionPatternMethodRequestObjectSnippet.g.cs | 43 ++++ ...atternMethodResourceNamesAsyncSnippet.g.cs | 41 +++ ...tionPatternMethodResourceNamesSnippet.g.cs | 40 +++ ...t.LooseValidationPatternMethodSnippet.g.cs | 40 +++ ...nippet_metadata_testing.resourcenames.json | 159 +++++++++++- .../ResourceNamesClientSnippets.g.cs | 89 ++++++- .../ResourceNamesClientTest.g.cs | 104 +++++++- .../ResourceNamesClient.g.cs | 131 +++++++++- .../ResourceNamesResourceNames.g.cs | 239 +++++++++++++++++- 13 files changed, 984 insertions(+), 6 deletions(-) create mode 100644 Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodAsyncSnippet.g.cs create mode 100644 Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodRequestObjectAsyncSnippet.g.cs create mode 100644 Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodRequestObjectSnippet.g.cs create mode 100644 Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodResourceNamesAsyncSnippet.g.cs create mode 100644 Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodResourceNamesSnippet.g.cs create mode 100644 Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodSnippet.g.cs diff --git a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/ResourceNames.proto b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/ResourceNames.proto index ba44169e..8e153bf1 100644 --- a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/ResourceNames.proto +++ b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/ResourceNames.proto @@ -29,6 +29,10 @@ service ResourceNames { rpc WildcardMultiPatternMultipleMethod(WildcardMultiPatternMultiple) returns(Response) { option (google.api.method_signature) = "ref, repeated_ref"; // `name` parameter delibrately missing. } + + rpc LooseValidationPatternMethod(LooseValidationPattern) returns(Response) { + option (google.api.method_signature) = "name"; + } } message SinglePattern { @@ -91,4 +95,12 @@ message WildcardMultiPatternMultiple { repeated string repeated_ref = 3 [(google.api.resource_reference).type = "resourcenames.example.com/WildcardMultiPatternMultiple"]; } +message LooseValidationPattern { + option (google.api.resource) = { + type: "resourcenames.example.com/LooseValidationPattern" + pattern: "parents/{parent_id}/invalid_name/items/{item_id}" + }; + string name = 1; +} + message Response { } diff --git a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/ResourceNamesFakes.cs b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/ResourceNamesFakes.cs index 18b6e4b8..845a9c63 100644 --- a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/ResourceNamesFakes.cs +++ b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/ResourceNamesFakes.cs @@ -35,6 +35,8 @@ public ResourceNamesClient(CallInvoker callInvoker) { } public virtual AsyncUnaryCall WildcardMultiPatternMethodAsync(WildcardMultiPattern request, CallOptions callOptions) => throw new NotImplementedException(); public virtual Response WildcardMultiPatternMultipleMethod(WildcardMultiPatternMultiple request, CallOptions callOptions) => throw new NotImplementedException(); public virtual AsyncUnaryCall WildcardMultiPatternMultipleMethodAsync(WildcardMultiPatternMultiple request, CallOptions callOptions) => throw new NotImplementedException(); + public virtual Response LooseValidationPatternMethod(LooseValidationPattern request, CallOptions callOptions) => throw new NotImplementedException(); + public virtual AsyncUnaryCall LooseValidationPatternMethodAsync(LooseValidationPattern request, CallOptions callOptions) => throw new NotImplementedException(); } } @@ -76,5 +78,10 @@ public partial class WildcardMultiPatternMultiple : ProtoMsgFake RepeatedRef { get; } = new RepeatedField(); } + public partial class LooseValidationPattern : ProtoMsgFake + { + public string Name { get; set; } + } + public partial class Response : ProtoMsgFake { } } diff --git a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodAsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodAsyncSnippet.g.cs new file mode 100644 index 00000000..69eccf6c --- /dev/null +++ b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodAsyncSnippet.g.cs @@ -0,0 +1,41 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated code. DO NOT EDIT! + +namespace Testing.ResourceNames.Snippets +{ + // [START unknown_generated_ResourceNames_LooseValidationPatternMethod_async_flattened] + using System.Threading.Tasks; + using Testing.ResourceNames; + + public sealed partial class GeneratedResourceNamesClientSnippets + { + /// Snippet for LooseValidationPatternMethodAsync + /// + /// This snippet has been automatically generated for illustrative purposes only. + /// It may require modifications to work in your environment. + /// + public async Task LooseValidationPatternMethodAsync() + { + // Create client + ResourceNamesClient resourceNamesClient = await ResourceNamesClient.CreateAsync(); + // Initialize request argument(s) + string name = "parents/[PARENT_ID]/invalid_name/items/[ITEM_ID]"; + // Make the request + Response response = await resourceNamesClient.LooseValidationPatternMethodAsync(name); + } + } + // [END unknown_generated_ResourceNames_LooseValidationPatternMethod_async_flattened] +} diff --git a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodRequestObjectAsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodRequestObjectAsyncSnippet.g.cs new file mode 100644 index 00000000..1feba5d5 --- /dev/null +++ b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodRequestObjectAsyncSnippet.g.cs @@ -0,0 +1,44 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated code. DO NOT EDIT! + +namespace Testing.ResourceNames.Snippets +{ + // [START unknown_generated_ResourceNames_LooseValidationPatternMethod_async] + using System.Threading.Tasks; + using Testing.ResourceNames; + + public sealed partial class GeneratedResourceNamesClientSnippets + { + /// Snippet for LooseValidationPatternMethodAsync + /// + /// This snippet has been automatically generated for illustrative purposes only. + /// It may require modifications to work in your environment. + /// + public async Task LooseValidationPatternMethodRequestObjectAsync() + { + // Create client + ResourceNamesClient resourceNamesClient = await ResourceNamesClient.CreateAsync(); + // Initialize request argument(s) + LooseValidationPattern request = new LooseValidationPattern + { + LooseValidationPatternName = LooseValidationPatternName.FromParentItem("[PARENT_ID]", "[ITEM_ID]"), + }; + // Make the request + Response response = await resourceNamesClient.LooseValidationPatternMethodAsync(request); + } + } + // [END unknown_generated_ResourceNames_LooseValidationPatternMethod_async] +} diff --git a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodRequestObjectSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodRequestObjectSnippet.g.cs new file mode 100644 index 00000000..cd355fab --- /dev/null +++ b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodRequestObjectSnippet.g.cs @@ -0,0 +1,43 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated code. DO NOT EDIT! + +namespace Testing.ResourceNames.Snippets +{ + // [START unknown_generated_ResourceNames_LooseValidationPatternMethod_sync] + using Testing.ResourceNames; + + public sealed partial class GeneratedResourceNamesClientSnippets + { + /// Snippet for LooseValidationPatternMethod + /// + /// This snippet has been automatically generated for illustrative purposes only. + /// It may require modifications to work in your environment. + /// + public void LooseValidationPatternMethodRequestObject() + { + // Create client + ResourceNamesClient resourceNamesClient = ResourceNamesClient.Create(); + // Initialize request argument(s) + LooseValidationPattern request = new LooseValidationPattern + { + LooseValidationPatternName = LooseValidationPatternName.FromParentItem("[PARENT_ID]", "[ITEM_ID]"), + }; + // Make the request + Response response = resourceNamesClient.LooseValidationPatternMethod(request); + } + } + // [END unknown_generated_ResourceNames_LooseValidationPatternMethod_sync] +} diff --git a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodResourceNamesAsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodResourceNamesAsyncSnippet.g.cs new file mode 100644 index 00000000..48d2c1f5 --- /dev/null +++ b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodResourceNamesAsyncSnippet.g.cs @@ -0,0 +1,41 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated code. DO NOT EDIT! + +namespace Testing.ResourceNames.Snippets +{ + // [START unknown_generated_ResourceNames_LooseValidationPatternMethod_async_flattened_resourceNames] + using System.Threading.Tasks; + using Testing.ResourceNames; + + public sealed partial class GeneratedResourceNamesClientSnippets + { + /// Snippet for LooseValidationPatternMethodAsync + /// + /// This snippet has been automatically generated for illustrative purposes only. + /// It may require modifications to work in your environment. + /// + public async Task LooseValidationPatternMethodResourceNamesAsync() + { + // Create client + ResourceNamesClient resourceNamesClient = await ResourceNamesClient.CreateAsync(); + // Initialize request argument(s) + LooseValidationPatternName name = LooseValidationPatternName.FromParentItem("[PARENT_ID]", "[ITEM_ID]"); + // Make the request + Response response = await resourceNamesClient.LooseValidationPatternMethodAsync(name); + } + } + // [END unknown_generated_ResourceNames_LooseValidationPatternMethod_async_flattened_resourceNames] +} diff --git a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodResourceNamesSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodResourceNamesSnippet.g.cs new file mode 100644 index 00000000..dd0f0bfe --- /dev/null +++ b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodResourceNamesSnippet.g.cs @@ -0,0 +1,40 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated code. DO NOT EDIT! + +namespace Testing.ResourceNames.Snippets +{ + // [START unknown_generated_ResourceNames_LooseValidationPatternMethod_sync_flattened_resourceNames] + using Testing.ResourceNames; + + public sealed partial class GeneratedResourceNamesClientSnippets + { + /// Snippet for LooseValidationPatternMethod + /// + /// This snippet has been automatically generated for illustrative purposes only. + /// It may require modifications to work in your environment. + /// + public void LooseValidationPatternMethodResourceNames() + { + // Create client + ResourceNamesClient resourceNamesClient = ResourceNamesClient.Create(); + // Initialize request argument(s) + LooseValidationPatternName name = LooseValidationPatternName.FromParentItem("[PARENT_ID]", "[ITEM_ID]"); + // Make the request + Response response = resourceNamesClient.LooseValidationPatternMethod(name); + } + } + // [END unknown_generated_ResourceNames_LooseValidationPatternMethod_sync_flattened_resourceNames] +} diff --git a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodSnippet.g.cs new file mode 100644 index 00000000..fd844d45 --- /dev/null +++ b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/ResourceNamesClient.LooseValidationPatternMethodSnippet.g.cs @@ -0,0 +1,40 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated code. DO NOT EDIT! + +namespace Testing.ResourceNames.Snippets +{ + // [START unknown_generated_ResourceNames_LooseValidationPatternMethod_sync_flattened] + using Testing.ResourceNames; + + public sealed partial class GeneratedResourceNamesClientSnippets + { + /// Snippet for LooseValidationPatternMethod + /// + /// This snippet has been automatically generated for illustrative purposes only. + /// It may require modifications to work in your environment. + /// + public void LooseValidationPatternMethod() + { + // Create client + ResourceNamesClient resourceNamesClient = ResourceNamesClient.Create(); + // Initialize request argument(s) + string name = "parents/[PARENT_ID]/invalid_name/items/[ITEM_ID]"; + // Make the request + Response response = resourceNamesClient.LooseValidationPatternMethod(name); + } + } + // [END unknown_generated_ResourceNames_LooseValidationPatternMethod_sync_flattened] +} diff --git a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/snippet_metadata_testing.resourcenames.json b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/snippet_metadata_testing.resourcenames.json index a1d54f91..e4eb6156 100644 --- a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/snippet_metadata_testing.resourcenames.json +++ b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.GeneratedSnippets/snippet_metadata_testing.resourcenames.json @@ -1,4 +1,4 @@ -{ +{ "clientLibrary": { "name": "Testing.ResourceNames", "language": "C_SHARP", @@ -1293,6 +1293,161 @@ } }, "origin": "API_DEFINITION" + }, + { + "regionTag": "unknown_generated_ResourceNames_LooseValidationPatternMethod_sync", + "title": "LooseValidationPatternMethodRequestObject", + "description": "Snippet for LooseValidationPatternMethod", + "file": "ResourceNamesClient.LooseValidationPatternMethodRequestObjectSnippet.g.cs", + "language": "C_SHARP", + "clientMethod": { + "shortName": "LooseValidationPatternMethod", + "fullName": "Testing.ResourceNames.ResourceNamesClient.LooseValidationPatternMethod", + "resultType": "Testing.ResourceNames.Response", + "client": { + "shortName": "ResourceNamesClient", + "fullName": "Testing.ResourceNames.ResourceNamesClient" + }, + "method": { + "shortName": "LooseValidationPatternMethod", + "fullName": "testing.resourcenames.ResourceNames.LooseValidationPatternMethod", + "service": { + "shortName": "ResourceNames", + "fullName": "testing.resourcenames.ResourceNames" + } + } + }, + "canonical": true, + "origin": "API_DEFINITION" + }, + { + "regionTag": "unknown_generated_ResourceNames_LooseValidationPatternMethod_async", + "title": "LooseValidationPatternMethodRequestObjectAsync", + "description": "Snippet for LooseValidationPatternMethodAsync", + "file": "ResourceNamesClient.LooseValidationPatternMethodRequestObjectAsyncSnippet.g.cs", + "language": "C_SHARP", + "clientMethod": { + "shortName": "LooseValidationPatternMethodAsync", + "fullName": "Testing.ResourceNames.ResourceNamesClient.LooseValidationPatternMethodAsync", + "async": true, + "resultType": "System.Threading.Tasks.Task", + "client": { + "shortName": "ResourceNamesClient", + "fullName": "Testing.ResourceNames.ResourceNamesClient" + }, + "method": { + "shortName": "LooseValidationPatternMethod", + "fullName": "testing.resourcenames.ResourceNames.LooseValidationPatternMethod", + "service": { + "shortName": "ResourceNames", + "fullName": "testing.resourcenames.ResourceNames" + } + } + }, + "canonical": true, + "origin": "API_DEFINITION" + }, + { + "regionTag": "unknown_generated_ResourceNames_LooseValidationPatternMethod_sync_flattened", + "title": "LooseValidationPatternMethod", + "description": "Snippet for LooseValidationPatternMethod", + "file": "ResourceNamesClient.LooseValidationPatternMethodSnippet.g.cs", + "language": "C_SHARP", + "clientMethod": { + "shortName": "LooseValidationPatternMethod", + "fullName": "Testing.ResourceNames.ResourceNamesClient.LooseValidationPatternMethod", + "resultType": "Testing.ResourceNames.Response", + "client": { + "shortName": "ResourceNamesClient", + "fullName": "Testing.ResourceNames.ResourceNamesClient" + }, + "method": { + "shortName": "LooseValidationPatternMethod", + "fullName": "testing.resourcenames.ResourceNames.LooseValidationPatternMethod", + "service": { + "shortName": "ResourceNames", + "fullName": "testing.resourcenames.ResourceNames" + } + } + }, + "origin": "API_DEFINITION" + }, + { + "regionTag": "unknown_generated_ResourceNames_LooseValidationPatternMethod_async_flattened", + "title": "LooseValidationPatternMethodAsync", + "description": "Snippet for LooseValidationPatternMethodAsync", + "file": "ResourceNamesClient.LooseValidationPatternMethodAsyncSnippet.g.cs", + "language": "C_SHARP", + "clientMethod": { + "shortName": "LooseValidationPatternMethodAsync", + "fullName": "Testing.ResourceNames.ResourceNamesClient.LooseValidationPatternMethodAsync", + "async": true, + "resultType": "System.Threading.Tasks.Task", + "client": { + "shortName": "ResourceNamesClient", + "fullName": "Testing.ResourceNames.ResourceNamesClient" + }, + "method": { + "shortName": "LooseValidationPatternMethod", + "fullName": "testing.resourcenames.ResourceNames.LooseValidationPatternMethod", + "service": { + "shortName": "ResourceNames", + "fullName": "testing.resourcenames.ResourceNames" + } + } + }, + "origin": "API_DEFINITION" + }, + { + "regionTag": "unknown_generated_ResourceNames_LooseValidationPatternMethod_sync_flattened_resourceNames", + "title": "LooseValidationPatternMethodResourceNames", + "description": "Snippet for LooseValidationPatternMethod", + "file": "ResourceNamesClient.LooseValidationPatternMethodResourceNamesSnippet.g.cs", + "language": "C_SHARP", + "clientMethod": { + "shortName": "LooseValidationPatternMethod", + "fullName": "Testing.ResourceNames.ResourceNamesClient.LooseValidationPatternMethod", + "resultType": "Testing.ResourceNames.Response", + "client": { + "shortName": "ResourceNamesClient", + "fullName": "Testing.ResourceNames.ResourceNamesClient" + }, + "method": { + "shortName": "LooseValidationPatternMethod", + "fullName": "testing.resourcenames.ResourceNames.LooseValidationPatternMethod", + "service": { + "shortName": "ResourceNames", + "fullName": "testing.resourcenames.ResourceNames" + } + } + }, + "origin": "API_DEFINITION" + }, + { + "regionTag": "unknown_generated_ResourceNames_LooseValidationPatternMethod_async_flattened_resourceNames", + "title": "LooseValidationPatternMethodResourceNamesAsync", + "description": "Snippet for LooseValidationPatternMethodAsync", + "file": "ResourceNamesClient.LooseValidationPatternMethodResourceNamesAsyncSnippet.g.cs", + "language": "C_SHARP", + "clientMethod": { + "shortName": "LooseValidationPatternMethodAsync", + "fullName": "Testing.ResourceNames.ResourceNamesClient.LooseValidationPatternMethodAsync", + "async": true, + "resultType": "System.Threading.Tasks.Task", + "client": { + "shortName": "ResourceNamesClient", + "fullName": "Testing.ResourceNames.ResourceNamesClient" + }, + "method": { + "shortName": "LooseValidationPatternMethod", + "fullName": "testing.resourcenames.ResourceNames.LooseValidationPatternMethod", + "service": { + "shortName": "ResourceNames", + "fullName": "testing.resourcenames.ResourceNames" + } + } + }, + "origin": "API_DEFINITION" } ] -} \ No newline at end of file +} diff --git a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.Snippets/ResourceNamesClientSnippets.g.cs b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.Snippets/ResourceNamesClientSnippets.g.cs index 67cb3777..17ce05dd 100644 --- a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.Snippets/ResourceNamesClientSnippets.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.Snippets/ResourceNamesClientSnippets.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -975,5 +975,92 @@ public async Task WildcardMultiPatternMultipleMethodResourceNames4Async() Response response = await resourceNamesClient.WildcardMultiPatternMultipleMethodAsync(@ref, repeatedRef); // End snippet } + + /// Snippet for LooseValidationPatternMethod + public void LooseValidationPatternMethodRequestObject() + { + // Snippet: LooseValidationPatternMethod(LooseValidationPattern, CallSettings) + // Create client + ResourceNamesClient resourceNamesClient = ResourceNamesClient.Create(); + // Initialize request argument(s) + LooseValidationPattern request = new LooseValidationPattern + { + LooseValidationPatternName = LooseValidationPatternName.FromParentItem("[PARENT_ID]", "[ITEM_ID]"), + }; + // Make the request + Response response = resourceNamesClient.LooseValidationPatternMethod(request); + // End snippet + } + + /// Snippet for LooseValidationPatternMethodAsync + public async Task LooseValidationPatternMethodRequestObjectAsync() + { + // Snippet: LooseValidationPatternMethodAsync(LooseValidationPattern, CallSettings) + // Additional: LooseValidationPatternMethodAsync(LooseValidationPattern, CancellationToken) + // Create client + ResourceNamesClient resourceNamesClient = await ResourceNamesClient.CreateAsync(); + // Initialize request argument(s) + LooseValidationPattern request = new LooseValidationPattern + { + LooseValidationPatternName = LooseValidationPatternName.FromParentItem("[PARENT_ID]", "[ITEM_ID]"), + }; + // Make the request + Response response = await resourceNamesClient.LooseValidationPatternMethodAsync(request); + // End snippet + } + + /// Snippet for LooseValidationPatternMethod + public void LooseValidationPatternMethod() + { + // Snippet: LooseValidationPatternMethod(string, CallSettings) + // Create client + ResourceNamesClient resourceNamesClient = ResourceNamesClient.Create(); + // Initialize request argument(s) + string name = "parents/[PARENT_ID]/invalid_name/items/[ITEM_ID]"; + // Make the request + Response response = resourceNamesClient.LooseValidationPatternMethod(name); + // End snippet + } + + /// Snippet for LooseValidationPatternMethodAsync + public async Task LooseValidationPatternMethodAsync() + { + // Snippet: LooseValidationPatternMethodAsync(string, CallSettings) + // Additional: LooseValidationPatternMethodAsync(string, CancellationToken) + // Create client + ResourceNamesClient resourceNamesClient = await ResourceNamesClient.CreateAsync(); + // Initialize request argument(s) + string name = "parents/[PARENT_ID]/invalid_name/items/[ITEM_ID]"; + // Make the request + Response response = await resourceNamesClient.LooseValidationPatternMethodAsync(name); + // End snippet + } + + /// Snippet for LooseValidationPatternMethod + public void LooseValidationPatternMethodResourceNames() + { + // Snippet: LooseValidationPatternMethod(LooseValidationPatternName, CallSettings) + // Create client + ResourceNamesClient resourceNamesClient = ResourceNamesClient.Create(); + // Initialize request argument(s) + LooseValidationPatternName name = LooseValidationPatternName.FromParentItem("[PARENT_ID]", "[ITEM_ID]"); + // Make the request + Response response = resourceNamesClient.LooseValidationPatternMethod(name); + // End snippet + } + + /// Snippet for LooseValidationPatternMethodAsync + public async Task LooseValidationPatternMethodResourceNamesAsync() + { + // Snippet: LooseValidationPatternMethodAsync(LooseValidationPatternName, CallSettings) + // Additional: LooseValidationPatternMethodAsync(LooseValidationPatternName, CancellationToken) + // Create client + ResourceNamesClient resourceNamesClient = await ResourceNamesClient.CreateAsync(); + // Initialize request argument(s) + LooseValidationPatternName name = LooseValidationPatternName.FromParentItem("[PARENT_ID]", "[ITEM_ID]"); + // Make the request + Response response = await resourceNamesClient.LooseValidationPatternMethodAsync(name); + // End snippet + } } } diff --git a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.Tests/ResourceNamesClientTest.g.cs b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.Tests/ResourceNamesClientTest.g.cs index 0e9d2247..118bae24 100644 --- a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.Tests/ResourceNamesClientTest.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames.Tests/ResourceNamesClientTest.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -1170,5 +1170,107 @@ public void WildcardMultiPatternMultipleMethodResourceNames4() xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); } + + [xunit::FactAttribute] + public void LooseValidationPatternMethodRequestObject() + { + moq::Mock mockGrpcClient = new moq::Mock(moq::MockBehavior.Strict); + LooseValidationPattern request = new LooseValidationPattern + { + LooseValidationPatternName = LooseValidationPatternName.FromParentItem("[PARENT_ID]", "[ITEM_ID]"), + }; + Response expectedResponse = new Response { }; + mockGrpcClient.Setup(x => x.LooseValidationPatternMethod(request, moq::It.IsAny())).Returns(expectedResponse); + ResourceNamesClient client = new ResourceNamesClientImpl(mockGrpcClient.Object, null); + Response response = client.LooseValidationPatternMethod(request); + xunit::Assert.Same(expectedResponse, response); + mockGrpcClient.VerifyAll(); + } + + [xunit::FactAttribute] + public async stt::Task LooseValidationPatternMethodRequestObjectAsync() + { + moq::Mock mockGrpcClient = new moq::Mock(moq::MockBehavior.Strict); + LooseValidationPattern request = new LooseValidationPattern + { + LooseValidationPatternName = LooseValidationPatternName.FromParentItem("[PARENT_ID]", "[ITEM_ID]"), + }; + Response expectedResponse = new Response { }; + mockGrpcClient.Setup(x => x.LooseValidationPatternMethodAsync(request, moq::It.IsAny())).Returns(new grpccore::AsyncUnaryCall(stt::Task.FromResult(expectedResponse), null, null, null, null)); + ResourceNamesClient client = new ResourceNamesClientImpl(mockGrpcClient.Object, null); + Response responseCallSettings = await client.LooseValidationPatternMethodAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); + xunit::Assert.Same(expectedResponse, responseCallSettings); + Response responseCancellationToken = await client.LooseValidationPatternMethodAsync(request, st::CancellationToken.None); + xunit::Assert.Same(expectedResponse, responseCancellationToken); + mockGrpcClient.VerifyAll(); + } + + [xunit::FactAttribute] + public void LooseValidationPatternMethod() + { + moq::Mock mockGrpcClient = new moq::Mock(moq::MockBehavior.Strict); + LooseValidationPattern request = new LooseValidationPattern + { + LooseValidationPatternName = LooseValidationPatternName.FromParentItem("[PARENT_ID]", "[ITEM_ID]"), + }; + Response expectedResponse = new Response { }; + mockGrpcClient.Setup(x => x.LooseValidationPatternMethod(request, moq::It.IsAny())).Returns(expectedResponse); + ResourceNamesClient client = new ResourceNamesClientImpl(mockGrpcClient.Object, null); + Response response = client.LooseValidationPatternMethod(request.Name); + xunit::Assert.Same(expectedResponse, response); + mockGrpcClient.VerifyAll(); + } + + [xunit::FactAttribute] + public async stt::Task LooseValidationPatternMethodAsync() + { + moq::Mock mockGrpcClient = new moq::Mock(moq::MockBehavior.Strict); + LooseValidationPattern request = new LooseValidationPattern + { + LooseValidationPatternName = LooseValidationPatternName.FromParentItem("[PARENT_ID]", "[ITEM_ID]"), + }; + Response expectedResponse = new Response { }; + mockGrpcClient.Setup(x => x.LooseValidationPatternMethodAsync(request, moq::It.IsAny())).Returns(new grpccore::AsyncUnaryCall(stt::Task.FromResult(expectedResponse), null, null, null, null)); + ResourceNamesClient client = new ResourceNamesClientImpl(mockGrpcClient.Object, null); + Response responseCallSettings = await client.LooseValidationPatternMethodAsync(request.Name, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); + xunit::Assert.Same(expectedResponse, responseCallSettings); + Response responseCancellationToken = await client.LooseValidationPatternMethodAsync(request.Name, st::CancellationToken.None); + xunit::Assert.Same(expectedResponse, responseCancellationToken); + mockGrpcClient.VerifyAll(); + } + + [xunit::FactAttribute] + public void LooseValidationPatternMethodResourceNames() + { + moq::Mock mockGrpcClient = new moq::Mock(moq::MockBehavior.Strict); + LooseValidationPattern request = new LooseValidationPattern + { + LooseValidationPatternName = LooseValidationPatternName.FromParentItem("[PARENT_ID]", "[ITEM_ID]"), + }; + Response expectedResponse = new Response { }; + mockGrpcClient.Setup(x => x.LooseValidationPatternMethod(request, moq::It.IsAny())).Returns(expectedResponse); + ResourceNamesClient client = new ResourceNamesClientImpl(mockGrpcClient.Object, null); + Response response = client.LooseValidationPatternMethod(request.LooseValidationPatternName); + xunit::Assert.Same(expectedResponse, response); + mockGrpcClient.VerifyAll(); + } + + [xunit::FactAttribute] + public async stt::Task LooseValidationPatternMethodResourceNamesAsync() + { + moq::Mock mockGrpcClient = new moq::Mock(moq::MockBehavior.Strict); + LooseValidationPattern request = new LooseValidationPattern + { + LooseValidationPatternName = LooseValidationPatternName.FromParentItem("[PARENT_ID]", "[ITEM_ID]"), + }; + Response expectedResponse = new Response { }; + mockGrpcClient.Setup(x => x.LooseValidationPatternMethodAsync(request, moq::It.IsAny())).Returns(new grpccore::AsyncUnaryCall(stt::Task.FromResult(expectedResponse), null, null, null, null)); + ResourceNamesClient client = new ResourceNamesClientImpl(mockGrpcClient.Object, null); + Response responseCallSettings = await client.LooseValidationPatternMethodAsync(request.LooseValidationPatternName, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); + xunit::Assert.Same(expectedResponse, responseCallSettings); + Response responseCancellationToken = await client.LooseValidationPatternMethodAsync(request.LooseValidationPatternName, st::CancellationToken.None); + xunit::Assert.Same(expectedResponse, responseCancellationToken); + mockGrpcClient.VerifyAll(); + } } } diff --git a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames/ResourceNamesClient.g.cs b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames/ResourceNamesClient.g.cs index b69cc67e..c000ddfd 100644 --- a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames/ResourceNamesClient.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames/ResourceNamesClient.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -49,6 +49,7 @@ private ResourceNamesSettings(ResourceNamesSettings existing) : base(existing) WildcardOnlyPatternMethodSettings = existing.WildcardOnlyPatternMethodSettings; WildcardMultiPatternMethodSettings = existing.WildcardMultiPatternMethodSettings; WildcardMultiPatternMultipleMethodSettings = existing.WildcardMultiPatternMultipleMethodSettings; + LooseValidationPatternMethodSettings = existing.LooseValidationPatternMethodSettings; OnCopy(existing); } @@ -118,6 +119,19 @@ private ResourceNamesSettings(ResourceNamesSettings existing) : base(existing) /// public gaxgrpc::CallSettings WildcardMultiPatternMultipleMethodSettings { get; set; } = gaxgrpc::CallSettings.FromExpiration(gax::Expiration.None); + /// + /// for synchronous and asynchronous calls to + /// ResourceNamesClient.LooseValidationPatternMethod and + /// ResourceNamesClient.LooseValidationPatternMethodAsync. + /// + /// + /// + /// This call will not be retried. + /// No timeout is applied. + /// + /// + public gaxgrpc::CallSettings LooseValidationPatternMethodSettings { get; set; } = gaxgrpc::CallSettings.FromExpiration(gax::Expiration.None); + /// Creates a deep clone of this object, with all the same property values. /// A deep clone of this object. public ResourceNamesSettings Clone() => new ResourceNamesSettings(this); @@ -1492,6 +1506,90 @@ public virtual Response WildcardMultiPatternMultipleMethod(gax::IResourceName @r /// A Task containing the RPC response. public virtual stt::Task WildcardMultiPatternMultipleMethodAsync(gax::IResourceName @ref, scg::IEnumerable repeatedRef, st::CancellationToken cancellationToken) => WildcardMultiPatternMultipleMethodAsync(@ref, repeatedRef, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken)); + + /// + /// + /// The request object containing all of the parameters for the API call. + /// If not null, applies overrides to this RPC call. + /// The RPC response. + public virtual Response LooseValidationPatternMethod(LooseValidationPattern request, gaxgrpc::CallSettings callSettings = null) => + throw new sys::NotImplementedException(); + + /// + /// + /// The request object containing all of the parameters for the API call. + /// If not null, applies overrides to this RPC call. + /// A Task containing the RPC response. + public virtual stt::Task LooseValidationPatternMethodAsync(LooseValidationPattern request, gaxgrpc::CallSettings callSettings = null) => + throw new sys::NotImplementedException(); + + /// + /// + /// The request object containing all of the parameters for the API call. + /// A to use for this RPC. + /// A Task containing the RPC response. + public virtual stt::Task LooseValidationPatternMethodAsync(LooseValidationPattern request, st::CancellationToken cancellationToken) => + LooseValidationPatternMethodAsync(request, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken)); + + /// + /// + /// + /// + /// If not null, applies overrides to this RPC call. + /// The RPC response. + public virtual Response LooseValidationPatternMethod(string name, gaxgrpc::CallSettings callSettings = null) => + LooseValidationPatternMethod(new LooseValidationPattern { Name = name ?? "", }, callSettings); + + /// + /// + /// + /// + /// If not null, applies overrides to this RPC call. + /// A Task containing the RPC response. + public virtual stt::Task LooseValidationPatternMethodAsync(string name, gaxgrpc::CallSettings callSettings = null) => + LooseValidationPatternMethodAsync(new LooseValidationPattern { Name = name ?? "", }, callSettings); + + /// + /// + /// + /// + /// A to use for this RPC. + /// A Task containing the RPC response. + public virtual stt::Task LooseValidationPatternMethodAsync(string name, st::CancellationToken cancellationToken) => + LooseValidationPatternMethodAsync(name, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken)); + + /// + /// + /// + /// + /// If not null, applies overrides to this RPC call. + /// The RPC response. + public virtual Response LooseValidationPatternMethod(LooseValidationPatternName name, gaxgrpc::CallSettings callSettings = null) => + LooseValidationPatternMethod(new LooseValidationPattern + { + LooseValidationPatternName = name, + }, callSettings); + + /// + /// + /// + /// + /// If not null, applies overrides to this RPC call. + /// A Task containing the RPC response. + public virtual stt::Task LooseValidationPatternMethodAsync(LooseValidationPatternName name, gaxgrpc::CallSettings callSettings = null) => + LooseValidationPatternMethodAsync(new LooseValidationPattern + { + LooseValidationPatternName = name, + }, callSettings); + + /// + /// + /// + /// + /// A to use for this RPC. + /// A Task containing the RPC response. + public virtual stt::Task LooseValidationPatternMethodAsync(LooseValidationPatternName name, st::CancellationToken cancellationToken) => + LooseValidationPatternMethodAsync(name, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken)); } /// ResourceNames client wrapper implementation, for convenient use. @@ -1509,6 +1607,8 @@ public sealed partial class ResourceNamesClientImpl : ResourceNamesClient private readonly gaxgrpc::ApiCall _callWildcardMultiPatternMultipleMethod; + private readonly gaxgrpc::ApiCall _callLooseValidationPatternMethod; + /// /// Constructs a client wrapper for the ResourceNames service, with the specified gRPC client and settings. /// @@ -1534,6 +1634,9 @@ public ResourceNamesClientImpl(ResourceNames.ResourceNamesClient grpcClient, Res _callWildcardMultiPatternMultipleMethod = clientHelper.BuildApiCall(grpcClient.WildcardMultiPatternMultipleMethodAsync, grpcClient.WildcardMultiPatternMultipleMethod, effectiveSettings.WildcardMultiPatternMultipleMethodSettings); Modify_ApiCall(ref _callWildcardMultiPatternMultipleMethod); Modify_WildcardMultiPatternMultipleMethodApiCall(ref _callWildcardMultiPatternMultipleMethod); + _callLooseValidationPatternMethod = clientHelper.BuildApiCall(grpcClient.LooseValidationPatternMethodAsync, grpcClient.LooseValidationPatternMethod, effectiveSettings.LooseValidationPatternMethodSettings); + Modify_ApiCall(ref _callLooseValidationPatternMethod); + Modify_LooseValidationPatternMethodApiCall(ref _callLooseValidationPatternMethod); OnConstruction(grpcClient, effectiveSettings, clientHelper); } @@ -1549,6 +1652,8 @@ public ResourceNamesClientImpl(ResourceNames.ResourceNamesClient grpcClient, Res partial void Modify_WildcardMultiPatternMultipleMethodApiCall(ref gaxgrpc::ApiCall call); + partial void Modify_LooseValidationPatternMethodApiCall(ref gaxgrpc::ApiCall call); + partial void OnConstruction(ResourceNames.ResourceNamesClient grpcClient, ResourceNamesSettings effectiveSettings, gaxgrpc::ClientHelper clientHelper); /// The underlying gRPC ResourceNames client @@ -1564,6 +1669,8 @@ public ResourceNamesClientImpl(ResourceNames.ResourceNamesClient grpcClient, Res partial void Modify_WildcardMultiPatternMultiple(ref WildcardMultiPatternMultiple request, ref gaxgrpc::CallSettings settings); + partial void Modify_LooseValidationPattern(ref LooseValidationPattern request, ref gaxgrpc::CallSettings settings); + /// /// /// The request object containing all of the parameters for the API call. @@ -1673,5 +1780,27 @@ public override Response WildcardMultiPatternMultipleMethod(WildcardMultiPattern Modify_WildcardMultiPatternMultiple(ref request, ref callSettings); return _callWildcardMultiPatternMultipleMethod.Async(request, callSettings); } + + /// + /// + /// The request object containing all of the parameters for the API call. + /// If not null, applies overrides to this RPC call. + /// The RPC response. + public override Response LooseValidationPatternMethod(LooseValidationPattern request, gaxgrpc::CallSettings callSettings = null) + { + Modify_LooseValidationPattern(ref request, ref callSettings); + return _callLooseValidationPatternMethod.Sync(request, callSettings); + } + + /// + /// + /// The request object containing all of the parameters for the API call. + /// If not null, applies overrides to this RPC call. + /// A Task containing the RPC response. + public override stt::Task LooseValidationPatternMethodAsync(LooseValidationPattern request, gaxgrpc::CallSettings callSettings = null) + { + Modify_LooseValidationPattern(ref request, ref callSettings); + return _callLooseValidationPatternMethod.Async(request, callSettings); + } } } diff --git a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames/ResourceNamesResourceNames.g.cs b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames/ResourceNamesResourceNames.g.cs index 114ae350..fa746d9a 100644 --- a/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames/ResourceNamesResourceNames.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/ResourceNames/Testing.ResourceNames/ResourceNamesResourceNames.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -975,6 +975,231 @@ public override string ToString() public static bool operator !=(WildcardMultiPatternMultipleName a, WildcardMultiPatternMultipleName b) => !(a == b); } + /// Resource name for the LooseValidationPattern resource. + public sealed partial class LooseValidationPatternName : gax::IResourceName, sys::IEquatable + { + /// The possible contents of . + public enum ResourceNameType + { + /// An unparsed resource name. + Unparsed = 0, + + /// A resource name with pattern parents/{parent_id}/invalid_name/items/{item_id}. + ParentItem = 1, + } + + private static gax::PathTemplate s_parentItem = new gax::PathTemplate("parents/{parent_id}/invalid_name/items/{item_id}"); + + /// Creates a containing an unparsed resource name. + /// The unparsed resource name. Must not be null. + /// + /// A new instance of containing the provided + /// . + /// + public static LooseValidationPatternName FromUnparsed(gax::UnparsedResourceName unparsedResourceName) => + new LooseValidationPatternName(ResourceNameType.Unparsed, gax::GaxPreconditions.CheckNotNull(unparsedResourceName, nameof(unparsedResourceName))); + + /// + /// Creates a with the pattern + /// parents/{parent_id}/invalid_name/items/{item_id}. + /// + /// The Parent ID. Must not be null or empty. + /// The Item ID. Must not be null or empty. + /// + /// A new instance of constructed from the provided ids. + /// + public static LooseValidationPatternName FromParentItem(string parentId, string itemId) => + new LooseValidationPatternName(ResourceNameType.ParentItem, parentId: gax::GaxPreconditions.CheckNotNullOrEmpty(parentId, nameof(parentId)), itemId: gax::GaxPreconditions.CheckNotNullOrEmpty(itemId, nameof(itemId))); + + /// + /// Formats the IDs into the string representation of this with pattern + /// parents/{parent_id}/invalid_name/items/{item_id}. + /// + /// The Parent ID. Must not be null or empty. + /// The Item ID. Must not be null or empty. + /// + /// The string representation of this with pattern + /// parents/{parent_id}/invalid_name/items/{item_id}. + /// + public static string Format(string parentId, string itemId) => FormatParentItem(parentId, itemId); + + /// + /// Formats the IDs into the string representation of this with pattern + /// parents/{parent_id}/invalid_name/items/{item_id}. + /// + /// The Parent ID. Must not be null or empty. + /// The Item ID. Must not be null or empty. + /// + /// The string representation of this with pattern + /// parents/{parent_id}/invalid_name/items/{item_id}. + /// + public static string FormatParentItem(string parentId, string itemId) => + s_parentItem.Expand(gax::GaxPreconditions.CheckNotNullOrEmpty(parentId, nameof(parentId)), gax::GaxPreconditions.CheckNotNullOrEmpty(itemId, nameof(itemId))); + + /// + /// Parses the given resource name string into a new instance. + /// + /// + /// To parse successfully, the resource name must be formatted as one of the following: + /// + /// parents/{parent_id}/invalid_name/items/{item_id} + /// + /// + /// The resource name in string form. Must not be null. + /// The parsed if successful. + public static LooseValidationPatternName Parse(string looseValidationPatternName) => + Parse(looseValidationPatternName, false); + + /// + /// Parses the given resource name string into a new instance; + /// optionally allowing an unparseable resource name. + /// + /// + /// To parse successfully, the resource name must be formatted as one of the following: + /// + /// parents/{parent_id}/invalid_name/items/{item_id} + /// + /// Or may be in any format if is true. + /// + /// The resource name in string form. Must not be null. + /// + /// If true will successfully store an unparseable resource name into the + /// property; otherwise will throw an if an unparseable resource name is + /// specified. + /// + /// The parsed if successful. + public static LooseValidationPatternName Parse(string looseValidationPatternName, bool allowUnparsed) => + TryParse(looseValidationPatternName, allowUnparsed, out LooseValidationPatternName result) ? result : throw new sys::ArgumentException("The given resource-name matches no pattern."); + + /// + /// Tries to parse the given resource name string into a new instance. + /// + /// + /// To parse successfully, the resource name must be formatted as one of the following: + /// + /// parents/{parent_id}/invalid_name/items/{item_id} + /// + /// + /// The resource name in string form. Must not be null. + /// + /// When this method returns, the parsed , or null if parsing + /// failed. + /// + /// true if the name was parsed successfully; false otherwise. + public static bool TryParse(string looseValidationPatternName, out LooseValidationPatternName result) => + TryParse(looseValidationPatternName, false, out result); + + /// + /// Tries to parse the given resource name string into a new instance; + /// optionally allowing an unparseable resource name. + /// + /// + /// To parse successfully, the resource name must be formatted as one of the following: + /// + /// parents/{parent_id}/invalid_name/items/{item_id} + /// + /// Or may be in any format if is true. + /// + /// The resource name in string form. Must not be null. + /// + /// If true will successfully store an unparseable resource name into the + /// property; otherwise will throw an if an unparseable resource name is + /// specified. + /// + /// + /// When this method returns, the parsed , or null if parsing + /// failed. + /// + /// true if the name was parsed successfully; false otherwise. + public static bool TryParse(string looseValidationPatternName, bool allowUnparsed, out LooseValidationPatternName result) + { + gax::GaxPreconditions.CheckNotNull(looseValidationPatternName, nameof(looseValidationPatternName)); + gax::TemplatedResourceName resourceName; + if (s_parentItem.TryParseName(looseValidationPatternName, out resourceName)) + { + result = FromParentItem(resourceName[0], resourceName[1]); + return true; + } + if (allowUnparsed) + { + if (gax::UnparsedResourceName.TryParse(looseValidationPatternName, out gax::UnparsedResourceName unparsedResourceName)) + { + result = FromUnparsed(unparsedResourceName); + return true; + } + } + result = null; + return false; + } + + private LooseValidationPatternName(ResourceNameType type, gax::UnparsedResourceName unparsedResourceName = null, string itemId = null, string parentId = null) + { + Type = type; + UnparsedResource = unparsedResourceName; + ItemId = itemId; + ParentId = parentId; + } + + /// + /// Constructs a new instance of a class from the component parts of + /// pattern parents/{parent_id}/invalid_name/items/{item_id} + /// + /// The Parent ID. Must not be null or empty. + /// The Item ID. Must not be null or empty. + public LooseValidationPatternName(string parentId, string itemId) : this(ResourceNameType.ParentItem, parentId: gax::GaxPreconditions.CheckNotNullOrEmpty(parentId, nameof(parentId)), itemId: gax::GaxPreconditions.CheckNotNullOrEmpty(itemId, nameof(itemId))) + { + } + + /// The of the contained resource name. + public ResourceNameType Type { get; } + + /// + /// The contained . Only non-null if this instance contains an + /// unparsed resource name. + /// + public gax::UnparsedResourceName UnparsedResource { get; } + + /// + /// The Item ID. Will not be null, unless this instance contains an unparsed resource name. + /// + public string ItemId { get; } + + /// + /// The Parent ID. Will not be null, unless this instance contains an unparsed resource name. + /// + public string ParentId { get; } + + /// Whether this instance contains a resource name with a known pattern. + public bool IsKnownPattern => Type != ResourceNameType.Unparsed; + + /// The string representation of the resource name. + /// The string representation of the resource name. + public override string ToString() + { + switch (Type) + { + case ResourceNameType.Unparsed: return UnparsedResource.ToString(); + case ResourceNameType.ParentItem: return s_parentItem.Expand(ParentId, ItemId); + default: throw new sys::InvalidOperationException("Unrecognized resource-type."); + } + } + + /// Returns a hash code for this resource name. + public override int GetHashCode() => ToString().GetHashCode(); + + /// + public override bool Equals(object obj) => Equals(obj as LooseValidationPatternName); + + /// + public bool Equals(LooseValidationPatternName other) => ToString() == other?.ToString(); + + /// + public static bool operator ==(LooseValidationPatternName a, LooseValidationPatternName b) => ReferenceEquals(a, b) || (a?.Equals(b) ?? false); + + /// + public static bool operator !=(LooseValidationPatternName a, LooseValidationPatternName b) => !(a == b); + } + public partial class SinglePattern { /// @@ -1259,4 +1484,16 @@ public partial class WildcardMultiPatternMultiple }); } } + + public partial class LooseValidationPattern + { + /// + /// -typed view over the resource name property. + /// + public tr::LooseValidationPatternName LooseValidationPatternName + { + get => string.IsNullOrEmpty(Name) ? null : tr::LooseValidationPatternName.Parse(Name, allowUnparsed: true); + set => Name = value?.ToString() ?? ""; + } + } }