aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/AuthorizationUnitTest.cs
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-10-17 20:46:57 +0800
committer杨宇千 <crupest@outlook.com>2019-10-17 20:46:57 +0800
commitdef8e8dd78812c019a0d6e8e5a3e2de4e82ae3e4 (patch)
treedc7688d7d2dd5ab28a7e3c553154ee84676f75d2 /Timeline.Tests/AuthorizationUnitTest.cs
parent297d0c9029360f1d5334ed843b9b299356740ec1 (diff)
downloadtimeline-def8e8dd78812c019a0d6e8e5a3e2de4e82ae3e4.tar.gz
timeline-def8e8dd78812c019a0d6e8e5a3e2de4e82ae3e4.tar.bz2
timeline-def8e8dd78812c019a0d6e8e5a3e2de4e82ae3e4.zip
...
Diffstat (limited to 'Timeline.Tests/AuthorizationUnitTest.cs')
-rw-r--r--Timeline.Tests/AuthorizationUnitTest.cs76
1 files changed, 0 insertions, 76 deletions
diff --git a/Timeline.Tests/AuthorizationUnitTest.cs b/Timeline.Tests/AuthorizationUnitTest.cs
deleted file mode 100644
index 4751e95f..00000000
--- a/Timeline.Tests/AuthorizationUnitTest.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-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;
-using Xunit.Abstractions;
-
-namespace Timeline.Tests
-{
- public class AuthorizationUnitTest : IClassFixture<MyWebApplicationFactory<Startup>>, IDisposable
- {
- private const string AuthorizeUrl = "Test/User/Authorize";
- private const string UserUrl = "Test/User/User";
- private const string AdminUrl = "Test/User/Admin";
-
- private readonly WebApplicationFactory<Startup> _factory;
- private readonly Action _disposeAction;
-
- public AuthorizationUnitTest(MyWebApplicationFactory<Startup> factory, ITestOutputHelper outputHelper)
- {
- _factory = factory.WithTestConfig(outputHelper, out _disposeAction);
- }
-
- public void Dispose()
- {
- _disposeAction();
- }
-
- [Fact]
- public async Task UnauthenticationTest()
- {
- using (var client = _factory.CreateDefaultClient())
- {
- var response = await client.GetAsync(AuthorizeUrl);
- response.Should().HaveStatusCode(HttpStatusCode.Unauthorized);
- }
- }
-
- [Fact]
- public async Task AuthenticationTest()
- {
- using (var client = await _factory.CreateClientAsUser())
- {
- var response = await client.GetAsync(AuthorizeUrl);
- response.Should().HaveStatusCode(HttpStatusCode.OK);
- }
- }
-
- [Fact]
- public async Task UserAuthorizationTest()
- {
- using (var client = await _factory.CreateClientAsUser())
- {
- var response1 = await client.GetAsync(UserUrl);
- response1.Should().HaveStatusCode(HttpStatusCode.OK);
- var response2 = await client.GetAsync(AdminUrl);
- response2.Should().HaveStatusCode(HttpStatusCode.Forbidden);
- }
- }
-
- [Fact]
- public async Task AdminAuthorizationTest()
- {
- using (var client = await _factory.CreateClientAsAdmin())
- {
- var response1 = await client.GetAsync(UserUrl);
- response1.Should().HaveStatusCode(HttpStatusCode.OK);
- var response2 = await client.GetAsync(AdminUrl);
- response2.Should().HaveStatusCode(HttpStatusCode.OK);
- }
- }
- }
-}