Skip to content
Provides a way to test WebAPI
C# Batchfile
Latest commit 0f115a9 Dec 21, 2015 @jchannon Merge pull request #9 from jchannon/Browser_extension_methods
Added extension method for easily posting as json
Failed to load latest commit information.
src Added extension method for easily posting as json Dec 21, 2015
.gitignore
README.md
WebAPI.Testing.nuspec Enabled multi targeted nuget package build Dec 3, 2015
WebAPI.Testing.sln Enabled multi targeted nuget package build Dec 3, 2015
WebAPI.Testing.userprefs
buildandpack.cmd
licence.txt
packages.config

README.md

WebAPI.Testing

Provides a way to test WebAPI projects.

public class GetDataTests
{
    [Fact]
    public void GetData_WhenRequested_ShouldReturnJSON()
    {
        var browser = new Browser();
        var response = browser.Get("/GetData", (with) =>
        {
            with.Header("Accept", "application/json");
            with.HttpRequest();
        });

        Assert.Equal("application/json", response.Content.Headers.ContentType.MediaType);
    }

    [Fact]
    public void GetData_WhenRequested_ShouldReturnOKStatusCode()
    {
        var browser = new Browser();
        var response = browser.Get("/GetData", (with) =>
        {
            with.Header("Authorization", "Bearer johnsmith");
            with.Header("Accept", "application/json");
            with.HttpRequest();
        });

        Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
    }
}

This project is a modified version of Nancy.Testing but built to work with ASP.Net WebAPI


To build nuget packages open a Developer Command Prompt and run: buildandpack.cmd

Something went wrong with that request. Please try again.