Skip to content

Commit 7015b21

Browse files
author
Bart Koelman
authored
Fix for non-deterministic failing tests (#669)
* Moved tests for `NoEntityFrameworkTests` into a different database, because two variants of `TodoItem` exist (where one is a subset of the other), causing tests to fail/succeed depending on their execution order. A separate database is needed instead of schema, because `context.Database.EnsureCreated()` only checks for database existence and does not create additional tables when the database already exists. Furthermore, I decided to remove fields from `NoEntityFrameworkExample.Models.TodoItem` that do not exist in the INSERT SQL statement in `NoEntityFrameworkExample.Services.TodoItemService` and because non-nullable CreatedDate causes insert to fail. * Fixed another bug, where tests would sometimes fail This occured when working in the solution for a while, building and rebuilding one or more projects individually. What happened is that the appsettings.json from NoEntityFrameworkCoreExample project would overwrite the one from JsonApiDotNetCoreExample in the output folder of JsonApiDotNetCoreExample. Causing that project to reference the wrong database. I solved this by removing the unneeded dependency between these projects and by relying on automatic copying of appsettings by the project system. I removed the copied appsettings.json files from the test projects, which end up in the output directory anyway (because they reference the *Example projects). * Fixed invalid logging configuration
1 parent d7d8a79 commit 7015b21

File tree

7 files changed

+6
-51
lines changed

7 files changed

+6
-51
lines changed

src/Examples/JsonApiDotNetCoreExample/appsettings.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
"Default": "Warning",
99
"System": "Warning",
1010
"Microsoft": "Warning",
11-
"LogLevel": {
12-
"Microsoft.EntityFrameworkCore": "Debug"
13-
}
11+
"Microsoft.EntityFrameworkCore": "Debug"
1412
}
1513
}
1614
}

src/Examples/NoEntityFrameworkExample/Models/TodoItem.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,5 @@ public TodoItem()
2020

2121
[Attr]
2222
public Guid GuidProperty { get; set; }
23-
24-
[Attr]
25-
public DateTime CreatedDate { get; set; }
26-
27-
[Attr(isFilterable: false, isSortable: false)]
28-
public DateTime? AchievedDate { get; set; }
29-
30-
[Attr]
31-
public DateTime? UpdatedDate { get; set; }
32-
33-
[Attr]
34-
public DateTimeOffset? OffsetDate { get; set; }
3523
}
3624
}

src/Examples/NoEntityFrameworkExample/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{
1+
{
22
"Data": {
3-
"DefaultConnection": "Host=localhost;Port=5432;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=postgres"
3+
"DefaultConnection": "Host=localhost;Port=5432;Database=JsonApiDotNetCoreNoEFCoreExample;User ID=postgres;Password=postgres"
44
},
55
"Logging": {
66
"IncludeScopes": false,

test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<None Update="xunit.runner.json;appsettings.json">
8+
<None Update="xunit.runner.json">
99
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1010
</None>
1111
</ItemGroup>
1212

1313
<ItemGroup>
1414
<ProjectReference Include="../../src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj" />
15-
<ProjectReference Include="../../src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj" />
1615
<ProjectReference Include="../UnitTests/UnitTests.csproj" />
1716
</ItemGroup>
1817

test/JsonApiDotNetCoreExampleTests/appsettings.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>$(NetCoreAppVersion)</TargetFramework>
44
<PreserveCompilationContext>true</PreserveCompilationContext>
@@ -9,7 +9,7 @@
99
<ServerGarbageCollection>true</ServerGarbageCollection>
1010
</PropertyGroup>
1111
<ItemGroup>
12-
<None Update="xunit.runner.json;appsettings.json">
12+
<None Update="xunit.runner.json">
1313
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1414
</None>
1515
</ItemGroup>

test/NoEntityFrameworkTests/appsettings.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)