Antenna 1.0.2

Helper classes and methods for aspnet webapi tests (System.Net.Http : ApiController) for now .net 4.5

Install-Package Antenna -Version 1.0.2
dotnet add package Antenna --version 1.0.2
<PackageReference Include="Antenna" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Antenna --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Antenna (ant)

A repository with helper classes and methods for aspnet webapi tests (System.Net.Http : ApiController) for .net 4.5

contributions welcome

ant

WebApi 2 Pipeline

HTTP REQUEST
--> DelegatingHandler (ant)
--> AuthenticationFilter (ant)
--> AuthorizationFilter (ant)
---> ExceptionFilter (ant)
--> ActionFilter (ant)
--> Controller.

anything can be ant'd.

Usage

Let's try it with a simple TestController. we will add some route attributes to make it feel "more custom".
We will use this sample controller, to see the various features of the library.

[RoutePrefix("api/test")]
public class TestController : ApiController
{
    [Route("")]
    [HttpGet]
    public IHttpActionResult Get()
    {
        return Ok();
    }

    [Route("another/more/complex/route")]
    public IHttpActionResult MoreComplexPost([FromBody] string test)
    {
        return Ok();
    }
}

HttpRequest

Let's make a call to the GET route, specifying the verb and the complete http route.

var testController = new TestController();
var responseStatus = await new TestController().Test().HttpRequest(HttpMethod.Get, TestApiRoute, r => r.StatusCode);
Assert.True(resultStatus == HttpStatusCode.OK);

To abbreviate usage, with the most common methods GET and POST, also GetAsync and PostAsync overloads are provided
they simply "hide" the explicit HttpMethod, no magic (yet!).

BuildHttpRequest (antenna mode on)

Now things become really interesting here!
Using magic ant antennas (ok, it's just .NET reflection), we are able to infer both the http request Uri and the Http verb used,
using the .BuildHttpRequest extension method. The verb is first inferred from any HttpMethodAttribute,
and then, if not present, from the method name (convention based).

 var statusCode = await new testController.Test()
    .BuildHttpRequest(() => testController.MoreComplexPost(null)), r => r.StatusCode);

Cusomizations in Test seupt and Request

*The .Test extension method accepts different customizations: e.g. custom DelegatingHandlers, Filters, and a custom
Action\&lt;HttpConfiguration\&gt; if a special setup is needed.

*The .HttpRequest and BuildHttpRequest methods in its different variants, takes also an additional parameters to add custom actions on HttpRequest and HttpResponse messages within the pipeline (in case Handlers and Filters aren't enough for some particular case).

Status

build status

<!-- language: lang-none -->
_ _ ,, ,, _ _
()()-O 0-()()
L L L J J J
--.._____..------````----....__....-`````--.....``dwb`.

Antenna (ant)

A repository with helper classes and methods for aspnet webapi tests (System.Net.Http : ApiController) for .net 4.5

contributions welcome

ant

WebApi 2 Pipeline

HTTP REQUEST
--> DelegatingHandler (ant)
--> AuthenticationFilter (ant)
--> AuthorizationFilter (ant)
---> ExceptionFilter (ant)
--> ActionFilter (ant)
--> Controller.

anything can be ant'd.

Usage

Let's try it with a simple TestController. we will add some route attributes to make it feel "more custom".
We will use this sample controller, to see the various features of the library.

[RoutePrefix("api/test")]
public class TestController : ApiController
{
    [Route("")]
    [HttpGet]
    public IHttpActionResult Get()
    {
        return Ok();
    }

    [Route("another/more/complex/route")]
    public IHttpActionResult MoreComplexPost([FromBody] string test)
    {
        return Ok();
    }
}

HttpRequest

Let's make a call to the GET route, specifying the verb and the complete http route.

var testController = new TestController();
var responseStatus = await new TestController().Test().HttpRequest(HttpMethod.Get, TestApiRoute, r => r.StatusCode);
Assert.True(resultStatus == HttpStatusCode.OK);

To abbreviate usage, with the most common methods GET and POST, also GetAsync and PostAsync overloads are provided
they simply "hide" the explicit HttpMethod, no magic (yet!).

BuildHttpRequest (antenna mode on)

Now things become really interesting here!
Using magic ant antennas (ok, it's just .NET reflection), we are able to infer both the http request Uri and the Http verb used,
using the .BuildHttpRequest extension method. The verb is first inferred from any HttpMethodAttribute,
and then, if not present, from the method name (convention based).

 var statusCode = await new testController.Test()
    .BuildHttpRequest(() => testController.MoreComplexPost(null)), r => r.StatusCode);

Cusomizations in Test seupt and Request

*The .Test extension method accepts different customizations: e.g. custom DelegatingHandlers, Filters, and a custom
Action\&lt;HttpConfiguration\&gt; if a special setup is needed.

*The .HttpRequest and BuildHttpRequest methods in its different variants, takes also an additional parameters to add custom actions on HttpRequest and HttpResponse messages within the pipeline (in case Handlers and Filters aren't enough for some particular case).

Status

build status

<!-- language: lang-none -->
_ _ ,, ,, _ _
()()-O 0-()()
L L L J J J
--.._____..------````----....__....-`````--.....``dwb`.

Release Notes

Initial release.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.2 220 8/26/2018
1.0.1 184 8/20/2018
1.0.0 173 8/20/2018