aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-04-21 00:08:59 +0800
committercrupest <crupest@outlook.com>2019-04-21 00:08:59 +0800
commita9f248ad817683e911348cd168c570db3d07757f (patch)
tree9fa853690866f452a571b45fb062ac692d298a2e /Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs
parentb86c8cf5130d21ac56e733640cecd08945d30e6d (diff)
downloadtimeline-a9f248ad817683e911348cd168c570db3d07757f.tar.gz
timeline-a9f248ad817683e911348cd168c570db3d07757f.tar.bz2
timeline-a9f248ad817683e911348cd168c570db3d07757f.zip
Reorgnize api. Add basic unit test.
Diffstat (limited to 'Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs')
-rw-r--r--Timeline.Tests/Helpers/Authentication/AuthenticationHttpClientExtensions.cs38
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);
- }
- }
-}