Skip to content

Commit b17c4d0

Browse files
author
Bart Koelman
committed
Fix cibuild (database isolation)
1 parent 3240b74 commit b17c4d0

File tree

13 files changed

+79
-80
lines changed

13 files changed

+79
-80
lines changed

Build.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ CheckLastExitCode
2929

3030
# Workaround: running 'dotnet test -c Release' fails for yet unknown reasons on AppVeyor, so we run tests one by one.
3131

32+
dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj -c Release --no-build
33+
CheckLastExitCode
34+
3235
dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj -c Release --no-build
3336
CheckLastExitCode
3437

@@ -41,9 +44,6 @@ CheckLastExitCode
4144
dotnet test ./test/UnitTests/UnitTests.csproj -c Release --no-build
4245
CheckLastExitCode
4346

44-
dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj -c Release --no-build
45-
CheckLastExitCode
46-
4747
Write-Output "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG"
4848

4949
If($env:APPVEYOR_REPO_TAG -eq $true) {
@@ -62,7 +62,7 @@ If($env:APPVEYOR_REPO_TAG -eq $true) {
6262
}
6363
}
6464
Else {
65-
Write-Output "VERSION-SUFFIX: alpha1-$revision"
65+
Write-Output "VERSION-SUFFIX: alpha5-$revision"
6666
Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision"
6767
dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision --include-symbols
6868
CheckLastExitCode

appveyor.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@ version: '{build}'
22
os: Visual Studio 2019
33

44
environment:
5-
POSTGRES_PORT: tcp://localhost:5432
6-
POSTGRES_ENV_POSTGRES_USER: postgres
7-
POSTGRES_ENV_POSTGRES_PASSWORD: Password12!
8-
POSTGRES_ENV_POSTGRES_DB: JsonApiDotNetCoreExample
95
PGUSER: postgres
106
PGPASSWORD: Password12!
11-
Data:DefaultConnection: "Host=localhost;Port=5432;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=Password12!"
127
ACCESS_TOKEN:
138
secure: g1T332Uarmdgtkftchpafa8tDP/7eM4O0BD6iu1wu+zR224IyH5R8pb4sTChr4Ia
149

@@ -63,10 +58,9 @@ init:
6358
- SET PATH=C:\Program Files\PostgreSQL\9.6\bin\;%PATH%
6459

6560
services:
66-
- postgresql
61+
- postgresql96
6762

6863
build_script:
69-
- ps: createdb JsonApiDotNetCoreExample
7064
- ps: dotnet --version
7165
- ps: .\Build.ps1
7266

src/Examples/JsonApiDotNetCoreExample/Startups/NoDefaultPageSizeStartup.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ namespace JsonApiDotNetCoreExample
99
/// </summary>
1010
public sealed class NoDefaultPageSizeStartup : TestStartup
1111
{
12-
public NoDefaultPageSizeStartup(IWebHostEnvironment env) : base(env) { }
12+
public NoDefaultPageSizeStartup(IWebHostEnvironment env) : base(env)
13+
{
14+
}
1315

1416
protected override void ConfigureJsonApiOptions(JsonApiOptions options)
1517
{

src/Examples/JsonApiDotNetCoreExample/Startups/Startup.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace JsonApiDotNetCoreExample
1616
{
1717
public class Startup
1818
{
19-
public readonly IConfiguration Config;
19+
private readonly string _connectionString;
2020

2121
public Startup(IWebHostEnvironment env)
2222
{
@@ -25,7 +25,10 @@ public Startup(IWebHostEnvironment env)
2525
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
2626
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
2727
.AddEnvironmentVariables();
28-
Config = builder.Build();
28+
var configuration = builder.Build();
29+
30+
string postgresPassword = Environment.GetEnvironmentVariable("PGPASSWORD") ?? "postgres";
31+
_connectionString = configuration["Data:DefaultConnection"].Replace("###", postgresPassword);
2932
}
3033

3134
public virtual void ConfigureServices(IServiceCollection services)
@@ -40,7 +43,7 @@ public virtual void ConfigureServices(IServiceCollection services)
4043
{
4144
options
4245
.EnableSensitiveDataLogging()
43-
.UseNpgsql(GetDbConnectionString(), innerOptions => innerOptions.SetPostgresVersion(new Version(9,6)));
46+
.UseNpgsql(_connectionString, innerOptions => innerOptions.SetPostgresVersion(new Version(9,6)));
4447
}, ServiceLifetime.Transient)
4548
.AddJsonApi<AppDbContext>(ConfigureJsonApiOptions, discovery => discovery.AddCurrentAssembly());
4649

@@ -72,7 +75,5 @@ public void Configure(
7275
context.Database.EnsureCreated();
7376
app.UseJsonApi();
7477
}
75-
76-
public string GetDbConnectionString() => Config["Data:DefaultConnection"];
7778
}
7879
}

src/Examples/JsonApiDotNetCoreExample/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Data": {
3-
"DefaultConnection": "Host=localhost;Port=5432;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=postgres"
3+
"DefaultConnection": "Host=localhost;Port=5432;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=###"
44
},
55
"Logging": {
66
"LogLevel": {

src/Examples/NoEntityFrameworkExample/Controllers/TodoItemsController.cs renamed to src/Examples/NoEntityFrameworkExample/Controllers/WorkItemsController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
namespace NoEntityFrameworkExample.Controllers
88
{
9-
public sealed class TodoItemsController : JsonApiController<TodoItem>
9+
public sealed class WorkItemsController : JsonApiController<WorkItem>
1010
{
11-
public TodoItemsController(
11+
public WorkItemsController(
1212
IJsonApiOptions jsonApiOptions,
1313
ILoggerFactory loggerFactory,
14-
IResourceService<TodoItem> resourceService)
14+
IResourceService<WorkItem> resourceService)
1515
: base(jsonApiOptions, loggerFactory, resourceService)
1616
{ }
1717
}

src/Examples/NoEntityFrameworkExample/Data/AppDbContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace NoEntityFrameworkExample.Data
55
{
66
public sealed class AppDbContext : DbContext
77
{
8-
public DbSet<TodoItem> TodoItems { get; set; }
8+
public DbSet<WorkItem> WorkItems { get; set; }
99

1010
public AppDbContext(DbContextOptions<AppDbContext> options)
1111
: base(options)

src/Examples/NoEntityFrameworkExample/Models/TodoItem.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using JsonApiDotNetCore.Models;
3+
4+
namespace NoEntityFrameworkExample.Models
5+
{
6+
public sealed class WorkItem : Identifiable
7+
{
8+
[Attr]
9+
public bool IsBlocked { get; set; }
10+
11+
[Attr]
12+
public string Title { get; set; }
13+
14+
[Attr]
15+
public long DurationInHours { get; set; }
16+
17+
[Attr]
18+
public Guid ProjectId { get; set; } = Guid.NewGuid();
19+
}
20+
}

src/Examples/NoEntityFrameworkExample/Services/TodoItemService.cs renamed to src/Examples/NoEntityFrameworkExample/Services/WorkItemService.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,26 @@
1111

1212
namespace NoEntityFrameworkExample.Services
1313
{
14-
public sealed class TodoItemService : IResourceService<TodoItem>
14+
public sealed class WorkItemService : IResourceService<WorkItem>
1515
{
1616
private readonly string _connectionString;
1717

18-
public TodoItemService(IConfiguration configuration)
18+
public WorkItemService(IConfiguration configuration)
1919
{
20-
_connectionString = configuration["Data:DefaultConnection"];
20+
string postgresPassword = Environment.GetEnvironmentVariable("PGPASSWORD") ?? "postgres";
21+
_connectionString = configuration["Data:DefaultConnection"].Replace("###", postgresPassword);
2122
}
2223

23-
public async Task<IEnumerable<TodoItem>> GetAsync()
24+
public async Task<IEnumerable<WorkItem>> GetAsync()
2425
{
2526
return await QueryAsync(async connection =>
26-
await connection.QueryAsync<TodoItem>(@"select * from ""TodoItems"""));
27+
await connection.QueryAsync<WorkItem>(@"select * from ""WorkItems"""));
2728
}
2829

29-
public async Task<TodoItem> GetAsync(int id)
30+
public async Task<WorkItem> GetAsync(int id)
3031
{
3132
var query = await QueryAsync(async connection =>
32-
await connection.QueryAsync<TodoItem>(@"select * from ""TodoItems"" where ""Id""=@id", new { id }));
33+
await connection.QueryAsync<WorkItem>(@"select * from ""WorkItems"" where ""Id""=@id", new { id }));
3334

3435
return query.Single();
3536
}
@@ -39,28 +40,28 @@ public Task<object> GetRelationshipAsync(int id, string relationshipName)
3940
throw new NotImplementedException();
4041
}
4142

42-
public Task<TodoItem> GetRelationshipsAsync(int id, string relationshipName)
43+
public Task<WorkItem> GetRelationshipsAsync(int id, string relationshipName)
4344
{
4445
throw new NotImplementedException();
4546
}
4647

47-
public async Task<TodoItem> CreateAsync(TodoItem entity)
48+
public async Task<WorkItem> CreateAsync(WorkItem entity)
4849
{
4950
return (await QueryAsync(async connection =>
5051
{
51-
var query = @"insert into ""TodoItems"" (""Description"", ""IsLocked"", ""Ordinal"", ""UniqueId"") values (@description, @isLocked, @ordinal, @uniqueId) returning ""Id"", ""Description"", ""IsLocked"", ""Ordinal"", ""UniqueId""";
52-
var result = await connection.QueryAsync<TodoItem>(query, new { description = entity.Description, ordinal = entity.Ordinal, uniqueId = entity.UniqueId, isLocked = entity.IsLocked });
52+
var query = @"insert into ""WorkItems"" (""Title"", ""IsBlocked"", ""DurationInHours"", ""ProjectId"") values (@description, @isLocked, @ordinal, @uniqueId) returning ""Id"", ""Title"", ""IsBlocked"", ""DurationInHours"", ""ProjectId""";
53+
var result = await connection.QueryAsync<WorkItem>(query, new { description = entity.Title, ordinal = entity.DurationInHours, uniqueId = entity.ProjectId, isLocked = entity.IsBlocked });
5354
return result;
5455
})).SingleOrDefault();
5556
}
5657

5758
public async Task DeleteAsync(int id)
5859
{
5960
await QueryAsync(async connection =>
60-
await connection.QueryAsync<TodoItem>(@"delete from ""TodoItems"" where ""Id""=@id", new { id }));
61+
await connection.QueryAsync<WorkItem>(@"delete from ""WorkItems"" where ""Id""=@id", new { id }));
6162
}
6263

63-
public Task<TodoItem> UpdateAsync(int id, TodoItem entity)
64+
public Task<WorkItem> UpdateAsync(int id, WorkItem entity)
6465
{
6566
throw new NotImplementedException();
6667
}

src/Examples/NoEntityFrameworkExample/Startup.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ public class Startup
1717

1818
public Startup(IConfiguration configuration)
1919
{
20-
_connectionString = configuration["Data:DefaultConnection"];
20+
string postgresPassword = Environment.GetEnvironmentVariable("PGPASSWORD") ?? "postgres";
21+
_connectionString = configuration["Data:DefaultConnection"].Replace("###", postgresPassword);
2122
}
2223

2324
// This method gets called by the runtime. Use this method to add services to the container.
24-
public virtual void ConfigureServices(IServiceCollection services)
25+
public void ConfigureServices(IServiceCollection services)
2526
{
2627
services.AddJsonApi(
2728
options => options.Namespace = "api/v1",
28-
resources: builder => builder.AddResource<TodoItem>("todoItems")
29+
resources: builder => builder.AddResource<WorkItem>("workItems")
2930
);
3031

31-
services.AddScoped<IResourceService<TodoItem>, TodoItemService>();
32+
services.AddScoped<IResourceService<WorkItem>, WorkItemService>();
3233

3334
services.AddDbContext<AppDbContext>(options =>
3435
{

src/Examples/NoEntityFrameworkExample/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Data": {
3-
"DefaultConnection": "Host=localhost;Port=5432;Database=NoEntityFrameworkExample;User ID=postgres;Password=postgres"
3+
"DefaultConnection": "Host=localhost;Port=5432;Database=NoEntityFrameworkExample;User ID=postgres;Password=###"
44
},
55
"Logging": {
66
"LogLevel": {

0 commit comments

Comments
 (0)