diff options
author | crupest <crupest@outlook.com> | 2019-04-21 00:08:59 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-04-21 00:08:59 +0800 |
commit | 076e0131dff71a9f76fff13c92fffa0ef408935f (patch) | |
tree | 9fa853690866f452a571b45fb062ac692d298a2e /Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs | |
parent | 325d4c7dbfba45e9c5a7518279831f54c4690d20 (diff) | |
download | timeline-076e0131dff71a9f76fff13c92fffa0ef408935f.tar.gz timeline-076e0131dff71a9f76fff13c92fffa0ef408935f.tar.bz2 timeline-076e0131dff71a9f76fff13c92fffa0ef408935f.zip |
Reorgnize api. Add basic unit test.
Diffstat (limited to 'Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs')
-rw-r--r-- | Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs b/Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs deleted file mode 100644 index c0051c53..00000000 --- a/Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; -using Timeline.Entities; -using Xunit; - -namespace Timeline.Tests.Helpers.Authentication -{ - public static class AuthenticationHttpClientExtensions - { - private const string CreateTokenUrl = "/User/CreateToken"; - - public static async Task<CreateTokenResponse> CreateUserTokenAsync(this HttpClient client, string username, string password, bool assertSuccess = true) - { - var response = await client.PostAsJsonAsync(CreateTokenUrl, new CreateTokenRequest { Username = username, Password = password }); - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - - var result = JsonConvert.DeserializeObject<CreateTokenResponse>(await response.Content.ReadAsStringAsync()); - if (assertSuccess) - Assert.True(result.Success); - - return result; - } - - public static async Task<HttpResponseMessage> SendWithAuthenticationAsync(this HttpClient client, string token, string path, Action<HttpRequestMessage> requestBuilder = null) - { - var request = new HttpRequestMessage - { - RequestUri = new Uri(client.BaseAddress, path), - }; - request.Headers.Add("Authorization", "Bearer " + token); - requestBuilder?.Invoke(request); - return await client.SendAsync(request); - } - } -} |