Definition
Assembly: Microsoft.Restier.Breakdance.dll Namespace: Microsoft.Restier.Breakdance Inheritance: System.ObjectSyntax
Summary
A set of methods that make it easier to pull out Restier runtime components for unit testing.Remarks
See RestierTestHelperTests.cs for more examples of how to use these methods.Methods
ExecuteTestRequest
Configures the Restier pipeline in-memory and executes a test request against a given service, returning an HttpResponseMessage for inspection.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
httpMethod | System.Net.Http.HttpMethod | The HttpMethod to use for the request. |
host | string | The protocol and host to connect to in order to run the tests. Must end with a forward-slash. Defaults to “http://localhost/”, and should not normally be changed. NOTE: This should |
| NOT be the same as any of your actual running environments, and does not require a port assignment in order to function. | ||
routeName | string | The name that will be assigned to the route in the route configuration dictionary. |
routePrefix | string | The string that will be appended in between the Host and the Resource when constructing a URL. NOTE: DO NOT set this to the same URL as your deployment environments. |
| The prefix is irrelevant, is only for internal testing, and should ONLY be changed if you are testing more than one API in a test method (which is not recommended). | ||
resource | string | The specific resource on the endpoint that will be called. Must start with a forward-slash. |
serviceCollection | System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> | - |
acceptHeader | string | The “Accept” header that should be added to the request. Defaults to “application/json;odata.metadata=full”. |
defaultQuerySettings | Microsoft.AspNet.OData.Query.DefaultQuerySettings | A DefaultQuerySettings instabce that defines how OData operations should work. Defaults to everything enabled with a MaxTop of 10. |
timeZoneInfo | System.TimeZoneInfo | A TimeZoneInfo instenace specifying what time zone should be used to translate time payloads into. Defaults to Utc. |
payload | object | When the httpMethod is Post or Put, this object is serialized to JSON and inserted into the Content. |
jsonSerializerSettings | Newtonsoft.Json.JsonSerializerSettings | A JsonSerializerSettings or JsonSerializerOptions instance defining how the payload should be serialized into the request body. Defaults to using Zulu time and will include all properties in the payload, even null ones. |
useEndpointRouting | bool | On ASP.NET Core, determines whether or not to use EndpointRouting for the request. Not used on ASP.NET Classic. |
Returns
Type:System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
An HttpResponseMessage that contains the managed response for the request for inspection.
Type Parameters
TApi- The class inheriting from ApiBase that implements the Restier API to test.
GetApiMetadataAsync
Executes a test request against the configured API endpoint and retrieves the content from the /$metadata endpoint.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
host | string | - |
routeName | string | The name that will be assigned to the route in the route configuration dictionary. |
routePrefix | string | The string that will be appended in between the Host and the Resource when constructing a URL. |
serviceCollection | System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> | - |
useEndpointRouting | bool | On ASP.NET Core, determines whether or not to use EndpointRouting for the request. Not used on ASP.NET Classic. |
Returns
Type:System.Threading.Tasks.Task<System.Xml.Linq.XDocument>
An XDocument containing the results of the metadata request.
Type Parameters
TApi- The class inheriting from ApiBase that implements the Restier API to test.
GetModelBuilderHierarchy
Gets a list of fully-qualified builder instances that are registered down the ModelBuilder chain. The order is really important, so this is a great way to troubleshoot.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
routeName | string | The name that will be assigned to the route in the route configuration dictionary. |
routePrefix | string | The string that will be appended in between the Host and the Resource when constructing a URL. |
serviceCollection | System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> | - |
useEndpointRouting | bool | On ASP.NET Core, determines whether or not to use EndpointRouting for the request. Not used on ASP.NET Classic. |
Returns
Type:System.Threading.Tasks.Task<System.Collections.Generic.List<string>>
Type Parameters
TApi- The class inheriting from ApiBase that implements the Restier API to test.
GetTestableApiInstance
Retrieves the instance of the Restier API (inheriting from ApiBase from the Dependency Injection container.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
routeName | string | The name that will be assigned to the route in the route configuration dictionary. |
routePrefix | string | The string that will be appendedin between the Host and the Resource when constructing a URL. |
serviceCollection | System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> | - |
useEndpointRouting | bool | On ASP.NET Core, determines whether or not to use EndpointRouting for the request. Not used on ASP.NET Classic. |
Returns
Type:System.Threading.Tasks.Task<TApi>
Type Parameters
TApi- The class inheriting from ApiBase that implements the Restier API to test.
GetTestableHttpClient
Returns a properly configured HttpClient that can make reqests to the in-memory Restier context.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
routeName | string | The name that will be assigned to the route in the route configuration dictionary. |
routePrefix | string | The string that will be appendedin between the Host and the Resource when constructing a URL. |
serviceCollection | System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> | - |
useEndpointRouting | bool | On ASP.NET Core, determines whether or not to use EndpointRouting for the request. Not used on ASP.NET Classic. |
Returns
Type:System.Threading.Tasks.Task<System.Net.Http.HttpClient>
A properly configured HttpClient that can make reqests to the in-memory Restier context.
Type Parameters
TApi- The class inheriting from ApiBase that implements the Restier API to test.
GetTestableInjectedService
Retrieves class instance of type TService from the Dependency Injection container.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
routeName | string | The name that will be assigned to the route in the route configuration dictionary. |
routePrefix | string | The string that will be appended in between the Host and the Resource when constructing a URL. |
serviceCollection | System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> | - |
useEndpointRouting | bool | On ASP.NET Core, determines whether or not to use EndpointRouting for the request. Not used on ASP.NET Classic. |
Returns
Type:System.Threading.Tasks.Task<TService>
Type Parameters
TApi- The class inheriting from ApiBase that implements the Restier API to test.TService- The type whose instance should be retrieved from the DI container.
GetTestableInjectionContainer
Retrieves the Dependency Injection container that was created as a part of the request pipeline.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
routeName | string | The name that will be assigned to the route in the route configuration dictionary. |
routePrefix | string | The string that will be appendedin between the Host and the Resource when constructing a URL. |
serviceCollection | System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> | - |
useEndpointRouting | bool | On ASP.NET Core, determines whether or not to use EndpointRouting for the request. Not used on ASP.NET Classic. |
Returns
Type:System.Threading.Tasks.Task<System.IServiceProvider>
Type Parameters
TApi- The class inheriting from ApiBase that implements the Restier API to test.
GetTestableModelAsync
Retrieves the IEdmModel instance for a given API, whether it used a custom ModelBuilder or the RestierModelBuilder.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
routeName | string | The name that will be assigned to the route in the route configuration dictionary. |
routePrefix | string | The string that will be appended in between the Host and the Resource when constructing a URL. |
serviceCollection | System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> | - |
useEndpointRouting | bool | On ASP.NET Core, determines whether or not to use EndpointRouting for the request. Not used on ASP.NET Classic. |
Returns
Type:System.Threading.Tasks.Task<Microsoft.OData.Edm.IEdmModel>
An IEdmModel instance containing the model used to configure both OData and Restier processing.
Type Parameters
TApi- The class inheriting from ApiBase that implements the Restier API to test.
GetTestableRestierConfiguration
Retrieves an HttpConfiguration instance that has been configured to execute a given Restier API, along with settings suitable for easy troubleshooting.</see>Syntax
Parameters
| Name | Type | Description |
|---|---|---|
routeName | string | The name that will be assigned to the route in the route configuration dictionary. |
routePrefix | string | The string that will be appendedin between the Host and the Resource when constructing a URL. |
defaultQuerySettings | Microsoft.AspNet.OData.Query.DefaultQuerySettings | A DefaultQuerySettings instabce that defines how OData operations should work. Defaults to everything enabled with a MaxTop of 10. |
timeZoneInfo | System.TimeZoneInfo | A TimeZoneInfo instenace specifying what time zone should be used to translate time payloads into. Defaults to Utc. |
serviceCollection | System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> | - |
Returns
Type:System.Threading.Tasks.Task<System.Web.Http.HttpConfiguration>
An HttpConfiguration instance
Type Parameters
TApi- The class inheriting from ApiBase that implements the Restier API to test.
WriteCurrentApiMetadata
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
sourceDirectory | string | - |
suffix | string | - |
serviceCollection | System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> | - |
useEndpointRouting | bool | On ASP.NET Core, determines whether or not to use EndpointRouting for the request. Not used on ASP.NET Classic. |
Returns
Type:System.Threading.Tasks.Task
Type Parameters
TApi- The class inheriting from ApiBase that implements the Restier API to test.