Skip to main content

Definition

Assembly: CloudNimble.Breakdance.AspNetCore.dll Namespace: CloudNimble.Breakdance.AspNetCore Inheritance: CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase

Syntax

Summary

A base class for building unit tests for AspNetCore APIs that automatically maintains a TestServer with configuration and a Dependency Injection containers for you.

Type Parameters

  • TStartup -

Constructors

.ctor

Creates a new AspNetCoreBreakdanceTestBase instance.

Syntax

Remarks

The call to .Configure() with no content is required to get a minimal, empty IWebHost.

.ctor Inherited

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Creates a new AspNetCoreBreakdanceTestBase instance.

Syntax

Remarks

Uses the modern IHostBuilder pattern for web hosting instead of the deprecated WebHostBuilder.

Properties

TestHostBuilder Inherited

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Replaces the AspNetCoreBreakdanceTestBase.TestHostBuilder from the BreakdanceTestBase with an IHostBuilder implementation configured for web hosting.

Syntax

Property Value

Type: Microsoft.Extensions.Hosting.IHostBuilder

TestServer Inherited

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
The AspNetCoreBreakdanceTestBase.TestServer for handling requests.

Syntax

Property Value

Type: Microsoft.AspNetCore.TestHost.TestServer

Methods

AddApis Inherited

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Adds Controller services to the AspNetCoreBreakdanceTestBase.TestHostBuilder.

Syntax

Parameters

Remarks

Calls AddControllers() on the 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).

AddMinimalMvc Inherited

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Adds minimal MVC services to the AspNetCoreBreakdanceTestBase.TestHostBuilder.

Syntax

Parameters

Remarks

Calls AddMvcCore() on the 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.

AddRazorPages Inherited

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Adds support for Controllers and Razor views to the AspNetCoreBreakdanceTestBase.TestHostBuilder.

Syntax

Parameters

Remarks

Calls AddRazorPages() on the 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).

AddViews Inherited

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Adds support for Controllers and Razor views to the AspNetCoreBreakdanceTestBase.TestHostBuilder.

Syntax

Parameters

Remarks

Calls AddControllersWithViews() on the 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).

AssemblySetup Override

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Method used by test assemblies to setup the environment.

Syntax

Remarks

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

AssemblySetupAsync Override

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Method used by test assemblies to setup the environment asynchronously.

Syntax

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

EnsureTestServer Inherited

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Ensures that the AspNetCoreBreakdanceTestBase.TestServer has been constructed.

Syntax

Remarks

Builds the host using IHostBuilder, starts it, and retrieves the AspNetCoreBreakdanceTestBase.TestServer from the host services.

EnsureTestServerAsync Inherited

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Ensures that the AspNetCoreBreakdanceTestBase.TestServer has been constructed asynchronously.

Syntax

Returns

Type: System.Threading.Tasks.Task

Remarks

Builds the host using IHostBuilder, starts it, and retrieves the AspNetCoreBreakdanceTestBase.TestServer from the host services.

GetHttpClient Inherited

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Retrieves an HttpClient instance from the AspNetCoreBreakdanceTestBase.TestServer and properly configures the BaseAddress.

Syntax

Parameters

Returns

Type: System.Net.Http.HttpClient A properly configured HttpClientinstance from the AspNetCoreBreakdanceTestBase.TestServer.

GetHttpClient Inherited

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Retrieves an HttpClient instance from the AspNetCoreBreakdanceTestBase.TestServer and properly configures the BaseAddress.

Syntax

Parameters

Returns

Type: System.Net.Http.HttpClient A properly configured HttpClientinstance from the AspNetCoreBreakdanceTestBase.TestServer.

GetKeyedService Override

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Get service of type T from the System.IServiceProvider.

Syntax

Parameters

Returns

Type: T A service object of type T.

Type Parameters

  • T - The type of service object to get.

GetKeyedServices Override

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Get services of type T from the System.IServiceProvider.

Syntax

Parameters

Returns

Type: System.Collections.Generic.IEnumerable<T> An IEnumerable`1 of type T.

Type Parameters

  • T - The type of service object to get.

GetService Override

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Get service of type T from the System.IServiceProvider.

Syntax

Returns

Type: T A service object of type T.

Type Parameters

  • T - The type of service object to get.

GetServices Override

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Get an enumeration of services of type T from the System.IServiceProvider.

Syntax

Returns

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

Type Parameters

  • T - The type of service object to get.

TestSetup Override

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Method used by test classes to setup the environment.

Syntax

Remarks

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

TestSetupAsync Override

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Method used by test classes to setup the environment asynchronously.

Syntax

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

TestTearDown Override

Inherited from CloudNimble.Breakdance.AspNetCore.AspNetCoreBreakdanceTestBase
Method used by test classes to clean up the environment.

Syntax

Remarks

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