-
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Boomerang makes testing your applications easier by enabling you to fake HTTP services your code depends upon.
This makes tests faster and less brittle, allowing you to get consistent and fast feedback from your tests.
If you new to Boomerang take a look at the Getting started guide. After this, you might want to take a look at the Extending Boomerang area.
Boomerang supports all HTTP verbs. You can configure these using Boomerangs simple fluent interface. The first thing you need to do is create an instance of Boomerang;
var host = Host.Boomerang.Create(
x => x.AtAddress("http://localhost:5100")
);
Now your ready to configure requests on the host. Examples of using the interface is below;
GET
The below code configures will return a OK response with a body of 'Coffee' for a request to http://localhost:5100/api/menu
host.Get("api/menu/items/123").Returns("Coffee", 200);
Post
The below code will return a Created response with a body of Mocha for a request to the relative address api/menu/items/123
host.Post("api/menu/items/123").Returns("Mocha", 201);
Put
host.Put("api/menu/items/123").Returns("Mocha", 201);
Delete
host.Delete("api/menu/items/123").Returns("Mocha", 202);
Request
All other verbs are supported via the general Request method. For example, the below code configures a Trace request;
host.Request("api/menu/items", "TRACE").Returns("", 200);
The second parameter defines the Http verb the request is configuring.
If you configure these several times you might consider creating you own extension method as below;
public static IRequestHandler Trace(this IBoomerang host, string relativeUrl)
{
return host.Request(relativeUrl, "TRACE");
}
Now you can simply use this extension method whereever you want to configure a Trace request;
host.Trace("api/menu/items").Returns("Trace", 200);