aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/IntegratedTests/UserDetailTest.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-11-20 00:28:53 +0800
committercrupest <crupest@outlook.com>2019-11-20 00:28:53 +0800
commita72960e54a89bd31dcb8be8f52e097007dfd23e5 (patch)
tree55eaf43bda897148b0fa8a65406e7289aed3832e /Timeline.Tests/IntegratedTests/UserDetailTest.cs
parentf3c7912caec2e9eee8a685d8751894f357528a71 (diff)
downloadtimeline-a72960e54a89bd31dcb8be8f52e097007dfd23e5.tar.gz
timeline-a72960e54a89bd31dcb8be8f52e097007dfd23e5.tar.bz2
timeline-a72960e54a89bd31dcb8be8f52e097007dfd23e5.zip
Clean and refactor tests.
Diffstat (limited to 'Timeline.Tests/IntegratedTests/UserDetailTest.cs')
-rw-r--r--Timeline.Tests/IntegratedTests/UserDetailTest.cs25
1 files changed, 7 insertions, 18 deletions
diff --git a/Timeline.Tests/IntegratedTests/UserDetailTest.cs b/Timeline.Tests/IntegratedTests/UserDetailTest.cs
index 8f2b6925..932c287e 100644
--- a/Timeline.Tests/IntegratedTests/UserDetailTest.cs
+++ b/Timeline.Tests/IntegratedTests/UserDetailTest.cs
@@ -1,38 +1,27 @@
using FluentAssertions;
using Microsoft.AspNetCore.Mvc.Testing;
-using System;
using System.Net;
using System.Net.Http.Headers;
using System.Net.Mime;
using System.Threading.Tasks;
using Timeline.Tests.Helpers;
-using Timeline.Tests.Helpers.Authentication;
-using Timeline.Tests.Mock.Data;
using Xunit;
namespace Timeline.Tests.IntegratedTests
{
- public class UserDetailTest : IClassFixture<WebApplicationFactory<Startup>>, IDisposable
+ public class UserDetailTest : IntegratedTestBase
{
- private readonly TestApplication _testApp;
- private readonly WebApplicationFactory<Startup> _factory;
-
public UserDetailTest(WebApplicationFactory<Startup> factory)
+ : base(factory)
{
- _testApp = new TestApplication(factory);
- _factory = _testApp.Factory;
- }
- public void Dispose()
- {
- _testApp.Dispose();
}
[Fact]
public async Task PermissionTest()
{
{ // unauthorize
- using var client = _factory.CreateDefaultClient();
+ using var client = await CreateClientWithNoAuth();
{ // GET
var res = await client.GetAsync($"users/{MockUser.User.Username}/nickname");
res.Should().HaveStatusCode(HttpStatusCode.OK);
@@ -47,7 +36,7 @@ namespace Timeline.Tests.IntegratedTests
}
}
{ // user
- using var client = await _factory.CreateClientAsUser();
+ using var client = await CreateClientAsUser();
{ // GET
var res = await client.GetAsync($"users/{MockUser.User.Username}/nickname");
res.Should().HaveStatusCode(HttpStatusCode.OK);
@@ -70,7 +59,7 @@ namespace Timeline.Tests.IntegratedTests
}
}
{ // user
- using var client = await _factory.CreateClientAsAdmin();
+ using var client = await CreateClientAsAdmin();
{ // PUT other
var res = await client.PutStringAsync($"users/{MockUser.User.Username}/nickname", "aaa");
res.Should().HaveStatusCode(HttpStatusCode.OK);
@@ -88,7 +77,7 @@ namespace Timeline.Tests.IntegratedTests
var url = $"users/{MockUser.User.Username}/nickname";
var userNotExistUrl = "users/usernotexist/nickname";
{
- using var client = await _factory.CreateClientAsUser();
+ using var client = await CreateClientAsUser();
{
var res = await client.GetAsync(userNotExistUrl);
res.Should().HaveStatusCode(HttpStatusCode.NotFound)
@@ -134,7 +123,7 @@ namespace Timeline.Tests.IntegratedTests
}
}
{
- using var client = await _factory.CreateClientAsAdmin();
+ using var client = await CreateClientAsAdmin();
{
var res = await client.PutStringAsync(userNotExistUrl, "aaa");
res.Should().HaveStatusCode(HttpStatusCode.BadRequest)