-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update policy copying for clone and convert (#21069)
- Loading branch information
Showing
4 changed files
with
76 additions
and
101 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
sdk/core/Azure.Core/tests/ManagementPipelineBuilderTests.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,56 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading; | ||
using Azure.Core.Pipeline; | ||
using Azure.Core.TestFramework; | ||
using Azure.ResourceManager.Core; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.Core.Tests.Management | ||
{ | ||
public class ManagementPipelineBuilderTests | ||
{ | ||
[TestCase] | ||
public void AddPerCallPolicy() | ||
{ | ||
var options = new ArmClientOptions(); | ||
var dummyPolicy = new DummyPolicy(); | ||
options.AddPolicy(dummyPolicy, HttpPipelinePosition.PerCall); | ||
var pipeline = ManagementPipelineBuilder.Build(new MockCredential(), new Uri("http://foo.com"), options); | ||
|
||
var perCallPolicyField = pipeline.GetType().GetField("_pipeline", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField); | ||
var policies = (ReadOnlyMemory<HttpPipelinePolicy>)perCallPolicyField.GetValue(pipeline); | ||
Assert.IsNotNull(policies.ToArray().FirstOrDefault(p => p.GetType() == typeof(DummyPolicy))); | ||
} | ||
|
||
[TestCase] | ||
public void AddPerCallPolicyViaClient() | ||
{ | ||
var options = new ArmClientOptions(); | ||
var dummyPolicy = new DummyPolicy(); | ||
options.AddPolicy(dummyPolicy, HttpPipelinePosition.PerCall); | ||
var client = new ArmClient(Guid.NewGuid().ToString(), new MockCredential(), options); | ||
|
||
var pipelineProperty = client.GetType().GetProperty("Pipeline", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty); | ||
var pipeline = pipelineProperty.GetValue(client) as HttpPipeline; | ||
|
||
var perCallPolicyField = pipeline.GetType().GetField("_pipeline", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField); | ||
var policies = (ReadOnlyMemory<HttpPipelinePolicy>)perCallPolicyField.GetValue(pipeline); | ||
Assert.IsNotNull(policies.ToArray().FirstOrDefault(p => p.GetType() == typeof(DummyPolicy))); | ||
} | ||
|
||
private class DummyPolicy : HttpPipelineSynchronousPolicy | ||
{ | ||
public int numMsgGot = 0; | ||
|
||
public override void OnReceivedResponse(HttpMessage message) | ||
{ | ||
Interlocked.Increment(ref numMsgGot); | ||
} | ||
} | ||
} | ||
} |
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