forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RequestId to request and response and use it in EventSource (Azur…
- Loading branch information
Showing
11 changed files
with
332 additions
and
87 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
36 changes: 36 additions & 0 deletions
36
src/SDKs/Azure.Base/data-plane/Azure.Base.Tests/MockHttpClientHandler.cs
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,36 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Azure.Base.Tests | ||
{ | ||
internal class MockHttpClientHandler : HttpMessageHandler | ||
{ | ||
private readonly Func<HttpRequestMessage, Task<HttpResponseMessage>> _onSend; | ||
|
||
public MockHttpClientHandler(Action<HttpRequestMessage> onSend) | ||
{ | ||
_onSend = req => { | ||
onSend(req); | ||
return Task.FromResult<HttpResponseMessage>(null); | ||
}; | ||
} | ||
|
||
public MockHttpClientHandler(Func<HttpRequestMessage, Task<HttpResponseMessage>> onSend) | ||
{ | ||
_onSend = onSend; | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
var response = await _onSend(request); | ||
|
||
return response ?? new HttpResponseMessage((HttpStatusCode)200); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/SDKs/Azure.Base/data-plane/Azure.Base.Tests/PipelineTestBase.cs
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.Threading; | ||
using System.Threading.Tasks; | ||
using Azure.Base.Http; | ||
using Azure.Base.Http.Pipeline; | ||
|
||
namespace Azure.Base.Tests | ||
{ | ||
public class PipelineTestBase | ||
{ | ||
protected static async Task<HttpPipelineResponse> ExecuteRequest(HttpPipelineRequest request, HttpClientTransport transport) | ||
{ | ||
using (var message = new HttpPipelineMessage(CancellationToken.None) | ||
{ | ||
Request = request | ||
}) | ||
{ | ||
await transport.ProcessAsync(message); | ||
return message.Response; | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.