Skip to content

Commit c2352a0

Browse files
Merge branch 'release-1.7'
2 parents 5f15d0f + 688adf3 commit c2352a0

27 files changed

+1272
-206
lines changed

build/EasyHttp.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
</dependencies>
1919
</metadata>
2020
<files>
21-
<file src="..\src\EasyHttp\bin\Release\EasyHttp.*" target="lib\net40" />
21+
<file src="..\src\EasyHttp\bin\$configuration$\EasyHttp.*" target="lib\net40" />
2222
</files>
2323
</package>

build/build.proj

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,101 @@
11
<?xml version="1.0" encoding="utf-8" ?>
2-
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="CIBuild">
3+
34
<PropertyGroup>
4-
<ProjectFolder>..\src\</ProjectFolder>
5-
<Version>1.0.0.0</Version>
5+
<BuildConfiguration>Debug</BuildConfiguration>
6+
7+
<RootDir>$([System.IO.Path]::GetFullPath("$(MSBuildThisFileDirectory)..\"))</RootDir>
8+
<SoultionDir>$(RootDir)src\</SoultionDir>
9+
<PackagesDir>$(SoultionDir)packages\</PackagesDir>
10+
<BinDir>$(RootDir)bin\</BinDir>
11+
12+
<VersionStemFile>$(RootDir)version.txt</VersionStemFile>
13+
14+
<MSpecConsoleRunner>$(PackagesDir)Machine.Specifications.0.5.10\tools\mspec-x86-clr4.exe</MSpecConsoleRunner>
15+
<NugetExe>$(SoultionDir).nuget\nuget.exe</NugetExe>
16+
<NuspecFile>$(MSBuildFileThisDirectory)EasyHttp.nuspec</NuspecFile>
617
</PropertyGroup>
7-
<Target Name="BuildNuGet">
8-
<MSBuild Projects="$(ProjectFolder)\EasyHttp.sln" Properties="Configuration=Release;" />
9-
<Exec Command="NuGet pack EasyHttp.nuspec -Properties Configuration=Release -Version $(version)" />
18+
19+
<Target Name="CIBuild" DependsOnTargets="$(CIBuild_DependsOn)"/>
20+
<Target Name="Publish" DependsOnTargets="$(Publish_DependsOn)"/>
21+
22+
<ItemGroup>
23+
<Solution Include="$(SoultionDir)EasyHttp.sln"/>
24+
</ItemGroup>
25+
26+
<Import Project="$(PackagesDir)GitVersionTask.3.6.5\build\dotnet\GitVersionTask.targets"/>
27+
28+
<PropertyGroup>
29+
<CIBuild_DependsOn>
30+
GetVersion; <!-- from GitVersionTask.targets -->
31+
Describe; <!-- self-documenting -->
32+
Build; <!-- Step 1 -->
33+
RunTests; <!-- Step 2 -->
34+
BuildPackage; <!-- Step 3 -->
35+
</CIBuild_DependsOn>
36+
<Publish_DependsOn>
37+
PublishPackage;
38+
</Publish_DependsOn>
39+
</PropertyGroup>
40+
41+
<Target Name="Describe" DependsOnTargets="GetVersion">
42+
<Message Text=" RootDir: $(RootDir)"/>
43+
<Message Text=" SourceDir: $(SoultionDir)"/>
44+
<Message Text=" PackageDir: $(PackagesDir)"/>
45+
<Message Text=" BinDir: $(BinDir)"/>
46+
<Message Text=" "/>
47+
<Message Text=" BuildConfiguration: $(BuildConfiguration)"/>
48+
<Message Text=" BranchName: $(GitVersion_BranchName)"/>
49+
<Message Text=" PreReleaseTag: $(GitVersion_PreReleaseTag)"/>
50+
<Message Text=" "/>
51+
<Message Text=" AssemblySemVer: $(GitVersion_AssemblySemVer)"/>
52+
<Message Text=" FullSemVer: $(GitVersion_FullSemVer)"/>
53+
<Message Text="InformationalVersion: $(GitVersion_InformationalVersion)"/>
54+
<Message Text=" "/>
55+
<Message Text=" NugetVersion: $(GitVersion_NugetVersion)"/>
56+
<Message Text=" "/>
57+
<Message Text="##teamcity[setParameter name='NugetPackageVersion' value='$(GitVersion_NugetVersion)']"/>
58+
</Target>
59+
60+
<Target Name="Build">
61+
<MSBuild Projects="%(Solution.Identity)"
62+
Targets="Rebuild"
63+
Properties="Configuration=$(BuildConfiguration);TreatWarningsAsErrors=True" />
64+
</Target>
65+
66+
<Target Name="RunTests">
67+
<ItemGroup>
68+
<TestAssemblies Include="$(SoultionDir)EasyHttp.Specs\bin\$(BuildConfiguration)\EasyHttp.Specs.dll"/>
69+
</ItemGroup>
70+
71+
<PropertyGroup>
72+
<cmd>"$(MSpecConsoleRunner)" @(TestAssemblies)</cmd>
73+
</PropertyGroup>
74+
75+
<Exec Command="$(cmd)"/>
76+
</Target>
77+
78+
<Target Name="EnsureBinExists">
79+
<MakeDir Directories="$(BinDir)" Condition="!Exists('$(BinDir)')"/>
80+
</Target>
81+
82+
<Target Name="BuildPackage" DependsOnTargets="EnsureBinExists">
83+
<PropertyGroup>
84+
<cmd>"$(NugetExe)" pack "$(NuspecFile)" -Properties Configuration=$(BuildConfiguration) -Version $(GitVersion_NugetVersion)</cmd>
85+
<cmd>$(cmd) -OutputDirectory "$(BinDir.TrimEnd('\'))"</cmd>
86+
</PropertyGroup>
87+
88+
<Exec Command="$(cmd)"/>
89+
</Target>
90+
91+
<Target Name="PublishPackage" DependsOnTargets="GetVersion">
92+
<Error Condition="'$(NugetApiKey)'==''" Text="Must provide a value for %24(NugetApiKey) before pushing packages."/>
93+
94+
<PropertyGroup>
95+
<cmd>"$(NugetExe)" push "$(BinDir)EasyHttp.$(GitVersion_NugetVersion).nupkg" $(NugetApiKey)</cmd>
96+
</PropertyGroup>
97+
98+
<Exec Command="$(cmd)"/>
1099
</Target>
11100

12101
</Project>

build/lib/net40/.gitignore

Lines changed: 0 additions & 14 deletions
This file was deleted.

go.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src\.nuget\nuget.exe restore src\EasyHttp.sln
2+
msbuild build\build.proj

src/EasyHttp.Specs/BugRepros/AcceptEncodingIssue.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System.Net;
22
using EasyHttp.Http;
3+
using EasyHttp.Http.Abstractions;
34
using EasyHttp.Specs.Helpers;
45
using Machine.Specifications;
6+
using ServiceStack.WebHost.Endpoints.Extensions;
57

68
namespace EasyHttp.Specs.BugRepros
79
{
@@ -18,7 +20,7 @@ public class when_preparing_a_web_request
1820

1921
Because of = () =>
2022
{
21-
underlyingRequest = http.Request.PrepareRequest();
23+
underlyingRequest = (http.Request.PrepareRequest() as HttpWebRequestWrapper).InnerRequest;
2224
};
2325

2426
It should_enable_automatic_gzip_compression_on_the_underlying_web_request_by_default = () =>
@@ -50,7 +52,7 @@ public class when_disabling_automatic_compression
5052

5153
Because of = () =>
5254
{
53-
underlyingRequest = http.Request.PrepareRequest();
55+
underlyingRequest = (http.Request.PrepareRequest() as HttpWebRequestWrapper).InnerRequest;
5456
};
5557

5658
It should_disable_automatic_gzip_compression_on_the_underlying_web_request = () =>

src/EasyHttp.Specs/EasyHttp.Specs.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<FileAlignment>512</FileAlignment>
1515
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
1616
<RestorePackages>true</RestorePackages>
17+
<NuGetPackageImportStamp>894ff1f5</NuGetPackageImportStamp>
1718
</PropertyGroup>
1819
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1920
<DebugSymbols>true</DebugSymbols>
@@ -48,6 +49,10 @@
4849
<SpecificVersion>False</SpecificVersion>
4950
<HintPath>..\packages\Machine.Specifications.0.5.10\lib\net40\Machine.Specifications.Clr4.dll</HintPath>
5051
</Reference>
52+
<Reference Include="NSubstitute, Version=1.10.0.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
53+
<HintPath>..\packages\NSubstitute.1.10.0.0\lib\net40\NSubstitute.dll</HintPath>
54+
<Private>True</Private>
55+
</Reference>
5156
<Reference Include="ServiceStack">
5257
<HintPath>..\packages\ServiceStack.3.9.23\lib\net35\ServiceStack.dll</HintPath>
5358
</Reference>

src/EasyHttp.Specs/Specs/HttpRequestSpecs.cs

Lines changed: 100 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#region License
22
// Distributed under the BSD License
33
// =================================
4-
//
4+
//
55
// Copyright (c) 2010, Hadi Hariri
66
// All rights reserved.
7-
//
7+
//
88
// Redistribution and use in source and binary forms, with or without
99
// modification, are permitted provided that the following conditions are met:
1010
// * Redistributions of source code must retain the above copyright
@@ -15,7 +15,7 @@
1515
// * Neither the name of Hadi Hariri nor the
1616
// names of its contributors may be used to endorse or promote products
1717
// derived from this software without specific prior written permission.
18-
//
18+
//
1919
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2020
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2121
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -27,26 +27,26 @@
2727
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2828
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
// =============================================================
30-
//
31-
//
30+
//
31+
//
3232
// Parts of this Software use JsonFX Serialization Library which is distributed under the MIT License:
33-
//
33+
//
3434
// Distributed under the terms of an MIT-style license:
35-
//
35+
//
3636
// The MIT License
37-
//
37+
//
3838
// Copyright (c) 2006-2009 Stephen M. McKamey
39-
//
39+
//
4040
// Permission is hereby granted, free of charge, to any person obtaining a copy
4141
// of this software and associated documentation files (the "Software"), to deal
4242
// in the Software without restriction, including without limitation the rights
4343
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4444
// copies of the Software, and to permit persons to whom the Software is
4545
// furnished to do so, subject to the following conditions:
46-
//
46+
//
4747
// The above copyright notice and this permission notice shall be included in
4848
// all copies or substantial portions of the Software.
49-
//
49+
//
5050
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5151
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5252
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -57,10 +57,12 @@
5757
#endregion
5858

5959
using System;
60+
using System.Collections.Generic;
6061
using System.Net;
6162
using EasyHttp.Http;
6263
using EasyHttp.Specs.Helpers;
6364
using Machine.Specifications;
65+
using NSubstitute;
6466
using Result = EasyHttp.Specs.Helpers.ResultResponse;
6567

6668
namespace EasyHttp.Specs.Specs
@@ -86,7 +88,7 @@ public class when_making_any_type_of_request_to_invalid_host
8688
}
8789

8890
[Subject("HttpClient")]
89-
public class when_making_a_DELETE_request_with_a_valid_uri
91+
public class when_making_a_DELETE_request_with_a_valid_uri
9092
{
9193
Establish context = () =>
9294
{
@@ -141,11 +143,95 @@ public class when_making_a_GET_request_with_valid_uri
141143
It should_return_body_with_rawtext =
142144
() => httpResponse.RawText.ShouldNotBeEmpty();
143145

144-
146+
145147
static HttpClient httpClient;
146148
static HttpResponse httpResponse;
147149
}
148150

151+
[Subject("HttpClient")]
152+
public class when_mocking_a_GET_request_with_valid_uri_to_return_a_NotFound
153+
{
154+
Establish context = () =>
155+
{
156+
var injectedResponse = Substitute.For<HttpResponse>();
157+
injectedResponse.StatusCode.Returns(HttpStatusCode.NotFound);
158+
159+
httpClient = Substitute.For<HttpClient>();
160+
httpClient.Get(Arg.Any<string>()).Returns(injectedResponse);
161+
};
162+
163+
Because of = () =>
164+
{
165+
httpResponse = httpClient.Get("http://localhost:16000");
166+
};
167+
168+
It should_return_a_NotFound =
169+
() => httpResponse.StatusCode.ShouldEqual(HttpStatusCode.NotFound);
170+
171+
172+
static HttpClient httpClient;
173+
static HttpResponse httpResponse;
174+
}
175+
176+
[Subject("HttpClient")]
177+
public class when_mocking_a_GET_request_with_valid_uri_to_inject_a_specific_response
178+
{
179+
Establish context = () =>
180+
{
181+
var injectedResponseBody =
182+
@"{
183+
'name': 'Serenity',
184+
'characterNames': [
185+
'Mal',
186+
'Wash',
187+
'Zoe'
188+
]
189+
}";
190+
httpClient = new HttpClient();
191+
192+
httpClient.OnRequest(r =>
193+
r.Uri.Contains("localhost:16000")
194+
&& r.Method == HttpMethod.POST
195+
)
196+
.InjectResponse(
197+
HttpStatusCode.BadRequest,
198+
HttpContentTypes.ApplicationJson,
199+
injectedResponseBody
200+
);
201+
};
202+
203+
Because of = () =>
204+
{
205+
httpGetResponse = httpClient.Get("http://localhost:16000");
206+
httpPostResponse = httpClient.Post("http://localhost:16000", null, HttpContentTypes.ApplicationJson);
207+
};
208+
209+
It should_return_OK_for_the_Get =
210+
() => httpGetResponse.StatusCode.ShouldEqual(HttpStatusCode.OK);
211+
212+
It should_return_BadRequest_for_the_Post =
213+
() => httpPostResponse.StatusCode.ShouldEqual(HttpStatusCode.BadRequest);
214+
215+
It should_return_the_injected_content_type_for_the_Post =
216+
() => httpPostResponse.ContentType.ShouldEndWith(HttpContentTypes.ApplicationJson);
217+
218+
It should_return_the_injected_body_content_for_the_Post =
219+
() =>
220+
{
221+
// have to explicitly cast this dynamic member so that the
222+
// Should extensions can bind properly at run-time.
223+
var characterNames = httpPostResponse.DynamicBody.characterNames as string[];
224+
225+
characterNames.ShouldNotBeNull();
226+
characterNames.Length.ShouldEqual(3);
227+
characterNames[1].ShouldEqual("Wash");
228+
};
229+
230+
static HttpClient httpClient;
231+
static HttpResponse httpGetResponse;
232+
static HttpResponse httpPostResponse;
233+
}
234+
149235
[Subject("HttpClient")]
150236
public class when_making_a_GET_request_with_valid_uri_and__and_valid_parameters
151237
{
@@ -302,7 +388,7 @@ public class when_making_a_GET_request_with_valid_uri_and_content_type_set_to_ap
302388
static HttpResponse response;
303389
}
304390

305-
391+
306392
[Subject("HttpClient")]
307393
public class when_making_a_HEAD_request_with_valid_uri
308394
{

src/EasyHttp.Specs/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<package id="JsonFx" version="2.0.1209.2802" targetFramework="net40" />
44
<package id="Machine.Specifications" version="0.5.7" />
55
<package id="Machine.Specifications" version="0.5.10" targetFramework="net40" />
6+
<package id="NSubstitute" version="1.10.0.0" targetFramework="net40" />
67
<package id="ServiceStack" version="3.9.23" targetFramework="net40" />
78
<package id="ServiceStack.Common" version="3.9.21" targetFramework="net40" />
89
<package id="ServiceStack.OrmLite.SqlServer" version="3.9.14" targetFramework="net40" />

0 commit comments

Comments
 (0)