Antenna 1.0.2
dotnet add package Antenna --version 1.0.2
NuGet\Install-Package Antenna -Version 1.0.2
<PackageReference Include="Antenna" Version="1.0.2" />
paket add Antenna --version 1.0.2
#r "nuget: Antenna, 1.0.2"
// 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
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
_ _ ,, ,, _ _
(_)(_)-O 0-(_)(_)
L L L J J J
`````--.._____..---`````---````----...._____....-`````--...__..``dwb`._
Product | Versions 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. |
-
- CommonServiceLocator (>= 1.3.0)
- Microsoft.AspNet.WebApi.Client (>= 5.2.3)
- Microsoft.AspNet.WebApi.Core (>= 5.2.3)
- Newtonsoft.Json (>= 6.0.4)
- System.ValueTuple (>= 4.5.0)
- Unity (>= 4.0.1)
- Unity.WebAPI (>= 5.2.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release.