Antenna 1.0.2

dotnet add package Antenna --version 1.0.2                
NuGet\Install-Package Antenna -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<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                
#r "nuget: Antenna, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Antenna as a Cake Addin
#addin nuget:?package=Antenna&version=1.0.2

// Install Antenna as a Cake Tool
#tool nuget:?package=Antenna&version=1.0.2                

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\<HttpConfiguration\> 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

 _  _  ,,                                                     ,, _  _
(_)(_)-O                                                      0-(_)(_)
 L L L                                                          J J J
 `````--.._____..---`````---````----...._____....-`````--...__..``dwb`._
Product Compatible and additional computed target framework versions.
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 1,065 8/26/2018
1.0.1 861 8/20/2018
1.0.0 838 8/20/2018

Initial release.