From a72960e54a89bd31dcb8be8f52e097007dfd23e5 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 20 Nov 2019 00:28:53 +0800 Subject: Clean and refactor tests. --- .../IntegratedTests/AuthorizationTest.cs | 23 ++++++---------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'Timeline.Tests/IntegratedTests/AuthorizationTest.cs') diff --git a/Timeline.Tests/IntegratedTests/AuthorizationTest.cs b/Timeline.Tests/IntegratedTests/AuthorizationTest.cs index a31d98f5..0bc094af 100644 --- a/Timeline.Tests/IntegratedTests/AuthorizationTest.cs +++ b/Timeline.Tests/IntegratedTests/AuthorizationTest.cs @@ -1,28 +1,17 @@ using FluentAssertions; using Microsoft.AspNetCore.Mvc.Testing; -using System; using System.Net; using System.Threading.Tasks; using Timeline.Tests.Helpers; -using Timeline.Tests.Helpers.Authentication; using Xunit; namespace Timeline.Tests.IntegratedTests { - public class AuthorizationTest : IClassFixture>, IDisposable + public class AuthorizationTest : IntegratedTestBase { - private readonly TestApplication _testApp; - private readonly WebApplicationFactory _factory; - public AuthorizationTest(WebApplicationFactory factory) + : base(factory) { - _testApp = new TestApplication(factory); - _factory = _testApp.Factory; - } - - public void Dispose() - { - _testApp.Dispose(); } private const string BaseUrl = "testing/auth/"; @@ -33,7 +22,7 @@ namespace Timeline.Tests.IntegratedTests [Fact] public async Task UnauthenticationTest() { - using var client = _factory.CreateDefaultClient(); + using var client = await CreateClientWithNoAuth(); var response = await client.GetAsync(AuthorizeUrl); response.Should().HaveStatusCode(HttpStatusCode.Unauthorized); } @@ -41,7 +30,7 @@ namespace Timeline.Tests.IntegratedTests [Fact] public async Task AuthenticationTest() { - using var client = await _factory.CreateClientAsUser(); + using var client = await CreateClientAsUser(); var response = await client.GetAsync(AuthorizeUrl); response.Should().HaveStatusCode(HttpStatusCode.OK); } @@ -49,7 +38,7 @@ namespace Timeline.Tests.IntegratedTests [Fact] public async Task UserAuthorizationTest() { - using var client = await _factory.CreateClientAsUser(); + using var client = await CreateClientAsUser(); var response1 = await client.GetAsync(UserUrl); response1.Should().HaveStatusCode(HttpStatusCode.OK); var response2 = await client.GetAsync(AdminUrl); @@ -59,7 +48,7 @@ namespace Timeline.Tests.IntegratedTests [Fact] public async Task AdminAuthorizationTest() { - using var client = await _factory.CreateClientAsAdmin(); + using var client = await CreateClientAsAdmin(); var response1 = await client.GetAsync(UserUrl); response1.Should().HaveStatusCode(HttpStatusCode.OK); var response2 = await client.GetAsync(AdminUrl); -- cgit v1.2.3