-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move RequestOptions and related types to Azure.Core (#24945)
* Move RequestContext and related to Azure.Core * Update sdk/core/Azure.Core/src/ErrorOptions.cs Co-authored-by: tg-msft <tg-msft@users.noreply.github.com> * remove PerCallPolicy and Apply method * update Core API listing * remove Apply() method Co-authored-by: tg-msft <tg-msft@users.noreply.github.com>
- Loading branch information
1 parent
e2c8130
commit c622678
Showing
11 changed files
with
172 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
sdk/core/Azure.Core.Experimental/tests/RequestOptionsTest.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
|
||
namespace Azure | ||
{ | ||
/// <summary> | ||
/// ErrorOptions controls the behavior of an operation when an unexpected response status code is received. | ||
/// </summary> | ||
[Flags] | ||
public enum ErrorOptions | ||
{ | ||
/// <summary> | ||
/// Indicates that an operation should throw an exception when the response indicates a failure. | ||
/// </summary> | ||
Default = 0, | ||
|
||
/// <summary> | ||
/// Indicates that an operation should not throw an exception when the response indicates a failure. | ||
/// Callers should check the Response.IsError property instead of catching exceptions. | ||
/// </summary> | ||
NoThrow = 1, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Threading; | ||
using Azure.Core; | ||
using Azure.Core.Pipeline; | ||
|
||
namespace Azure | ||
{ | ||
/// <summary> | ||
/// Options which can be used to control the behavior of a request sent by a client. | ||
/// </summary> | ||
public class RequestContext | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RequestContext"/> class. | ||
/// </summary> | ||
public RequestContext() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RequestContext"/> class using the given <see cref="ErrorOptions"/>. | ||
/// </summary> | ||
/// <param name="options"></param> | ||
public static implicit operator RequestContext(ErrorOptions options) => new RequestContext { ErrorOptions = options }; | ||
|
||
/// <summary> | ||
/// The token to check for cancellation. | ||
/// </summary> | ||
public CancellationToken CancellationToken { get; set; } = CancellationToken.None; | ||
|
||
/// <summary> | ||
/// Controls under what conditions the operation raises an exception if the underlying response indicates a failure. | ||
/// </summary> | ||
public ErrorOptions ErrorOptions { get; set; } = ErrorOptions.Default; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.Core.Tests | ||
{ | ||
public class RequestContextTests | ||
{ | ||
[Test] | ||
public void CanCastFromErrorOptions() | ||
{ | ||
RequestContext context = ErrorOptions.Default; | ||
|
||
Assert.IsTrue(context.ErrorOptions == ErrorOptions.Default); | ||
} | ||
|
||
[Test] | ||
public void CanSetErrorOptions() | ||
{ | ||
RequestContext context = new RequestContext { ErrorOptions = ErrorOptions.NoThrow }; | ||
|
||
Assert.IsTrue(context.ErrorOptions == ErrorOptions.NoThrow); | ||
} | ||
} | ||
} |