LRO: PUT 201 fix (#757)
This commit is contained in:
Родитель
28ac5bd4b7
Коммит
6bb68a64a3
|
@ -9,9 +9,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"@microsoft.azure/autorest.testserver": {
|
||||
"version": "2.10.36",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft.azure/autorest.testserver/-/autorest.testserver-2.10.36.tgz",
|
||||
"integrity": "sha512-PznHUcpSnbnZ7lLzw6AhZ1wvOpqMNfipz3OTencgjCb9lWxuCLCFhIr/6TAkhAp8MPUMuVC5s4uWji927MjOgw==",
|
||||
"version": "2.10.37",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft.azure/autorest.testserver/-/autorest.testserver-2.10.37.tgz",
|
||||
"integrity": "sha512-ZSB5eoi/z7Rl9xMqxBVOfiWXecNGnBkAt3GUET6MKdnz2xIoDcypy4caXFvEvAUGj9AZPbh4V2nA5/zw0zFJ9g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"azure-storage": "^2.4.0",
|
||||
|
@ -698,12 +698,12 @@
|
|||
}
|
||||
},
|
||||
"engine.io-client": {
|
||||
"version": "3.4.1",
|
||||
"resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-3.4.1.tgz",
|
||||
"integrity": "sha512-RJNmA+A9Js+8Aoq815xpGAsgWH1VoSYM//2VgIiu9lNOaHFfLpTjH4tOzktBpjIs5lvOfiNY1dwf+NuU6D38Mw==",
|
||||
"version": "3.4.2",
|
||||
"resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-3.4.2.tgz",
|
||||
"integrity": "sha512-AWjc1Xg06a6UPFOBAzJf48W1UR/qKYmv/ubgSCumo9GXgvL/xGIvo05dXoBL+2NTLMipDI7in8xK61C17L25xg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"component-emitter": "1.2.1",
|
||||
"component-emitter": "~1.3.0",
|
||||
"component-inherit": "0.0.3",
|
||||
"debug": "~4.1.0",
|
||||
"engine.io-parser": "~2.2.0",
|
||||
|
@ -716,6 +716,12 @@
|
|||
"yeast": "0.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"component-emitter": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz",
|
||||
"integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==",
|
||||
"dev": true
|
||||
},
|
||||
"debug": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
||||
|
@ -1969,9 +1975,9 @@
|
|||
}
|
||||
},
|
||||
"socket.io-parser": {
|
||||
"version": "3.4.0",
|
||||
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-3.4.0.tgz",
|
||||
"integrity": "sha512-/G/VOI+3DBp0+DJKW4KesGnQkQPFmUCbA/oO2QGT6CWxU7hLGWqU3tyuzeSK/dqcyeHsQg1vTe9jiZI8GU9SCQ==",
|
||||
"version": "3.4.1",
|
||||
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-3.4.1.tgz",
|
||||
"integrity": "sha512-11hMgzL+WCLWf1uFtHSNvliI++tcRUWdoeYuwIl+Axvwy9z2gQM+7nJyN3STj1tLj5JyIUH8/gpDGxzAlDdi0A==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"component-emitter": "1.2.1",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"description": "package.json intended for in-repo use only, package.json used for publishing is located in src/AutoRest.CSharp.V3/package.json",
|
||||
"devDependencies": {
|
||||
"@autorest/autorest": "https://github.com/Azure/autorest/releases/download/autorest-3.0.6222/autorest-autorest-3.0.6222.tgz",
|
||||
"@microsoft.azure/autorest.testserver": "2.10.36"
|
||||
"@microsoft.azure/autorest.testserver": "2.10.37"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
|
|
|
@ -125,6 +125,7 @@ namespace Azure.Core
|
|||
switch (finalResponse.Status)
|
||||
{
|
||||
case 200:
|
||||
case 201 when _requestMethod == RequestMethod.Put:
|
||||
case 204 when !(_requestMethod == RequestMethod.Put || _requestMethod == RequestMethod.Patch):
|
||||
{
|
||||
_value = async
|
||||
|
|
|
@ -465,7 +465,7 @@ namespace AutoRest.TestServer.Tests
|
|||
{
|
||||
var value = new Product();
|
||||
var operation = await new LrosaDsClient(ClientDiagnostics, pipeline, host).StartPutError201NoProvisioningStatePayloadAsync(value);
|
||||
Assert.ThrowsAsync<RequestFailedException>(async () => await operation.WaitForCompletionAsync().ConfigureAwait(false));
|
||||
Assert.ThrowsAsync(Is.InstanceOf<JsonException>(), async () => await operation.WaitForCompletionAsync().ConfigureAwait(false));
|
||||
});
|
||||
|
||||
[Test]
|
||||
|
@ -473,7 +473,7 @@ namespace AutoRest.TestServer.Tests
|
|||
{
|
||||
var value = new Product();
|
||||
var operation = new LrosaDsClient(ClientDiagnostics, pipeline, host).StartPutError201NoProvisioningStatePayload(value);
|
||||
Assert.Throws<RequestFailedException>(() => WaitForCompletion(operation));
|
||||
Assert.Throws(Is.InstanceOf<JsonException>(), () => WaitForCompletion(operation));
|
||||
});
|
||||
|
||||
[Test]
|
||||
|
@ -1080,6 +1080,28 @@ namespace AutoRest.TestServer.Tests
|
|||
Assert.AreEqual("Succeeded", result.Value.ProvisioningState);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task LROPutInlineComplete201() => Test(async (host, pipeline) =>
|
||||
{
|
||||
var value = new Product();
|
||||
var operation = await new LROsClient(ClientDiagnostics, pipeline, host).StartPut201SucceededAsync(value);
|
||||
var result = await operation.WaitForCompletionAsync().ConfigureAwait(false);
|
||||
Assert.AreEqual("100", result.Value.Id);
|
||||
Assert.AreEqual("foo", result.Value.Name);
|
||||
Assert.AreEqual("Succeeded", result.Value.ProvisioningState);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task LROPutInlineComplete201_Sync() => Test((host, pipeline) =>
|
||||
{
|
||||
var value = new Product();
|
||||
var operation = new LROsClient(ClientDiagnostics, pipeline, host).StartPut201Succeeded(value);
|
||||
var result = WaitForCompletion(operation);
|
||||
Assert.AreEqual("100", result.Value.Id);
|
||||
Assert.AreEqual("foo", result.Value.Name);
|
||||
Assert.AreEqual("Succeeded", result.Value.ProvisioningState);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task LROPutNoHeaderInRetry() => Test(async (host, pipeline) =>
|
||||
{
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -69,6 +69,44 @@ namespace lro
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary> Long running put request, service returns a 201 to the initial request, with an entity that contains ProvisioningState=’Succeeded’. </summary>
|
||||
/// <param name="product"> Product to put. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public virtual async ValueTask<LROsPut201SucceededOperation> StartPut201SucceededAsync(Product product = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var scope = _clientDiagnostics.CreateScope("LROsClient.StartPut201Succeeded");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
var originalResponse = await RestClient.Put201SucceededAsync(product, cancellationToken).ConfigureAwait(false);
|
||||
return new LROsPut201SucceededOperation(_clientDiagnostics, _pipeline, RestClient.CreatePut201SucceededRequest(product).Request, originalResponse);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Long running put request, service returns a 201 to the initial request, with an entity that contains ProvisioningState=’Succeeded’. </summary>
|
||||
/// <param name="product"> Product to put. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public virtual LROsPut201SucceededOperation StartPut201Succeeded(Product product = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var scope = _clientDiagnostics.CreateScope("LROsClient.StartPut201Succeeded");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
var originalResponse = RestClient.Put201Succeeded(product, cancellationToken);
|
||||
return new LROsPut201SucceededOperation(_clientDiagnostics, _pipeline, RestClient.CreatePut201SucceededRequest(product).Request, originalResponse);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Long running put request, service returns a 202 with empty body to first request, returns a 200 with body [{ 'id': '100', 'name': 'foo' }]. </summary>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public virtual async ValueTask<LROsPost202ListOperation> StartPost202ListAsync(CancellationToken cancellationToken = default)
|
||||
|
|
80
test/TestServerProjects/lro/Generated/LROsPut201SucceededOperation.cs
сгенерированный
Normal file
80
test/TestServerProjects/lro/Generated/LROsPut201SucceededOperation.cs
сгенерированный
Normal file
|
@ -0,0 +1,80 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// <auto-generated/>
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Azure;
|
||||
using Azure.Core;
|
||||
using Azure.Core.Pipeline;
|
||||
using lro.Models;
|
||||
|
||||
namespace lro
|
||||
{
|
||||
/// <summary> Long running put request, service returns a 201 to the initial request, with an entity that contains ProvisioningState=’Succeeded’. </summary>
|
||||
public partial class LROsPut201SucceededOperation : Operation<Product>, IOperationSource<Product>
|
||||
{
|
||||
private readonly ArmOperationHelpers<Product> _operation;
|
||||
internal LROsPut201SucceededOperation(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Request request, Response response)
|
||||
{
|
||||
_operation = new ArmOperationHelpers<Product>(this, clientDiagnostics, pipeline, request, response, OperationFinalStateVia.Location, "LROsPut201SucceededOperation");
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public override string Id => _operation.Id;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Product Value => _operation.Value;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HasCompleted => _operation.HasCompleted;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HasValue => _operation.HasValue;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Response GetRawResponse() => _operation.GetRawResponse();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operation.UpdateStatus(cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default) => _operation.UpdateStatusAsync(cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ValueTask<Response<Product>> WaitForCompletionAsync(CancellationToken cancellationToken = default) => _operation.WaitForCompletionAsync(cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ValueTask<Response<Product>> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionAsync(pollingInterval, cancellationToken);
|
||||
|
||||
Product IOperationSource<Product>.CreateResult(Response response, CancellationToken cancellationToken)
|
||||
{
|
||||
using var document = JsonDocument.Parse(response.ContentStream);
|
||||
if (document.RootElement.ValueKind == JsonValueKind.Null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Product.DeserializeProduct(document.RootElement);
|
||||
}
|
||||
}
|
||||
|
||||
async ValueTask<Product> IOperationSource<Product>.CreateResultAsync(Response response, CancellationToken cancellationToken)
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
if (document.RootElement.ValueKind == JsonValueKind.Null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Product.DeserializeProduct(document.RootElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -85,6 +85,57 @@ namespace lro
|
|||
}
|
||||
}
|
||||
|
||||
internal HttpMessage CreatePut201SucceededRequest(Product product)
|
||||
{
|
||||
var message = _pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Put;
|
||||
var uri = new RawRequestUriBuilder();
|
||||
uri.AppendRaw(host, false);
|
||||
uri.AppendPath("/lro/put/201/succeeded", false);
|
||||
request.Uri = uri;
|
||||
request.Headers.Add("Content-Type", "application/json");
|
||||
if (product != null)
|
||||
{
|
||||
using var content = new Utf8JsonRequestContent();
|
||||
content.JsonWriter.WriteObjectValue(product);
|
||||
request.Content = content;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
/// <summary> Long running put request, service returns a 201 to the initial request, with an entity that contains ProvisioningState=’Succeeded’. </summary>
|
||||
/// <param name="product"> Product to put. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response> Put201SucceededAsync(Product product = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var message = CreatePut201SucceededRequest(product);
|
||||
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 201:
|
||||
return message.Response;
|
||||
default:
|
||||
throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Long running put request, service returns a 201 to the initial request, with an entity that contains ProvisioningState=’Succeeded’. </summary>
|
||||
/// <param name="product"> Product to put. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public Response Put201Succeeded(Product product = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var message = CreatePut201SucceededRequest(product);
|
||||
_pipeline.Send(message, cancellationToken);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 201:
|
||||
return message.Response;
|
||||
default:
|
||||
throw _clientDiagnostics.CreateRequestFailedException(message.Response);
|
||||
}
|
||||
}
|
||||
|
||||
internal HttpMessage CreatePost202ListRequest()
|
||||
{
|
||||
var message = _pipeline.CreateMessage();
|
||||
|
|
Загрузка…
Ссылка в новой задаче