diff options
author | crupest <crupest@outlook.com> | 2020-06-15 00:11:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-15 00:11:07 +0800 |
commit | 8ec86937ce4f8073a1cf49652533a1b65bf630af (patch) | |
tree | fc07d6d2622140f82a2c7e3c50aecf759c144043 /Timeline.Tests/IntegratedTests/IntegratedTestBase.cs | |
parent | cf2cfa4853944ce0af6b6c22a089b937dd59ccaf (diff) | |
parent | e0b4c538228864c314900affae08df72edc9cd60 (diff) | |
download | timeline-8ec86937ce4f8073a1cf49652533a1b65bf630af.tar.gz timeline-8ec86937ce4f8073a1cf49652533a1b65bf630af.tar.bz2 timeline-8ec86937ce4f8073a1cf49652533a1b65bf630af.zip |
Merge pull request #107 from crupest/generic-host
refactor(back): Use generic host.
Diffstat (limited to 'Timeline.Tests/IntegratedTests/IntegratedTestBase.cs')
-rw-r--r-- | Timeline.Tests/IntegratedTests/IntegratedTestBase.cs | 18 |
1 files changed, 8 insertions, 10 deletions
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/");
|