> ## Documentation Index
> Fetch the complete documentation index at: https://easyaf.nimbleapps.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# AspNetCoreBreakdanceTestBase

> A base class for building unit tests for AspNetCore APIs that automatically maintains a [TestServer](https://learn.microsoft.com/dotnet/api/microsoft.aspnetc...

## Definition

**Assembly:** CloudNimble.Breakdance.AspNetCore.dll

**Namespace:** CloudNimble.Breakdance.AspNetCore

**Inheritance:** CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase

## Syntax

```csharp theme={"dark"}
CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase<TStartup>
```

## Summary

A base class for building unit tests for AspNetCore APIs that automatically maintains a [TestServer](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.testhost.testserver) with configuration and a Dependency Injection containers for you.

## Type Parameters

* `TStartup` -

## Constructors

### &#x20;.ctor

Creates a new [AspNetCoreBreakdanceTestBase](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md) instance.

#### Syntax

```csharp theme={"dark"}
public AspNetCoreBreakdanceTestBase()
```

#### Remarks

The call to .Configure() with no content is required to get a minimal, empty [IWebHost](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.hosting.iwebhost).

### &#x20;.ctor Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Creates a new [AspNetCoreBreakdanceTestBase](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md) instance.

#### Syntax

```csharp theme={"dark"}
public AspNetCoreBreakdanceTestBase()
```

#### Remarks

Uses the modern [IHostBuilder](https://easyaf.nimbleapps.cloud/breakdance/api-reference/Microsoft/Extensions/Hosting/IHostBuilder.md) pattern for web hosting instead of the deprecated WebHostBuilder.

## Properties

### &#x20;TestHostBuilder Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Replaces the [AspNetCoreBreakdanceTestBase.TestHostBuilder](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md#testhostbuilder) from the [BreakdanceTestBase](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/Assemblies/BreakdanceTestBase.md) with an [IHostBuilder](https://easyaf.nimbleapps.cloud/breakdance/api-reference/Microsoft/Extensions/Hosting/IHostBuilder.md) implementation configured for web hosting.

#### Syntax

```csharp theme={"dark"}
public Microsoft.Extensions.Hosting.IHostBuilder TestHostBuilder { get; internal set; }
```

#### Property Value

Type: `Microsoft.Extensions.Hosting.IHostBuilder`

### &#x20;TestServer Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

The [AspNetCoreBreakdanceTestBase.TestServer](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md#testserver) for handling requests.

#### Syntax

```csharp theme={"dark"}
public Microsoft.AspNetCore.TestHost.TestServer TestServer { get; internal set; }
```

#### Property Value

Type: `Microsoft.AspNetCore.TestHost.TestServer`

## Methods

### &#x20;AddApis Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Adds Controller services to the [AspNetCoreBreakdanceTestBase.TestHostBuilder](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md#testhostbuilder).

#### Syntax

```csharp theme={"dark"}
public void AddApis(System.Action<Microsoft.AspNetCore.Mvc.MvcOptions> options = null, System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder> app = null)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `options` | `System.Action<Microsoft.AspNetCore.Mvc.MvcOptions>` | - |
| `app` | `System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder>` | - |

#### Remarks

Calls AddControllers() on the [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection) which does the following, according to the Microsoft docs:
combines the effects of Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(Microsoft.Extensions.DependencyInjection.IServiceCollection),
Microsoft.Extensions.DependencyInjection.MvcApiExplorerMvcCoreBuilderExtensions.AddApiExplorer(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
Microsoft.Extensions.DependencyInjection.MvcCoreMvcCoreBuilderExtensions.AddAuthorization(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
Microsoft.Extensions.DependencyInjection.MvcCorsMvcCoreBuilderExtensions.AddCors(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
Microsoft.Extensions.DependencyInjection.MvcDataAnnotationsMvcCoreBuilderExtensions.AddDataAnnotations(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
and Microsoft.Extensions.DependencyInjection.MvcCoreMvcCoreBuilderExtensions.AddFormatterMappings(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder).

### &#x20;AddMinimalMvc Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Adds minimal MVC services to the [AspNetCoreBreakdanceTestBase.TestHostBuilder](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md#testhostbuilder).

#### Syntax

```csharp theme={"dark"}
public void AddMinimalMvc(System.Action<Microsoft.AspNetCore.Mvc.MvcOptions> options = null, System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder> app = null)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `options` | `System.Action<Microsoft.AspNetCore.Mvc.MvcOptions>` | - |
| `app` | `System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder>` | - |

#### Remarks

Calls AddMvcCore() on the [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection) which does the following, according to the Microsoft docs:
will register the minimum set of services necessary to route requests and invoke
controllers. It is not expected that any application will satisfy its requirements
with just a call to Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(Microsoft.Extensions.DependencyInjection.IServiceCollection).
Additional configuration using the Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder
will be required.

### &#x20;AddRazorPages Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Adds support for Controllers and Razor views to the [AspNetCoreBreakdanceTestBase.TestHostBuilder](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md#testhostbuilder).

#### Syntax

```csharp theme={"dark"}
public void AddRazorPages(System.Action<Microsoft.AspNetCore.Mvc.RazorPages.RazorPagesOptions> options = null, System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder> app = null)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `options` | `System.Action<Microsoft.AspNetCore.Mvc.RazorPages.RazorPagesOptions>` | - |
| `app` | `System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder>` | - |

#### Remarks

Calls AddRazorPages() on the [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection) which does the following, according to the Microsoft docs:
combines the effects of Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(Microsoft.Extensions.DependencyInjection.IServiceCollection),
Microsoft.Extensions.DependencyInjection.MvcCoreMvcCoreBuilderExtensions.AddAuthorization(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
Microsoft.Extensions.DependencyInjection.MvcDataAnnotationsMvcCoreBuilderExtensions.AddDataAnnotations(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
Microsoft.Extensions.DependencyInjection.TagHelperServicesExtensions.AddCacheTagHelper(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
and Microsoft.Extensions.DependencyInjection.MvcRazorPagesMvcCoreBuilderExtensions.AddRazorPages(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder).

### &#x20;AddViews Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Adds support for Controllers and Razor views to the [AspNetCoreBreakdanceTestBase.TestHostBuilder](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md#testhostbuilder).

#### Syntax

```csharp theme={"dark"}
public void AddViews(System.Action<Microsoft.AspNetCore.Mvc.MvcOptions> options = null, System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder> app = null)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `options` | `System.Action<Microsoft.AspNetCore.Mvc.MvcOptions>` | - |
| `app` | `System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder>` | - |

#### Remarks

Calls AddControllersWithViews() on the [IServiceCollection](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection) which does the following, according to the Microsoft docs:
combines the effects of Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(Microsoft.Extensions.DependencyInjection.IServiceCollection),
Microsoft.Extensions.DependencyInjection.MvcApiExplorerMvcCoreBuilderExtensions.AddApiExplorer(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
Microsoft.Extensions.DependencyInjection.MvcCoreMvcCoreBuilderExtensions.AddAuthorization(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
Microsoft.Extensions.DependencyInjection.MvcCorsMvcCoreBuilderExtensions.AddCors(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
Microsoft.Extensions.DependencyInjection.MvcDataAnnotationsMvcCoreBuilderExtensions.AddDataAnnotations(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
Microsoft.Extensions.DependencyInjection.MvcCoreMvcCoreBuilderExtensions.AddFormatterMappings(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
Microsoft.Extensions.DependencyInjection.TagHelperServicesExtensions.AddCacheTagHelper(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
Microsoft.Extensions.DependencyInjection.MvcViewFeaturesMvcCoreBuilderExtensions.AddViews(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder),
and Microsoft.Extensions.DependencyInjection.MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder).

### &#x20;AssemblySetup Override

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Method used by test assemblies to setup the environment.

#### Syntax

```csharp theme={"dark"}
public override void AssemblySetup()
```

#### Remarks

With MSTest, use \[AssemblyInitialize].
With NUnit, use \[OneTimeSetup].
With xUnit, good luck: [https://xunit.net/docs/shared-context](https://xunit.net/docs/shared-context)

### &#x20;AssemblySetupAsync Override

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Method used by test assemblies to setup the environment asynchronously.

#### Syntax

```csharp theme={"dark"}
public override System.Threading.Tasks.Task AssemblySetupAsync()
```

#### Returns

Type: `System.Threading.Tasks.Task`

#### Remarks

With MSTest, use \[AssemblyInitialize].
With NUnit, use \[OneTimeSetUp].
With xUnit, good luck: [https://xunit.net/docs/shared-context](https://xunit.net/docs/shared-context)

### &#x20;EnsureTestServer Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Ensures that the [AspNetCoreBreakdanceTestBase.TestServer](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md#testserver) has been constructed.

#### Syntax

```csharp theme={"dark"}
internal void EnsureTestServer()
```

#### Remarks

Builds the host using [IHostBuilder](https://easyaf.nimbleapps.cloud/breakdance/api-reference/Microsoft/Extensions/Hosting/IHostBuilder.md), starts it, and retrieves the [AspNetCoreBreakdanceTestBase.TestServer](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md#testserver) from the host services.

### &#x20;EnsureTestServerAsync Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Ensures that the [AspNetCoreBreakdanceTestBase.TestServer](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md#testserver) has been constructed asynchronously.

#### Syntax

```csharp theme={"dark"}
internal System.Threading.Tasks.Task EnsureTestServerAsync()
```

#### Returns

Type: `System.Threading.Tasks.Task`

#### Remarks

Builds the host using [IHostBuilder](https://easyaf.nimbleapps.cloud/breakdance/api-reference/Microsoft/Extensions/Hosting/IHostBuilder.md), starts it, and retrieves the [AspNetCoreBreakdanceTestBase.TestServer](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md#testserver) from the host services.

### &#x20;GetHttpClient Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Retrieves an [HttpClient](https://easyaf.nimbleapps.cloud/breakdance/api-reference/System/Net/Http/HttpClient.md) instance from the [AspNetCoreBreakdanceTestBase.TestServer](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md#testserver) and properly configures the [BaseAddress](https://learn.microsoft.com/dotnet/api/system.net.http.httpclient.baseaddress).

#### Syntax

```csharp theme={"dark"}
public System.Net.Http.HttpClient GetHttpClient(string routePrefix = "api/tests/")
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `routePrefix` | `string` | The string to append to the [BaseAddress](https://learn.microsoft.com/dotnet/api/system.net.http.httpclient.baseaddress) for all requests. Defaults to [WebApiConstants.RoutePrefix](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/WebApiConstants.md#routeprefix). |

#### Returns

Type: `System.Net.Http.HttpClient`
A properly configured [HttpClient](https://easyaf.nimbleapps.cloud/breakdance/api-reference/System/Net/Http/HttpClient.md)instance from the [AspNetCoreBreakdanceTestBase.TestServer](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md#testserver).

### &#x20;GetHttpClient Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Retrieves an [HttpClient](https://easyaf.nimbleapps.cloud/breakdance/api-reference/System/Net/Http/HttpClient.md) instance from the [AspNetCoreBreakdanceTestBase.TestServer](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md#testserver) and properly configures the [BaseAddress](https://learn.microsoft.com/dotnet/api/system.net.http.httpclient.baseaddress).

#### Syntax

```csharp theme={"dark"}
public System.Net.Http.HttpClient GetHttpClient(System.Net.Http.Headers.AuthenticationHeaderValue authHeader, string routePrefix = "api/tests/")
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `authHeader` | `System.Net.Http.Headers.AuthenticationHeaderValue` | - |
| `routePrefix` | `string` | The string to append to the [BaseAddress](https://learn.microsoft.com/dotnet/api/system.net.http.httpclient.baseaddress) for all requests. Defaults to [WebApiConstants.RoutePrefix](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/WebApiConstants.md#routeprefix). |

#### Returns

Type: `System.Net.Http.HttpClient`
A properly configured [HttpClient](https://easyaf.nimbleapps.cloud/breakdance/api-reference/System/Net/Http/HttpClient.md)instance from the [AspNetCoreBreakdanceTestBase.TestServer](https://easyaf.nimbleapps.cloud/breakdance/api-reference/CloudNimble/Breakdance/AspNetCore/AspNetCoreBreakdanceTestBase.md#testserver).

### &#x20;GetKeyedService Override

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Get service of type *T* from the System.IServiceProvider.

#### Syntax

```csharp theme={"dark"}
public override T GetKeyedService<T>(string key) where T : class
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `key` | `string` | The key of the service to get. |

#### Returns

Type: `T`
A service object of type *T*.

#### Type Parameters

* `T` - The type of service object to get.

### &#x20;GetKeyedServices Override

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Get services of type *T* from the System.IServiceProvider.

#### Syntax

```csharp theme={"dark"}
public override System.Collections.Generic.IEnumerable<T> GetKeyedServices<T>(string key) where T : class
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `key` | `string` | The |

#### Returns

Type: `System.Collections.Generic.IEnumerable<T>`
An [IEnumerable\`1](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1) of type *T*.

#### Type Parameters

* `T` - The type of service object to get.

### &#x20;GetService Override

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Get service of type *T* from the System.IServiceProvider.

#### Syntax

```csharp theme={"dark"}
public override T GetService<T>() where T : class
```

#### Returns

Type: `T`
A service object of type *T*.

#### Type Parameters

* `T` - The type of service object to get.

### &#x20;GetServices Override

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Get an enumeration of services of type *T* from the System.IServiceProvider.

#### Syntax

```csharp theme={"dark"}
public override System.Collections.Generic.IEnumerable<T> GetServices<T>() where T : class
```

#### Returns

Type: `System.Collections.Generic.IEnumerable<T>`
An enumeration of services of type *T*.

#### Type Parameters

* `T` - The type of service object to get.

### &#x20;TestSetup Override

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Method used by test classes to setup the environment.

#### Syntax

```csharp theme={"dark"}
public override void TestSetup()
```

#### Remarks

With MSTest, use \[TestInitialize].
With NUnit, use \[Setup].
With xUnit, good luck: [https://xunit.net/docs/shared-context](https://xunit.net/docs/shared-context)

### &#x20;TestSetupAsync Override

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Method used by test classes to setup the environment asynchronously.

#### Syntax

```csharp theme={"dark"}
public override System.Threading.Tasks.Task TestSetupAsync()
```

#### Returns

Type: `System.Threading.Tasks.Task`

#### Remarks

With MSTest, use \[TestInitialize].
With NUnit, use \[SetUp].
With xUnit, good luck: [https://xunit.net/docs/shared-context](https://xunit.net/docs/shared-context)

### &#x20;TestTearDown Override

> [!NOTE]
>
> Inherited from `CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase`

Method used by test classes to clean up the environment.

#### Syntax

```csharp theme={"dark"}
public override void TestTearDown()
```

#### Remarks

With MSTest, use \[TestCleanup].
With NUnit, use \[TearDown].
With xUnit, good luck: [https://xunit.net/docs/shared-context](https://xunit.net/docs/shared-context)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.