Skip to content

Commit

Permalink
add a spec demonstrating how to use the new injection to stub out a r…
Browse files Browse the repository at this point in the history
…esponse
  • Loading branch information
dalpert-korewireless committed Jan 1, 2017
1 parent 5618c92 commit 31a3537
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/EasyHttp.Specs/EasyHttp.Specs.csproj
Expand Up @@ -48,6 +48,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Machine.Specifications.0.5.10\lib\net40\Machine.Specifications.Clr4.dll</HintPath>
</Reference>
<Reference Include="NSubstitute, Version=1.10.0.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
<HintPath>..\packages\NSubstitute.1.10.0.0\lib\net40\NSubstitute.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ServiceStack">
<HintPath>..\packages\ServiceStack.3.9.23\lib\net35\ServiceStack.dll</HintPath>
</Reference>
Expand Down
26 changes: 26 additions & 0 deletions src/EasyHttp.Specs/Specs/HttpRequestSpecs.cs
Expand Up @@ -61,6 +61,7 @@
using EasyHttp.Http;
using EasyHttp.Specs.Helpers;
using Machine.Specifications;
using NSubstitute;
using Result = EasyHttp.Specs.Helpers.ResultResponse;

namespace EasyHttp.Specs.Specs
Expand Down Expand Up @@ -146,6 +147,31 @@ public class when_making_a_GET_request_with_valid_uri
static HttpResponse httpResponse;
}

[Subject("HttpClient")]
public class when_mocking_a_GET_request_with_valid_uri_to_return_a_NotFound
{
Establish context = () =>
{
var injectedResponse = Substitute.For<HttpResponse>();
injectedResponse.StatusCode.Returns(HttpStatusCode.NotFound);
httpClient = new HttpClient(x => injectedResponse);
};

Because of = () =>
{
httpResponse = httpClient.Get("http://localhost:16000");
};

It should_return_a_NotFound =
() => httpResponse.StatusCode.ShouldEqual(HttpStatusCode.NotFound);


static HttpClient httpClient;
static HttpResponse httpResponse;
}

[Subject("HttpClient")]
public class when_making_a_GET_request_with_valid_uri_and__and_valid_parameters
{
Expand Down
1 change: 1 addition & 0 deletions src/EasyHttp.Specs/packages.config
Expand Up @@ -3,6 +3,7 @@
<package id="JsonFx" version="2.0.1209.2802" targetFramework="net40" />
<package id="Machine.Specifications" version="0.5.7" />
<package id="Machine.Specifications" version="0.5.10" targetFramework="net40" />
<package id="NSubstitute" version="1.10.0.0" targetFramework="net40" />
<package id="ServiceStack" version="3.9.23" targetFramework="net40" />
<package id="ServiceStack.Common" version="3.9.21" targetFramework="net40" />
<package id="ServiceStack.OrmLite.SqlServer" version="3.9.14" targetFramework="net40" />
Expand Down

0 comments on commit 31a3537

Please sign in to comment.