Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

390625: Move the System.Web.Http.HttpRequestMessageExtensions and Htt…

…pResponseMessageExtensions classes to the System.Net.Http namespace

Also move GetCorrelationId to main request extensions file.
  • Loading branch information...
commit 5391de5efd0fc978fa3b4aac0de2b21a18f6843b 1 parent ca9c37e
@marcind marcind authored
View
1  src/System.Web.Http/Controllers/HttpActionBinding.cs
@@ -2,6 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
+using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.Metadata;
View
1  src/System.Web.Http/GlobalSuppressions.cs
@@ -18,3 +18,4 @@
[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Web.Http.Dependencies", Justification = "Namespace follows folder structure")]
[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Web.Http.Tracing.Tracers", Justification = "Namespace follows folder structure")]
[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Web.Http.Validation.Validators", Justification = "Namespace follows folder structure")]
+[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Net.Http", Justification = "Functionality logically belongs in a namespace defined in a different binary")]
View
29 src/System.Web.Http/HttpRequestMessageExtensions.cs
@@ -1,17 +1,16 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
-using System.Net;
-using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Threading;
+using System.Web.Http;
using System.Web.Http.Dependencies;
using System.Web.Http.Hosting;
using System.Web.Http.Properties;
using System.Web.Http.Routing;
-namespace System.Web.Http
+namespace System.Net.Http
{
/// <summary>
/// Provides extension methods for the <see cref="HttpRequestMessage"/> class.
@@ -353,5 +352,29 @@ public static void DisposeRequestResources(this HttpRequestMessage request)
resourcesToDispose.Clear();
}
}
+
+ /// <summary>
+ /// Retrieves the <see cref="Guid"/> which has been assigned as the
+ /// correlation id associated with the given <paramref name="request"/>.
+ /// The value will be created and set the first time this method is called.
+ /// </summary>
+ /// <param name="request">The <see cref="HttpRequestMessage"/></param>
+ /// <returns>The <see cref="Guid"/> associated with that request.</returns>
+ public static Guid GetCorrelationId(this HttpRequestMessage request)
+ {
+ if (request == null)
+ {
+ throw Error.ArgumentNull("request");
+ }
+
+ Guid correlationId;
+ if (!request.Properties.TryGetValue<Guid>(HttpPropertyKeys.RequestCorrelationKey, out correlationId))
+ {
+ correlationId = Guid.NewGuid();
+ request.Properties.Add(HttpPropertyKeys.RequestCorrelationKey, correlationId);
+ }
+
+ return correlationId;
+ }
}
}
View
4 src/System.Web.Http/HttpResponseMessageExtensions.cs
@@ -1,7 +1,7 @@
using System.ComponentModel;
-using System.Net.Http;
+using System.Web.Http;
-namespace System.Web.Http
+namespace System.Net.Http
{
[EditorBrowsable(EditorBrowsableState.Never)]
public static class HttpResponseMessageExtensions
View
1  src/System.Web.Http/System.Web.Http.csproj
@@ -263,7 +263,6 @@
<DesignTime>True</DesignTime>
<DependentUpon>SRResources.resx</DependentUpon>
</Compile>
- <Compile Include="Tracing\HttpRequestMessageExtensions.cs" />
<Compile Include="Tracing\IFormatterTracer.cs" />
<Compile Include="Tracing\ITraceManager.cs" />
<Compile Include="Tracing\ITraceWriter.cs" />
View
30 src/System.Web.Http/Tracing/HttpRequestMessageExtensions.cs
@@ -1,30 +0,0 @@
-using System.Diagnostics.Contracts;
-using System.Net.Http;
-using System.Web.Http.Hosting;
-
-namespace System.Web.Http.Tracing
-{
- public static class HttpRequestMessageExtensions
- {
- /// <summary>
- /// Retrieves the <see cref="Guid"/> which has been assigned as the
- /// correlation id associated with the given <paramref name="request"/>.
- /// The value will be created and set the first time this method is called.
- /// </summary>
- /// <param name="request">The <see cref="HttpRequestMessage"/></param>
- /// <returns>The <see cref="Guid"/> associated with that request.</returns>
- public static Guid GetCorrelationId(this HttpRequestMessage request)
- {
- Contract.Assert(request != null);
-
- Guid correlationId;
- if (!request.Properties.TryGetValue<Guid>(HttpPropertyKeys.RequestCorrelationKey, out correlationId))
- {
- correlationId = Guid.NewGuid();
- request.Properties.Add(HttpPropertyKeys.RequestCorrelationKey, correlationId);
- }
-
- return correlationId;
- }
- }
-}
View
40 test/System.Web.Http.Test/HttpRequestMessageExtensionsTest.cs
@@ -1,19 +1,17 @@
using System.Collections.Generic;
-using System.Net;
-using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Formatting.Mocks;
using System.Net.Http.Headers;
using System.Threading;
+using System.Web.Http;
using System.Web.Http.Hosting;
using System.Web.Http.Routing;
using System.Web.Http.Services;
-using Microsoft.TestCommon;
using Moq;
using Xunit;
using Assert = Microsoft.TestCommon.AssertEx;
-namespace System.Web.Http
+namespace System.Net.Http
{
public class HttpRequestMessageExtensionsTest
{
@@ -31,15 +29,10 @@ public HttpRequestMessageExtensionsTest()
}
[Fact]
- public void IsCorrectType()
- {
- Assert.Type.HasProperties(typeof(HttpRequestMessageExtensions), TypeAssert.TypeProperties.IsStatic | TypeAssert.TypeProperties.IsPublicVisibleClass);
- }
-
- [Fact]
public void GetConfigurationThrowsOnNull()
{
- Assert.ThrowsArgumentNull(() => HttpRequestMessageExtensions.GetConfiguration(null), "request");
+ HttpRequestMessage request = null;
+ Assert.ThrowsArgumentNull(() => request.GetConfiguration(), "request");
}
[Fact]
@@ -58,7 +51,8 @@ public void GetConfiguration()
[Fact]
public void GetSynchronizationContextThrowsOnNull()
{
- Assert.ThrowsArgumentNull(() => HttpRequestMessageExtensions.GetSynchronizationContext(null), "request");
+ HttpRequestMessage request = null;
+ Assert.ThrowsArgumentNull(() => request.GetSynchronizationContext(), "request");
}
[Fact]
@@ -103,14 +97,15 @@ public void GetRouteData_WhenRequestIsNull_Throws()
[Fact]
public void CreateResponse_DoingConneg_OnNullRequest_ThrowsException()
{
+ HttpRequestMessage request = null;
Assert.ThrowsArgumentNull(() =>
{
- HttpRequestMessageExtensions.CreateResponse(null, HttpStatusCode.OK, _value);
+ request.CreateResponse(HttpStatusCode.OK, _value);
}, "request");
Assert.ThrowsArgumentNull(() =>
{
- HttpRequestMessageExtensions.CreateResponse(null, HttpStatusCode.OK, _value, configuration: null);
+ request.CreateResponse(HttpStatusCode.OK, _value, configuration: null);
}, "request");
}
@@ -121,7 +116,7 @@ public void CreateResponse_DoingConneg_OnNullConfiguration_ThrowsException()
Assert.Throws<InvalidOperationException>(() =>
{
- HttpRequestMessageExtensions.CreateResponse(_request, HttpStatusCode.OK, _value, configuration: null);
+ _request.CreateResponse(HttpStatusCode.OK, _value, configuration: null);
}, "The request does not have an associated configuration object or the provided configuration was null.");
}
@@ -136,7 +131,7 @@ public void CreateResponse_DoingConneg_RetrievesContentNegotiatorFromServiceReso
_config.Services = servicesMock.Object;
// Act
- HttpRequestMessageExtensions.CreateResponse(_request, HttpStatusCode.OK, _value, _config);
+ _request.CreateResponse(HttpStatusCode.OK, _value, _config);
// Assert
servicesMock.Verify();
@@ -149,7 +144,7 @@ public void CreateResponse_DoingConneg_WhenNoContentNegotiatorInstanceRegistered
_config.Services.Clear(typeof(IContentNegotiator));
// Act & Assert
- Assert.Throws<InvalidOperationException>(() => HttpRequestMessageExtensions.CreateResponse(_request, HttpStatusCode.OK, _value, _config),
+ Assert.Throws<InvalidOperationException>(() => _request.CreateResponse(HttpStatusCode.OK, _value, _config),
"The provided configuration does not have an instance of the 'System.Net.Http.Formatting.IContentNegotiator' service registered.");
}
@@ -161,7 +156,7 @@ public void CreateResponse_DoingConneg_WhenContentNegotiatorReturnsNullResult_Th
_config.Services.Replace(typeof(IContentNegotiator), _negotiatorMock.Object);
// Act
- var response = HttpRequestMessageExtensions.CreateResponse<string>(_request, HttpStatusCode.OK, "", _config);
+ var response = _request.CreateResponse<string>(HttpStatusCode.OK, "", _config);
// Assert
Assert.Equal(HttpStatusCode.NotAcceptable, response.StatusCode);
@@ -178,7 +173,7 @@ public void CreateResponse_DoingConneg_PerformsContentNegotiationAndCreatesConte
_config.Services.Replace(typeof(IContentNegotiator), _negotiatorMock.Object);
// Act
- var response = HttpRequestMessageExtensions.CreateResponse<string>(_request, HttpStatusCode.NoContent, "42", _config);
+ var response = _request.CreateResponse<string>(HttpStatusCode.NoContent, "42", _config);
// Assert
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
@@ -335,8 +330,8 @@ public void CreateResponse_AcceptingFormatter_WithOverridenMediaTypeHeader_Creat
[Fact]
public void RegisterForDispose_WhenRequestParameterIsNull_Throws()
{
- Assert.ThrowsArgumentNull(
- () => HttpRequestMessageExtensions.RegisterForDispose(request: null, resource: null), "request");
+ HttpRequestMessage request = null;
+ Assert.ThrowsArgumentNull(() => request.RegisterForDispose(resource: null), "request");
}
[Fact]
@@ -375,7 +370,8 @@ public void RegisterForDispose_WhenResourceListExists_AddsResource()
[Fact]
public void DisposeRequestResources_WhenRequestParameterIsNull_Throws()
{
- Assert.ThrowsArgumentNull(() => HttpRequestMessageExtensions.DisposeRequestResources(request: null), "request");
+ HttpRequestMessage request = null;
+ Assert.ThrowsArgumentNull(() => request.DisposeRequestResources(), "request");
}
[Fact]
View
3  test/System.Web.Http.Test/HttpResponseMessageExtensionsTest.cs
@@ -1,12 +1,11 @@
using System.Collections.Generic;
-using System.Net.Http;
using System.Net.Http.Formatting;
using Moq;
using Xunit;
using Xunit.Extensions;
using Assert = Microsoft.TestCommon.AssertEx;
-namespace System.Web.Http
+namespace System.Net.Http
{
public class HttpResponseMessageExtensionsTest
{
Please sign in to comment.
Something went wrong with that request. Please try again.