Skip to content

Commit 973ee9f

Browse files
committed
Phase 3
1 parent 3a313f8 commit 973ee9f

22 files changed

+749
-777
lines changed

.github/workflows/build-and-dockerize.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
# Label used to access the service container
1414
postgres:
1515
# Docker Hub image
16-
image: postgres:17-alpine
16+
image: postgres:18-alpine
1717
ports:
1818
- 5432:5432
1919
# Provide the password for postgres
Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1+
namespace BervProject.WebApi.Integration.Test;
2+
13
using System.Net.Http.Json;
2-
using BervProject.WebApi.Integration.Test.Fixtures;
4+
using Fixtures;
35
using Microsoft.AspNetCore.Mvc.Testing;
4-
using Newtonsoft.Json.Linq;
56

6-
namespace BervProject.WebApi.Integration.Test
7+
[Collection("Webapp")]
8+
public class BlobControllerTest
79
{
8-
[Collection("Webapp")]
9-
public class BlobControllerTest
10+
private readonly WebApplicationFactory<Program> _applicationFactory;
11+
public BlobControllerTest(WebAppFixture webAppFixtures)
12+
{
13+
_applicationFactory = webAppFixtures.WebApp;
14+
}
15+
[Fact]
16+
public async Task UploadBlobTest()
1017
{
11-
private readonly WebApplicationFactory<Program> _applicationFactory;
12-
public BlobControllerTest(WebAppFixture webAppFixtures)
13-
{
14-
this._applicationFactory = webAppFixtures.WebApp;
15-
}
16-
[Fact]
17-
public async Task UploadBlobTest()
18-
{
19-
var client = _applicationFactory.CreateClient();
20-
var response = await client.PostAsync("/api/v1.0/blob/create", null);
21-
Assert.True(response.IsSuccessStatusCode);
22-
using var file1 = File.OpenRead(@"Docs/test.txt");
23-
using var content1 = new StreamContent(file1);
24-
using var formData = new MultipartFormDataContent();
25-
formData.Add(content1, "file", "test.txt");
26-
response = await client.PostAsync("/api/v1.0/blob/upload", formData);
27-
Assert.True(response.IsSuccessStatusCode);
28-
response = await client.GetAsync("/api/v1.0/blob/list");
29-
Assert.True(response.IsSuccessStatusCode);
30-
var data = await response.Content.ReadFromJsonAsync<List<Dictionary<string, string>>>();
31-
Assert.NotNull(data);
32-
Assert.Single(data);
33-
}
18+
var client = _applicationFactory.CreateClient();
19+
var response = await client.PostAsync("/api/v1.0/blob/create", null);
20+
Assert.True(response.IsSuccessStatusCode);
21+
using var file1 = File.OpenRead(@"Docs/test.txt");
22+
using var content1 = new StreamContent(file1);
23+
using var formData = new MultipartFormDataContent();
24+
formData.Add(content1, "file", "test.txt");
25+
response = await client.PostAsync("/api/v1.0/blob/upload", formData);
26+
Assert.True(response.IsSuccessStatusCode);
27+
response = await client.GetAsync("/api/v1.0/blob/list");
28+
Assert.True(response.IsSuccessStatusCode);
29+
var data = await response.Content.ReadFromJsonAsync<List<Dictionary<string, string>>>();
30+
Assert.NotNull(data);
31+
Assert.Single(data);
3432
}
35-
}
33+
}
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
using BervProject.WebApi.Integration.Test.Fixtures;
1+
namespace BervProject.WebApi.Integration.Test.Collections;
22

3-
namespace BervProject.WebApi.Integration.Test.Collections
3+
using Fixtures;
4+
5+
[CollectionDefinition("Webapp")]
6+
public class WebAppCollection : ICollectionFixture<WebAppFixture>
47
{
5-
[CollectionDefinition("Webapp")]
6-
public class WebAppCollection : ICollectionFixture<WebAppFixture>
7-
{
8-
// This class has no code, and is never created. Its purpose is simply
9-
// to be the place to apply [CollectionDefinition] and all the
10-
// ICollectionFixture<> interfaces.
11-
}
12-
}
8+
// This class has no code, and is never created. Its purpose is simply
9+
// to be the place to apply [CollectionDefinition] and all the
10+
// ICollectionFixture<> interfaces.
11+
}
Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
1-
using BervProject.WebApi.Integration.Test.Fixtures;
1+
namespace BervProject.WebApi.Integration.Test;
2+
3+
using Fixtures;
24
using Hangfire;
35
using Microsoft.AspNetCore.Mvc.Testing;
46

5-
namespace BervProject.WebApi.Integration.Test
7+
8+
[Collection("Webapp")]
9+
public class CronControllerTest : IDisposable
610
{
7-
[Collection("Webapp")]
8-
public class CronControllerTest : IDisposable
11+
private readonly WebApplicationFactory<Program> _applicationFactory;
12+
private readonly List<string> _registeredRecurring = new();
13+
public CronControllerTest(WebAppFixture webAppFixtures)
914
{
10-
private readonly WebApplicationFactory<Program> _applicationFactory;
11-
private readonly List<string> _registeredRecurring = new List<string>();
12-
public CronControllerTest(WebAppFixture webAppFixtures)
13-
{
14-
this._applicationFactory = webAppFixtures.WebApp;
15-
}
15+
_applicationFactory = webAppFixtures.WebApp;
16+
}
1617

17-
public void Dispose()
18-
{
19-
RemoveRecurringJob();
20-
}
18+
public void Dispose()
19+
{
20+
RemoveRecurringJob();
21+
}
2122

22-
private void RemoveRecurringJob()
23+
private void RemoveRecurringJob()
24+
{
25+
var cronClient = (IRecurringJobManager?)this._applicationFactory.Services.GetService(typeof(IRecurringJobManager));
26+
if (cronClient != null)
2327
{
24-
var cronClient = (IRecurringJobManager?)this._applicationFactory.Services.GetService(typeof(IRecurringJobManager));
25-
if (cronClient != null)
28+
foreach (var cronId in _registeredRecurring)
2629
{
27-
foreach (var cronId in _registeredRecurring)
28-
{
29-
cronClient.RemoveIfExists(cronId);
30-
}
30+
cronClient.RemoveIfExists(cronId);
3131
}
3232
}
33+
}
3334

34-
[Fact]
35-
public async Task SuccessCreateCronOnceTest()
35+
[Fact]
36+
public async Task SuccessCreateCronOnceTest()
37+
{
38+
var client = _applicationFactory.CreateClient();
39+
var response = await client.PostAsync("/api/v1.0/cron/CreateCronOnce", null);
40+
Assert.True(response.IsSuccessStatusCode);
41+
var stringResponse = await response.Content.ReadAsStringAsync();
42+
Assert.NotEmpty(stringResponse);
43+
var cronClient = (IBackgroundJobClient?)this._applicationFactory.Services.GetService(typeof(IBackgroundJobClient));
44+
if (cronClient != null)
3645
{
37-
var client = _applicationFactory.CreateClient();
38-
var response = await client.PostAsync("/api/v1.0/cron/CreateCronOnce", null);
39-
Assert.True(response.IsSuccessStatusCode);
40-
var stringResponse = await response.Content.ReadAsStringAsync();
41-
Assert.NotEmpty(stringResponse);
42-
var cronClient = (IBackgroundJobClient?)this._applicationFactory.Services.GetService(typeof(IBackgroundJobClient));
43-
if (cronClient != null)
44-
{
45-
var deleted = cronClient.Delete(stringResponse);
46-
Assert.True(deleted);
47-
}
46+
var deleted = cronClient.Delete(stringResponse);
47+
Assert.True(deleted);
4848
}
49+
}
4950

50-
[Fact]
51-
public async Task SuccessCreateRecuranceTest()
52-
{
53-
var client = _applicationFactory.CreateClient();
54-
var response = await client.PostAsync("/api/v1.0/cron/CreateRecurance", null);
55-
Assert.True(response.IsSuccessStatusCode);
56-
var stringResponse = await response.Content.ReadAsStringAsync();
57-
Assert.NotEmpty(stringResponse);
58-
_registeredRecurring.Add(stringResponse);
59-
}
51+
[Fact]
52+
public async Task SuccessCreateRecuranceTest()
53+
{
54+
var client = _applicationFactory.CreateClient();
55+
var response = await client.PostAsync("/api/v1.0/cron/CreateRecurance", null);
56+
Assert.True(response.IsSuccessStatusCode);
57+
var stringResponse = await response.Content.ReadAsStringAsync();
58+
Assert.NotEmpty(stringResponse);
59+
_registeredRecurring.Add(stringResponse);
6060
}
6161
}
Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
using BervProject.WebApi.Integration.Test.Fixtures;
1+
namespace BervProject.WebApi.Integration.Test;
2+
3+
using Fixtures;
24
using Microsoft.AspNetCore.Mvc.Testing;
35
using Newtonsoft.Json.Linq;
46

5-
namespace BervProject.WebApi.Integration.Test
7+
[Collection("Webapp")]
8+
public class ErrorControllerTest
69
{
7-
[Collection("Webapp")]
8-
public class ErrorControllerTest
10+
private readonly WebApplicationFactory<Program> _applicationFactory;
11+
public ErrorControllerTest(WebAppFixture webAppFixtures)
12+
{
13+
_applicationFactory = webAppFixtures.WebApp;
14+
}
15+
[Fact]
16+
public async Task SuccessCheck()
917
{
10-
private readonly WebApplicationFactory<Program> _applicationFactory;
11-
public ErrorControllerTest(WebAppFixture webAppFixtures)
12-
{
13-
this._applicationFactory = webAppFixtures.WebApp;
14-
}
15-
[Fact]
16-
public async Task SuccessCheck()
17-
{
18-
var client = _applicationFactory.CreateClient();
19-
var response = await client.GetAsync("/api/v1.0/error/error");
20-
Assert.False(response.IsSuccessStatusCode);
21-
Assert.Equal(System.Net.HttpStatusCode.InternalServerError, response.StatusCode);
22-
var responseString = await response.Content.ReadAsStringAsync();
23-
var jObject = JObject.Parse(responseString);
24-
var status = jObject.Value<int>("status");
25-
var title = jObject.Value<string>("title");
26-
Assert.Equal("An error occurred while processing your request.", title);
27-
Assert.Equal(500, status);
28-
}
18+
var client = _applicationFactory.CreateClient();
19+
var response = await client.GetAsync("/api/v1.0/error/error");
20+
Assert.False(response.IsSuccessStatusCode);
21+
Assert.Equal(System.Net.HttpStatusCode.InternalServerError, response.StatusCode);
22+
var responseString = await response.Content.ReadAsStringAsync();
23+
var jObject = JObject.Parse(responseString);
24+
var status = jObject.Value<int>("status");
25+
var title = jObject.Value<string>("title");
26+
Assert.Equal("An error occurred while processing your request.", title);
27+
Assert.Equal(500, status);
2928
}
30-
}
29+
}
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
using Microsoft.AspNetCore.Mvc.Testing;
1+
namespace BervProject.WebApi.Integration.Test.Fixtures;
22

3-
namespace BervProject.WebApi.Integration.Test.Fixtures
3+
using Microsoft.AspNetCore.Mvc.Testing;
4+
5+
public class WebAppFixture : IDisposable
46
{
5-
public class WebAppFixture : IDisposable
7+
public WebAppFixture()
68
{
7-
public WebAppFixture()
8-
{
9-
WebApp = new WebApplicationFactory<Program>()
10-
.WithWebHostBuilder(builder =>
11-
{
12-
// ... Configure test services
13-
});
9+
WebApp = new WebApplicationFactory<Program>()
10+
.WithWebHostBuilder(_ =>
11+
{
12+
// ... Configure test services
13+
});
1414

15-
}
15+
}
1616

17-
public void Dispose() => WebApp.Dispose();
17+
public void Dispose() => WebApp.Dispose();
1818

19-
public WebApplicationFactory<Program> WebApp { get; private set; }
20-
}
21-
}
19+
public WebApplicationFactory<Program> WebApp { get; }
20+
}
Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
using BervProject.WebApi.Integration.Test.Fixtures;
1+
namespace BervProject.WebApi.Integration.Test;
2+
3+
using Fixtures;
24
using Microsoft.AspNetCore.Mvc.Testing;
35

4-
namespace BervProject.WebApi.Integration.Test
6+
[Collection("Webapp")]
7+
public class HealthCheckTest
58
{
6-
[Collection("Webapp")]
7-
public class HealthCheckTest
9+
private readonly WebApplicationFactory<Program> _applicationFactory;
10+
public HealthCheckTest(WebAppFixture webAppFixtures)
11+
{
12+
_applicationFactory = webAppFixtures.WebApp;
13+
}
14+
[Fact]
15+
public async Task SuccessCheck()
816
{
9-
private readonly WebApplicationFactory<Program> _applicationFactory;
10-
public HealthCheckTest(WebAppFixture webAppFixtures)
11-
{
12-
this._applicationFactory = webAppFixtures.WebApp;
13-
}
14-
[Fact]
15-
public async Task SuccessCheck()
16-
{
17-
var client = _applicationFactory.CreateClient();
18-
var response = await client.GetAsync("/health");
19-
Assert.True(response.IsSuccessStatusCode);
20-
var stringResponse = await response.Content.ReadAsStringAsync();
21-
Assert.Equal("Healthy", stringResponse);
22-
}
17+
var client = _applicationFactory.CreateClient();
18+
var response = await client.GetAsync("/health");
19+
Assert.True(response.IsSuccessStatusCode);
20+
var stringResponse = await response.Content.ReadAsStringAsync();
21+
Assert.Equal("Healthy", stringResponse);
2322
}
2423
}

0 commit comments

Comments
 (0)