TheStandardBox.Data.Tests.Unit
1.0.1
See the version list below for details.
dotnet add package TheStandardBox.Data.Tests.Unit --version 1.0.1
NuGet\Install-Package TheStandardBox.Data.Tests.Unit -Version 1.0.1
<PackageReference Include="TheStandardBox.Data.Tests.Unit" Version="1.0.1" />
paket add TheStandardBox.Data.Tests.Unit --version 1.0.1
#r "nuget: TheStandardBox.Data.Tests.Unit, 1.0.1"
// Install TheStandardBox.Data.Tests.Unit as a Cake Addin #addin nuget:?package=TheStandardBox.Data.Tests.Unit&version=1.0.1 // Install TheStandardBox.Data.Tests.Unit as a Cake Tool #tool nuget:?package=TheStandardBox.Data.Tests.Unit&version=1.0.1
TheStandardBox
A .NET Library for essential code according to The Standard
Installation
Install the nuget package in your API project:
NuGet\Install-Package TheStandardBox.Data -Version 1.0.0
How to use?
This library will allow to you to use easly a sort of standard Storage Broker, Foundation Servicer and Controller:
Add your models
Your models, that represents your database entities, should implement the interface IStandardEntity
of the library:
public interface IStandardEntity
{
Guid Id { get; set; }
DateTimeOffset CreatedDate { get; set; }
DateTimeOffset UpdatedDate { get; set; }
}
For example an entity WeatherForecast
looks like:
public class WeatherForecast : IStandardEntity
{
public Guid Id { get; set; }
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string Summary { get; set; }
public DateTimeOffset CreatedDate { get; set; }
public DateTimeOffset UpdatedDate { get; set; }
}
Standard Storage Broker
In order to define your DbSets
ou need to create a new storage broker that inhirates from StandardStorageBroker
:
public class StorageBroker : StandardStorageBroker
{
public StorageBroker(IConfiguration configuration)
: base(configuration)
{ }
public DbSet<WeatherForecast> WeatherForecasts { get; set; }
}
Connection String
By default TheStandardBox reads the connection string from your configuration by the name DefaultConnection
.
You can define the name of your connection string:
public class StorageBroker : StandardStorageBroker
{
public StorageBroker(IConfiguration configuration)
: base(configuration)
{ }
protected override string DefaultConnectionName => "NEW_CONNECTION_STRING_NAME";
public DbSet<WeatherForecast> WeatherForecasts { get; set; }
}
Uses NoTracking Behavior
To use the NoTracking
behavior or not, override the property UsesNoTrackingBehavior
(By default true
):
protected override bool UsesNoTrackingBehavior => false;
Add TheStandard Box
Add the library as following in the Program.cs
file of your API project:
builder.Services.AddTheStandardBoxData<StorageBroker>();
Migrations
Dont forget to add a migration by running > Add-Migration [MIGRATION_NAME]
.
Foundation Service
For each entity add a standard foundation service as following:
builder.Services.AddStandardFoundationService<WeatherForecast>();
Unit testing ?
It is very important to unit test your services, using TheStandardBox this is now very easy. You need only to create your test class as following:
public class WeatherServiceTests : StandardServiceTests<WeatherForecast>
{ }
Support
For any question or infromation: contact@mahdhi.com
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Moq (>= 4.18.2)
- TheStandardBox.Data (>= 1.0.1)
- Tynamix.ObjectFiller (>= 1.5.8)
- xunit.assert (>= 2.4.2)
- xunit.extensibility.core (>= 2.4.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.