Skip to content

Commit

Permalink
refactoring ApiConnection.EmptyBody to RequestBody.Empty to break the…
Browse files Browse the repository at this point in the history
… inverse dependency from Connection to ApiConnection
  • Loading branch information
davidalpert committed Aug 1, 2015
1 parent c54dfa1 commit b4d71c8
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Octokit.Tests/Clients/TeamsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public async Task AllowsEmptyBody()

connection.Received().Put<Dictionary<string, string>>(
Arg.Is<Uri>(u => u.ToString() == "teams/1/memberships/user"),
Arg.Is<object>(u => u == ApiConnection.EmptyBody));
Arg.Is<object>(u => u == RequestBody.Empty));
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions Octokit.Tests/Http/ConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public async Task MakesPutRequestWithData()
[Fact]
public async Task MakesPutRequestWithNoData()
{
var body = ApiConnection.EmptyBody;
var body = RequestBody.Empty;
var expectedBody = SimpleJson.SerializeObject(body);
var httpClient = Substitute.For<IHttpClient>();
IResponse response = new Response();
Expand Down Expand Up @@ -421,7 +421,7 @@ public async Task MakesPutRequestWithDataAndTwoFactor()
[Fact]
public async Task MakesPutRequestWithNoDataAndTwoFactor()
{
var body = ApiConnection.EmptyBody ;
var body = RequestBody.Empty;
var expectedBody = SimpleJson.SerializeObject(body);
var httpClient = Substitute.For<IHttpClient>();
IResponse response = new Response();
Expand Down
2 changes: 1 addition & 1 deletion Octokit/Clients/TeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public async Task<TeamMembership> AddMembership(int id, string login)

try
{
response = await ApiConnection.Put<Dictionary<string, string>>(endpoint, Octokit.ApiConnection.EmptyBody);
response = await ApiConnection.Put<Dictionary<string, string>>(endpoint, RequestBody.Empty);
}
catch (NotFoundException)
{
Expand Down
3 changes: 0 additions & 3 deletions Octokit/Http/ApiConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public class ApiConnection : IApiConnection
{
readonly IApiPagination _pagination;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2211:NonConstantFieldsShouldNotBeVisible")]
public static object EmptyBody = new object();

/// <summary>
/// Initializes a new instance of the <see cref="ApiConnection"/> class.
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions Octokit/Http/RequestBody.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Octokit
{
/// <summary>
/// Container for the static <see cref="Empty"/> method that represents an
/// intentional empty request body to avoid overloading <code>null</code>.
/// </summary>
public static class RequestBody
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2211:NonConstantFieldsShouldNotBeVisible")]
public static object Empty = new object();
}
}
1 change: 1 addition & 0 deletions Octokit/Octokit-Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@
<Compile Include="Models\Response\ResourceRateLimit.cs" />
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\RequestBody.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
1 change: 1 addition & 0 deletions Octokit/Octokit-MonoAndroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@
<Compile Include="Models\Response\ResourceRateLimit.cs" />
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\RequestBody.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
1 change: 1 addition & 0 deletions Octokit/Octokit-Monotouch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@
<Compile Include="Models\Response\ResourceRateLimit.cs" />
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\RequestBody.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Expand Down
1 change: 1 addition & 0 deletions Octokit/Octokit-Portable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@
<Compile Include="Models\Response\ResourceRateLimit.cs" />
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\RequestBody.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
Expand Down
1 change: 1 addition & 0 deletions Octokit/Octokit-netcore45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@
<Compile Include="Models\Response\ResourceRateLimit.cs" />
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\RequestBody.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
Expand Down
1 change: 1 addition & 0 deletions Octokit/Octokit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<Compile Include="Helpers\SerializeNullAttribute.cs" />
<Compile Include="Http\HttpMessageHandlerFactory.cs" />
<Compile Include="Http\ProductHeaderValue.cs" />
<Compile Include="Http\RequestBody.cs" />
<Compile Include="Models\Request\GistFileUpdate.cs" />
<Compile Include="Models\Request\NewMerge.cs" />
<Compile Include="Models\Request\PublicRepositoryRequest.cs" />
Expand Down

0 comments on commit b4d71c8

Please sign in to comment.