aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/IntegratedTests
diff options
context:
space:
mode:
Diffstat (limited to 'Timeline.Tests/IntegratedTests')
-rw-r--r--Timeline.Tests/IntegratedTests/AuthorizationTest.cs6
-rw-r--r--Timeline.Tests/IntegratedTests/FrontEndTest.cs5
-rw-r--r--Timeline.Tests/IntegratedTests/IntegratedTestBase.cs18
-rw-r--r--Timeline.Tests/IntegratedTests/TimelineTest.cs6
-rw-r--r--Timeline.Tests/IntegratedTests/TokenTest.cs11
-rw-r--r--Timeline.Tests/IntegratedTests/UnknownEndpointTest.cs5
-rw-r--r--Timeline.Tests/IntegratedTests/UserAvatarTest.cs9
-rw-r--r--Timeline.Tests/IntegratedTests/UserTest.cs7
8 files changed, 13 insertions, 54 deletions
diff --git a/Timeline.Tests/IntegratedTests/AuthorizationTest.cs b/Timeline.Tests/IntegratedTests/AuthorizationTest.cs
index 4aa6b3ae..38071394 100644
--- a/Timeline.Tests/IntegratedTests/AuthorizationTest.cs
+++ b/Timeline.Tests/IntegratedTests/AuthorizationTest.cs
@@ -1,5 +1,4 @@
using FluentAssertions;
-using Microsoft.AspNetCore.Mvc.Testing;
using System.Net;
using System.Threading.Tasks;
using Timeline.Tests.Helpers;
@@ -9,11 +8,6 @@ namespace Timeline.Tests.IntegratedTests
{
public class AuthorizationTest : IntegratedTestBase
{
- public AuthorizationTest(WebApplicationFactory<Startup> factory)
- : base(factory)
- {
- }
-
private const string BaseUrl = "testing/auth/";
private const string AuthorizeUrl = BaseUrl + "Authorize";
private const string UserUrl = BaseUrl + "User";
diff --git a/Timeline.Tests/IntegratedTests/FrontEndTest.cs b/Timeline.Tests/IntegratedTests/FrontEndTest.cs
index a00d41b1..39a6e545 100644
--- a/Timeline.Tests/IntegratedTests/FrontEndTest.cs
+++ b/Timeline.Tests/IntegratedTests/FrontEndTest.cs
@@ -1,5 +1,4 @@
using FluentAssertions;
-using Microsoft.AspNetCore.Mvc.Testing;
using System.Net.Mime;
using System.Threading.Tasks;
using Timeline.Tests.Helpers;
@@ -9,10 +8,6 @@ namespace Timeline.Tests.IntegratedTests
{
public class FrontEndTest : IntegratedTestBase
{
- public FrontEndTest(WebApplicationFactory<Startup> factory) : base(factory)
- {
- }
-
[Fact]
public async Task Index()
{
diff --git a/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs b/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs
index 01544828..b5aec512 100644
--- a/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs
+++ b/Timeline.Tests/IntegratedTests/IntegratedTestBase.cs
@@ -1,4 +1,4 @@
-using Microsoft.AspNetCore.Mvc.Testing;
+using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
@@ -15,29 +15,27 @@ using Xunit;
namespace Timeline.Tests.IntegratedTests
{
- public abstract class IntegratedTestBase : IClassFixture<WebApplicationFactory<Startup>>, IAsyncLifetime
+ public abstract class IntegratedTestBase : IAsyncLifetime
{
protected TestApplication TestApp { get; }
- protected WebApplicationFactory<Startup> Factory => TestApp.Factory;
-
public IReadOnlyList<UserInfo> UserInfos { get; private set; }
private readonly int _userCount;
- public IntegratedTestBase(WebApplicationFactory<Startup> factory) : this(factory, 1)
+ public IntegratedTestBase() : this(1)
{
}
- public IntegratedTestBase(WebApplicationFactory<Startup> factory, int userCount)
+ public IntegratedTestBase(int userCount)
{
if (userCount < 0)
throw new ArgumentOutOfRangeException(nameof(userCount), userCount, "User count can't be negative.");
_userCount = userCount;
- TestApp = new TestApplication(factory);
+ TestApp = new TestApplication();
}
protected virtual Task OnInitializeAsync()
@@ -59,7 +57,7 @@ namespace Timeline.Tests.IntegratedTests
{
await TestApp.InitializeAsync();
- using (var scope = Factory.Services.CreateScope())
+ using (var scope = TestApp.Host.Services.CreateScope())
{
var users = new List<User>()
{
@@ -119,7 +117,7 @@ namespace Timeline.Tests.IntegratedTests
public Task<HttpClient> CreateDefaultClient(bool setApiBase = true)
{
- var client = Factory.CreateDefaultClient();
+ var client = TestApp.Host.GetTestServer().CreateClient();
if (setApiBase)
{
client.BaseAddress = new Uri(client.BaseAddress, "api/");
@@ -129,7 +127,7 @@ namespace Timeline.Tests.IntegratedTests
public async Task<HttpClient> CreateClientWithCredential(string username, string password, bool setApiBase = true)
{
- var client = Factory.CreateDefaultClient();
+ var client = TestApp.Host.GetTestServer().CreateClient();
if (setApiBase)
{
client.BaseAddress = new Uri(client.BaseAddress, "api/");
diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs
index d8017b8a..b6a56e94 100644
--- a/Timeline.Tests/IntegratedTests/TimelineTest.cs
+++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs
@@ -1,5 +1,4 @@
using FluentAssertions;
-using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using SixLabors.ImageSharp;
@@ -45,8 +44,7 @@ namespace Timeline.Tests.IntegratedTests
public class TimelineTest : IntegratedTestBase
{
- public TimelineTest(WebApplicationFactory<Startup> factory)
- : base(factory, 3)
+ public TimelineTest() : base(3)
{
}
@@ -1112,7 +1110,7 @@ namespace Timeline.Tests.IntegratedTests
}
{
- using var scope = TestApp.Factory.Services.CreateScope();
+ using var scope = TestApp.Host.Services.CreateScope();
var database = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
var count = await database.Data.CountAsync();
count.Should().Be(0);
diff --git a/Timeline.Tests/IntegratedTests/TokenTest.cs b/Timeline.Tests/IntegratedTests/TokenTest.cs
index 7b28746f..d1c31606 100644
--- a/Timeline.Tests/IntegratedTests/TokenTest.cs
+++ b/Timeline.Tests/IntegratedTests/TokenTest.cs
@@ -1,5 +1,4 @@
using FluentAssertions;
-using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using System.Net.Http;
@@ -17,12 +16,6 @@ namespace Timeline.Tests.IntegratedTests
private const string CreateTokenUrl = "token/create";
private const string VerifyTokenUrl = "token/verify";
- public TokenTest(WebApplicationFactory<Startup> factory)
- : base(factory)
- {
-
- }
-
private static async Task<CreateTokenResponse> CreateUserTokenAsync(HttpClient client, string username, string password, int? expireOffset = null)
{
var response = await client.PostAsJsonAsync(CreateTokenUrl, new CreateTokenRequest { Username = username, Password = password, Expire = expireOffset });
@@ -106,7 +99,7 @@ namespace Timeline.Tests.IntegratedTests
using var client = await CreateDefaultClient();
var token = (await CreateUserTokenAsync(client, "user1", "user1pw")).Token;
- using (var scope = Factory.Services.CreateScope()) // UserService is scoped.
+ using (var scope = TestApp.Host.Services.CreateScope()) // UserService is scoped.
{
// create a user for test
var userService = scope.ServiceProvider.GetRequiredService<IUserService>();
@@ -126,7 +119,7 @@ namespace Timeline.Tests.IntegratedTests
using var client = await CreateDefaultClient();
var token = (await CreateUserTokenAsync(client, "user1", "user1pw")).Token;
- using (var scope = Factory.Server.Host.Services.CreateScope()) // UserService is scoped.
+ using (var scope = TestApp.Host.Services.CreateScope()) // UserService is scoped.
{
var userService = scope.ServiceProvider.GetRequiredService<IUserService>();
await userService.DeleteUser("user1");
diff --git a/Timeline.Tests/IntegratedTests/UnknownEndpointTest.cs b/Timeline.Tests/IntegratedTests/UnknownEndpointTest.cs
index 40f818a7..732232e2 100644
--- a/Timeline.Tests/IntegratedTests/UnknownEndpointTest.cs
+++ b/Timeline.Tests/IntegratedTests/UnknownEndpointTest.cs
@@ -1,5 +1,4 @@
using FluentAssertions;
-using Microsoft.AspNetCore.Mvc.Testing;
using System.Threading.Tasks;
using Timeline.Models.Http;
using Timeline.Tests.Helpers;
@@ -9,10 +8,6 @@ namespace Timeline.Tests.IntegratedTests
{
public class UnknownEndpointTest : IntegratedTestBase
{
- public UnknownEndpointTest(WebApplicationFactory<Startup> factory) : base(factory)
- {
- }
-
[Fact]
public async Task UnknownEndpoint()
{
diff --git a/Timeline.Tests/IntegratedTests/UserAvatarTest.cs b/Timeline.Tests/IntegratedTests/UserAvatarTest.cs
index fbf34490..91986cda 100644
--- a/Timeline.Tests/IntegratedTests/UserAvatarTest.cs
+++ b/Timeline.Tests/IntegratedTests/UserAvatarTest.cs
@@ -1,6 +1,5 @@
using FluentAssertions;
using Microsoft.AspNetCore.Hosting;
-using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Gif;
@@ -21,12 +20,6 @@ namespace Timeline.Tests.IntegratedTests
{
public class UserAvatarTest : IntegratedTestBase
{
- public UserAvatarTest(WebApplicationFactory<Startup> factory)
- : base(factory)
- {
-
- }
-
[Fact]
public async Task Test()
{
@@ -45,7 +38,7 @@ namespace Timeline.Tests.IntegratedTests
.Which.Code.Should().Be(ErrorCodes.UserCommon.NotExist);
}
- var env = Factory.Server.Host.Services.GetRequiredService<IWebHostEnvironment>();
+ var env = TestApp.Host.Services.GetRequiredService<IWebHostEnvironment>();
var defaultAvatarData = await File.ReadAllBytesAsync(Path.Combine(env.ContentRootPath, "default-avatar.png"));
async Task GetReturnDefault(string username = "user1")
diff --git a/Timeline.Tests/IntegratedTests/UserTest.cs b/Timeline.Tests/IntegratedTests/UserTest.cs
index e226d084..7fd78d0e 100644
--- a/Timeline.Tests/IntegratedTests/UserTest.cs
+++ b/Timeline.Tests/IntegratedTests/UserTest.cs
@@ -1,5 +1,4 @@
using FluentAssertions;
-using Microsoft.AspNetCore.Mvc.Testing;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
@@ -12,12 +11,6 @@ namespace Timeline.Tests.IntegratedTests
{
public class UserTest : IntegratedTestBase
{
- public UserTest(WebApplicationFactory<Startup> factory)
- : base(factory)
- {
-
- }
-
[Fact]
public async Task GetList_NoAuth()
{