-
Notifications
You must be signed in to change notification settings - Fork 1
How implement testing support for different than NUnit, xUnit or MsTest Framework
NightAngell edited this page Feb 23, 2019
·
9 revisions
There is one simple condition. Framework must have possibility to execute code before and after each test. If it not support that features and you still want use my lib with your favourite testing framework don't worry, you still can use my lib (see this).
-
Create new class library project for .netCore (2.1+), name your project using this:
SignalR_UnitTestingSupport[ name of testing framework ]
. -
Add AspNetCore.SignalR.UnitTestingSupport.Common nuget to your project (and your testing framework nuget).
-
Create Hubs folder inside main project directory.
-
Create HubUnitTestsBase.cs file inside Hubs directory.
-
Copy this and paste to that file. Don't change class name (cause docs). Remove unnecessary comments. Add required usings.
public abstract class HubUnitTestsBase : HubUnitTestsSupport
{
//Attribute to be sure that, somebody don`t call it manually (some testing frameworks required public methods,
//but framework and only that framework should call this)
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
//Method which is executed before each test
public void HubUnitTestSupportSetUp()
{
SetUp();
}
}
- Create HubUnitTestsBaseT.cs file inside Hubs directory.
- Copy this and paste to that file. Don't change class name (cause docs). Remove unnecessary comments. Add required usings.
public abstract class HubUnitTestsBase<TIHubResponses> : HubUnitTestsSupport<TIHubResponses>
where TIHubResponses : class
{
//Attribute to be sure that, somebody don`t call it manually (some testing frameworks required public methods,
//but framework and only that framework should call this)
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
//Method which is executed before each test
public void BaseSetUp()
{
SetUp();
}
}
- Create HubUnitTestsWithEF file inside Hubs directory.
- Copy this and paste to that file. Don't change class name (cause docs). Remove unnecessary comments. Add required usings.
public abstract class HubUnitTestsWithEF<TDbContext> : HubUnitTestsWithEFSupport<TDbContext>
where TDbContext : DbContext
{
//Attribute to be sure that, somebody don`t call it manually (some testing frameworks required public methods,
//but framework and only that framework should call this)
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
//Method which is executed before each test
public void EfSetUp()
{
SetUp();
}
//Attribute to be sure that, somebody don`t call it manually (some testing frameworks required public methods,
//but framework and only that framework should call this)
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
//Method which is executed after each test
public void TearDownEFContexts()
{
TearDown();
}
}
- Create HubUnitTestsWithEF` file inside Hubs directory.
- Copy this and paste to that file. Don't change class name (cause docs). Remove unnecessary comments. Add required usings.
public abstract class HubUnitTestsWithEF<TIHubResponses, TDbContext>
: HubUnitTestsWithEFSupport<TIHubResponses, TDbContext>
where TIHubResponses: class
where TDbContext : DbContext
{
//Attribute to be sure that, somebody don`t call it manually (some testing frameworks required public methods,
//but framework and only that framework should call this)
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
//Method which is executed before each test
public void EfSetUp()
{
SetUp();
}
//Attribute to be sure that, somebody don`t call it manually (some testing frameworks required public methods,
//but framework and only that framework should call this)
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
//Method which is executed after each test
public void TearDownEFContexts()
{
TearDown();
}
}