forked from vb-consulting/PgRoutinerDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup unit tests and add companies controller
- Loading branch information
Showing
23 changed files
with
495 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
CompaniesWebBlazor/CompaniesDbTests/CompaniesDbTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Update="testsettings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\CompaniesDb\CompaniesDb.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="3.0.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="FluentAssertions" Version="5.10.3" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" /> | ||
<PackageReference Include="Norm.net" Version="3.2.0" /> | ||
<PackageReference Include="Npgsql" Version="5.0.4" /> | ||
<PackageReference Include="System.Linq.Async" Version="5.0.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |
49 changes: 49 additions & 0 deletions
49
CompaniesWebBlazor/CompaniesDbTests/CreateOnConflictDoUpdateReturningCompaniesUnitTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// <auto-generated /> | ||
using System; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Norm; | ||
using FluentAssertions; | ||
using CompaniesDb.Extensions; | ||
using CompaniesWebBlazor.Shared; | ||
|
||
namespace CompaniesDbTests | ||
{ | ||
public class CreateOnConflictDoUpdateReturningCompaniesUnitTests : PostgreSqlUnitTestFixture | ||
{ | ||
public CreateOnConflictDoUpdateReturningCompaniesUnitTests(PostgreSqlFixture fixture) : base(fixture) { } | ||
|
||
[Fact] | ||
public void CreateOnConflictDoUpdateReturningCompanies_Test1() | ||
{ | ||
// Arrange | ||
var model = new Company { Name = "n", NameNormalized = "nn", About = "about", AreaId = 1, Website = "website" }; | ||
|
||
// Act | ||
var result = Connection.CreateOnConflictDoUpdateReturningCompanies(model); | ||
|
||
// Assert | ||
model.Should().BeEquivalentTo(result, | ||
o => o.Excluding(c => c.Id).Excluding(c => c.Modified)); // Id and Modified are generated fields | ||
} | ||
|
||
[Fact] | ||
public void CreateOnConflictDoUpdateReturningCompanies_Test2_Upsert() | ||
{ | ||
// Arrange | ||
var model1 = new Company { Name = "n", NameNormalized = "nn", About = "about", AreaId = 1, Website = "website" }; | ||
var model2 = new Company { Name = "n2", NameNormalized = "nn", About = "about2", AreaId = 1, Website = "website2" }; | ||
|
||
// Act | ||
var result1 = Connection.CreateOnConflictDoUpdateReturningCompanies(model1); | ||
var result2 = Connection.CreateOnConflictDoUpdateReturningCompanies(model2, "name_normalized"); // name_normalized is unique index | ||
|
||
// Assert | ||
model2.Should().BeEquivalentTo(result2, | ||
o => o.Excluding(c => c.Id).Excluding(c => c.Modified)); // Id and Modified are generated fields | ||
Assert.Equal(result1.Id, result2.Id); // confirm that it is indeed same record updated | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
CompaniesWebBlazor/CompaniesDbTests/DeleteCompaniesUnitTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// <auto-generated /> | ||
using System; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Norm; | ||
using FluentAssertions; | ||
using CompaniesDb.Extensions; | ||
using CompaniesWebBlazor.Shared; | ||
|
||
namespace CompaniesDbTests | ||
{ | ||
public class DeleteCompaniesUnitTests : PostgreSqlUnitTestFixture | ||
{ | ||
public DeleteCompaniesUnitTests(PostgreSqlFixture fixture) : base(fixture) { } | ||
|
||
[Fact] | ||
public void DeleteCompanies_Test1() | ||
{ | ||
// Arrange | ||
var model = new Company { Name = "n", NameNormalized = "nn", About = "about", AreaId = 1, Website = "website" }; | ||
var result = Connection.CreateOnConflictDoUpdateReturningCompanies(model); | ||
|
||
// Act | ||
Connection.DeleteCompanies(result); | ||
|
||
// Assert | ||
Assert.False(Connection.Read($"select * from {CompaniesDelete.Name} where id = {result.Id}").Any()); | ||
} | ||
} | ||
} |
Oops, something went wrong.