Last active
October 10, 2019 08:36
-
-
Save MatthewDavidCampbell/eeff48a82ed7165dff86c6349c265dc8 to your computer and use it in GitHub Desktop.
Provoking non-encoding av NameValueKey pairs in HttpClient with diagnostics
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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<TargetFramework>netcoreapp2.2</TargetFramework> <!-- Switch this to 3.0 and everything works fine --> | |
<IsPackable>false</IsPackable> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" /> | |
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" /> | |
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.8.0" /> | |
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" /> | |
<PackageReference Include="xunit" Version="2.4.0" /> | |
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | |
<PackageReference Include="coverlet.collector" Version="1.0.1" /> | |
</ItemGroup> | |
</Project> |
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
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.TestHost; | |
using Microsoft.Extensions.DependencyInjection; | |
using System; | |
using System.Diagnostics; | |
using System.Net; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using Xunit; | |
namespace BlobingTest | |
{ | |
public class CorrelationContextTests : IClassFixture<TestServerFixture> | |
{ | |
public CorrelationContextTests(TestServerFixture fixture) | |
{ | |
Fixture = fixture; | |
} | |
protected TestServerFixture Fixture { get; } | |
[Fact] | |
public async Task When_InvalidCharacterInCorrelationContext_ItShould_Throw() | |
{ | |
// Arrange | |
var client = new HttpClient(); | |
var activity = new Activity("gary"); | |
// Act | |
activity.AddBaggage("Correlation-Context", "matthew@gmail.com"); | |
activity.Start(); | |
var response = await client.GetAsync("http://www.google.com"); | |
activity.Stop(); | |
// Assert | |
Assert.True(response.StatusCode == HttpStatusCode.OK); | |
} | |
} | |
public class TestServerFixture : IDisposable | |
{ | |
public TestServerFixture() | |
{ | |
Server = new TestServer( | |
new WebHostBuilder() | |
.UseStartup<FakeStartUp>() | |
); | |
} | |
public void Dispose() | |
{ | |
// ... clean up | |
Server.Dispose(); | |
} | |
public TestServer Server { get; private set; } | |
} | |
public class FakeStartUp | |
{ | |
public virtual void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddApplicationInsightsTelemetry(options => | |
{ | |
options.InstrumentationKey = "<secret key>"; | |
}); | |
} | |
public virtual void Configure(IApplicationBuilder app) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment