Skip to content
This repository has been archived by the owner. It is now read-only.
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

README.md

JustFakeIt

ℹ️ 📣 JustFakeIt is no longer actively maintained. 📣

For an actively supported alternative, consider using JustEat.HttpClientInterception.


An InProcess HTTP server which can be mocked and asserted against to allow for full stack HTTP testing

Build status


Introduction

JustFakeIt is a mockable HTTP server which is hosted within your unit test process and provides you with the ability to test your applications entire HTTP stack without having to provide mocks for anything in the stack. Because it's hosted In Process, it's really fast and takes very little effort to use.

It will configure itself as a default proxy and let you hook any WebRequest based client by default, intercepting all outbound Http calls in scope.

Installation

Pre-requisites: The project is built in .net v4.0.

Via NuGet:

	PM> Install-Package JustFakeIt

Getting Started

Once you have the package installed into your test project, a standard wire-up will look like this.

[Fact]
public void FakeServer_ExpectGetReturnsString_ResponseMatchesExpectation()
{    
    using (var fakeServer = new FakeServer(12354))
    {
        fakeServer.Expect.Get("/123").Returns("Some String Data");
        fakeServer.Start();

        var result = new WebClient().DownloadString(new Uri("http://www.anything-at-all.com/123"));

        result.Should().Be("Some String Data");
    }
}

Ignore parameters by replacing the value with "{ignore}"

 var fakeurl = "/some-resource/{ignore}/some-resource?date={ignore}&type={ignore}";
 fakeServer.Expect.Get(fakeurl).Returns(HttpStatusCode.Accepted, expectedResult);

Set a response time accross all endpoints by setting the ResponseTime property

 fakeServer.Expect.ResponseTime = TimeSpan.FromSeconds(5);

Set the response time for a specific endpoint with RespondsIn()

 fakeServer.Expect.Get(fakeurl).Returns(HttpStatusCode.Accepted, expectedResult).RespondsIn(TimeSpan.FromSeconds(5));

Assert against captured requests

 fakeServer.CapturedRequests.Count(x => x.Method == Http.Delete && x.Url == "/some-url").Should().Be(1);

Return content from razor template file

var path = "template.razor"
fakeServer.Expect.Get(url).ReturnsFromTemplate(path, new { Id = 2343, UserId = 2343, UserEmail = "mick.hucknall@just-eat.com" })

Return content from file

var path = "response.txt"
fakeServer.Expect.Get(url).ReturnsFromFile(path)

Contributing

If you find a bug, have a feature request or even want to contribute an enhancement or fix, please follow the contributing guidelines included in the repository.

Copyright

Copyright © JUST EAT PLC 2014

About

HTTP server faking library

Resources

License

Releases

No releases published

Languages

You can’t perform that action at this time.