diff options
author | 杨宇千 <crupest@outlook.com> | 2019-05-06 14:22:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-06 14:22:10 +0800 |
commit | ea84a067eee6dcd10dd0bc89967ef608677ef37e (patch) | |
tree | 37c2b6f9dcb3d6f57867ebc7538523d1a338183d /Timeline.Tests/Helpers/Authentication | |
parent | ae848e311b46a25ec1ed571432d55e800ac7595b (diff) | |
parent | 070a4a8399201150a633c80608a13cc44781a3c4 (diff) | |
download | timeline-ea84a067eee6dcd10dd0bc89967ef608677ef37e.tar.gz timeline-ea84a067eee6dcd10dd0bc89967ef608677ef37e.tar.bz2 timeline-ea84a067eee6dcd10dd0bc89967ef608677ef37e.zip |
Merge pull request #22 from crupest/user-admin
Develop user management feature.
Diffstat (limited to 'Timeline.Tests/Helpers/Authentication')
-rw-r--r-- | Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs (renamed from Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs) | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs b/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs index c0051c53..cda9fe99 100644 --- a/Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs +++ b/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs @@ -1,16 +1,17 @@ -using Newtonsoft.Json; +using Microsoft.AspNetCore.Mvc.Testing; +using Newtonsoft.Json; using System; using System.Net; using System.Net.Http; using System.Threading.Tasks; -using Timeline.Entities; +using Timeline.Entities.Http; using Xunit; namespace Timeline.Tests.Helpers.Authentication { - public static class AuthenticationHttpClientExtensions + public static class AuthenticationExtensions { - private const string CreateTokenUrl = "/User/CreateToken"; + private const string CreateTokenUrl = "/token/create"; public static async Task<CreateTokenResponse> CreateUserTokenAsync(this HttpClient client, string username, string password, bool assertSuccess = true) { @@ -24,6 +25,14 @@ namespace Timeline.Tests.Helpers.Authentication return result; } + public static async Task<HttpClient> CreateClientWithUser<T>(this WebApplicationFactory<T> factory, string username, string password) where T : class + { + var client = factory.CreateDefaultClient(); + var token = (await client.CreateUserTokenAsync(username, password)).Token; + client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); + return client; + } + public static async Task<HttpResponseMessage> SendWithAuthenticationAsync(this HttpClient client, string token, string path, Action<HttpRequestMessage> requestBuilder = null) { var request = new HttpRequestMessage |