Skip to content

Commit 668f071

Browse files
author
Bart Koelman
authored
Updated build scripts to use auto-discovery (#683)
* Fixed another cause for random test failures The problem: NoEntityFrameworkTests project has a reference to UnitTests project, which has a reference to JsonApiDotNetCoreExampleTests project, which has a reference to JsonApiDotNetCoreExample project. The last one contains an appsettings.json file with connection string to JsonApiDotNetCoreExample database. So when building, this file may end up in the output directory of NoEntityFrameworkTests project, overwriting the appsettings.json (containing the connection string to JsonApiDotNetCoreNoEFCoreExample database) from NoEntityFrameworkExample project. Next, if the NoEntityFrameworkTests testset runs first, it populates the JsonApiDotNetCoreExample database from models intended for the JsonApiDotNetCoreNoEFCoreExample database. And this causes subsequent test projects to fail. * Updated build scripts to use auto-discovery * Tried another workaround
1 parent 9fd3fc7 commit 668f071

File tree

8 files changed

+41
-48
lines changed

8 files changed

+41
-48
lines changed

Build.ps1

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,26 @@ $revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BU
2222
$revision = "{0:D4}" -f [convert]::ToInt32($revision, 10)
2323

2424
dotnet restore
25+
CheckLastExitCode
2526

26-
dotnet build ./src/Examples/GettingStarted/GettingStarted.csproj
27+
dotnet build -c Release
2728
CheckLastExitCode
2829

29-
dotnet test ./test/UnitTests/UnitTests.csproj
30+
# Workaround: running 'dotnet test -c Release' fails for yet unknown reasons on AppVeyor, so we run tests one by one.
31+
32+
dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj -c Release --no-build
3033
CheckLastExitCode
3134

32-
dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj
35+
dotnet test ./test/DiscoveryTests/DiscoveryTests.csproj -c Release --no-build
3336
CheckLastExitCode
3437

35-
dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj
38+
dotnet test ./test/IntegrationTests/IntegrationTests.csproj -c Release --no-build
3639
CheckLastExitCode
3740

38-
dotnet test ./test/DiscoveryTests/DiscoveryTests.csproj
41+
dotnet test ./test/UnitTests/UnitTests.csproj -c Release --no-build
3942
CheckLastExitCode
4043

41-
dotnet build ./src/JsonApiDotNetCore/JsonApiDotNetCore.csproj -c Release
44+
dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj -c Release --no-build
4245
CheckLastExitCode
4346

4447
Write-Output "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG"

build.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@
44
set -e
55

66
dotnet restore
7-
8-
dotnet test ./test/UnitTests/UnitTests.csproj
9-
dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj
10-
dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj
7+
dotnet build -c Release
8+
dotnet test -c Release --no-build

src/Examples/NoEntityFrameworkExample/Startup.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using JsonApiDotNetCore.Extensions;
23
using JsonApiDotNetCore.Services;
34
using Microsoft.AspNetCore.Builder;
@@ -37,7 +38,7 @@ public virtual void ConfigureServices(IServiceCollection services)
3738
);
3839
services.AddScoped<IResourceService<TodoItem>, TodoItemService>();
3940
var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>();
40-
optionsBuilder.UseNpgsql(GetDbConnectionString());
41+
optionsBuilder.UseNpgsql(GetDbConnectionString(), options => options.SetPostgresVersion(new Version(9,6)));
4142
services.AddSingleton<IConfiguration>(Configuration);
4243
services.AddSingleton(optionsBuilder.Options);
4344
services.AddScoped<AppDbContext>();

src/JsonApiDotNetCore/JsonApiDotNetCore.sln

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

test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.sln

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

test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
</ItemGroup>
1616
<ItemGroup>
1717
<ProjectReference Include="../../src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj" />
18-
<ProjectReference Include="../UnitTests/UnitTests.csproj" />
1918
<ProjectReference Include="..\..\src\JsonApiDotNetCore\JsonApiDotNetCore.csproj" />
2019
</ItemGroup>
2120
<ItemGroup>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using JsonApiDotNetCore.Services;
3+
using Microsoft.AspNetCore.Http;
4+
using Moq;
5+
6+
namespace NoEntityFrameworkTests
7+
{
8+
public class TestScopedServiceProvider : IScopedServiceProvider
9+
{
10+
private readonly IServiceProvider _serviceProvider;
11+
private Mock<IHttpContextAccessor> _httpContextAccessorMock = new Mock<IHttpContextAccessor>();
12+
13+
public TestScopedServiceProvider(IServiceProvider serviceProvider)
14+
{
15+
_serviceProvider = serviceProvider;
16+
}
17+
18+
public object GetService(Type serviceType)
19+
{
20+
if (serviceType == typeof(IHttpContextAccessor))
21+
{
22+
return _httpContextAccessorMock.Object;
23+
}
24+
25+
return _serviceProvider.GetService(serviceType);
26+
}
27+
}
28+
}

test/NoEntityFrameworkTests/TestStartup.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using Microsoft.AspNetCore.Hosting;
33
using Microsoft.Extensions.DependencyInjection;
44
using NoEntityFrameworkExample;
5-
using System;
6-
using UnitTests;
75

86
namespace NoEntityFrameworkTests
97
{

0 commit comments

Comments
 (0)