Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.0.1 #2

Merged
merged 6 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[*.cs]
[*]
indent_style = space
indent_size = 4

[*.cs]

# StyleCop

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,25 @@ Using the previous approach, the [PosInformatique.UnitTests.Databases](https://g

The [PosInformatique.UnitTests.Databases](https://github.com/PosInformatique/PosInformatique.UnitTests.Databases) tools are provided in two NuGet packages:

- [![Nuget](https://img.shields.io/nuget/v/PosInformatique.UnitTests.Databases.SqlServer)](https://www.nuget.org/packages/PosInformatique.UnitTests.Databases.SqlServer) which contains:
- [PosInformatique.UnitTests.Databases.SqlServer](https://www.nuget.org/packages/PosInformatique.UnitTests.Databases.SqlServer) NuGet package which contains:
- Tools to deploy a SQL Server database using a DACPAC file before each unit test.
- Helpers to initialize SQL Server databases with sample data.
- Helpers to easily query SQL Server databases.

- [![Nuget](https://img.shields.io/nuget/v/PosInformatique.UnitTests.Databases.SqlServer.EntityFramework)](https://www.nuget.org/packages/PosInformatique.UnitTests.Databases.SqlServer.EntityFramework) which contains:
- [PosInformatique.UnitTests.Databases.SqlServer.EntityFramework](https://www.nuget.org/packages/PosInformatique.UnitTests.Databases.SqlServer.EntityFramework) NuGet package which contains:
- Tools to deploy a SQL Server database using a DbContext.

This package uses and includes the previous [PosInformatique.UnitTests.Databases.SqlServer](https://www.nuget.org/packages/PosInformatique.UnitTests.Databases.SqlServer) NuGet package.

## Samples / Demo

A complete sample solution is available in this repository in the [./samples](./samples) folder.
A complete sample solution is available in this repository inside the [samples](./samples) folder.

The solution contains the following projects:
The solution contains the following sample projects:
- [DemoApp.Domain](./samples/DemoApp.Domain/DemoApp.Domain.csproj): Represents the domain of the application with a set of sample business entities.
- [DemoApp.DataAccessLayer](./samples/DemoApp.DataAccessLayer/DemoApp.DataAccessLayer.csproj): Represents a Data Access Layer with a set of repositories to unit test.
- [DemoApp.DataAccessLayer.Tests](./samples/DemoApp.DataAccessLayer.Tests/DemoApp.DataAccessLayer.Tests.csproj): Unit test project to test the [DemoApp.DataAccessLayer](./samples/DemoApp.DataAccessLayer/DemoApp.DataAccessLayer.csproj)
- project using the [PosInformatique.UnitTests.Databases.SqlServer](https://www.nuget.org/packages/PosInformatique.UnitTests.Databases.SqlServer) package.
project using the [PosInformatique.UnitTests.Databases.SqlServer.EntityFramework](https://www.nuget.org/packages/PosInformatique.UnitTests.Databases.SqlServer.EntityFramework) package.

## Writing unit tests for a Data Access Layer

Expand Down
4 changes: 3 additions & 1 deletion docs/WriteUnitTests.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class CustomerRepository

Which use the following `DbContext` implementation:

```json
```csharp
public class DemoAppDbContext : DbContext
{
public DemoAppDbContext(DbContextOptions<DemoAppDbContext> options)
Expand Down Expand Up @@ -282,6 +282,7 @@ this.database.InsertCustomer(id: 10, firstName: "John", lastName: "DOE");

In the end, if we want to insert 3 `Customer` rows in the database, the `CustomerRepositoryTest` constructor should look like this code:

```csharp
public CustomerRepositoryTest(SqlServerDatabaseInitializer initializer)
{
using var dbContext = new DemoAppDbContext(UnitTestsConnectionStrings.CreateDbContextOptions<DemoAppDbContext>(DatabaseName));
Expand All @@ -292,6 +293,7 @@ public CustomerRepositoryTest(SqlServerDatabaseInitializer initializer)
this.database.InsertCustomer(id: 15, firstName: "Marcel", lastName: "DUPONT", revenue: 4852.45);
this.database.InsertCustomer(id: 20, firstName: "Andres", lastName: "GARCIA");
}
```

Now, every time we will execute an unit test in the `CustomerRepositoryTest` class,
a database will be deployed with these 3 `Customer` before the execution of the unit test.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes>
1.0.0
- Initial version
1.0.1
- Fix the documentation

1.0.0
- Initial version
</PackageReleaseNotes>
<PackageTags>unittest entityframework sqlserver repository tdd dataaccesslayer</PackageTags>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes>
1.0.0
- Initial version
1.0.1
- Fix the documentation

1.0.0
- Initial version
</PackageReleaseNotes>
<PackageTags>unittest sqlserver repository tdd dataaccesslayer</PackageTags>
</PropertyGroup>
Expand Down
Loading