aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs
diff options
context:
space:
mode:
authorunknown <crupest@outlook.com>2019-08-07 17:38:56 +0800
committerunknown <crupest@outlook.com>2019-08-07 17:38:56 +0800
commit29bd71cd93b03248254f341aff9252374abc74ec (patch)
treedf5d1325c3b73b17f4f86b71097775e9ce3fa122 /Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs
parent0c0e0c963458aae3ba9589622fc688388833fa9c (diff)
downloadtimeline-29bd71cd93b03248254f341aff9252374abc74ec.tar.gz
timeline-29bd71cd93b03248254f341aff9252374abc74ec.tar.bz2
timeline-29bd71cd93b03248254f341aff9252374abc74ec.zip
Add script to convert encoding and eof. And of course run it.
Diffstat (limited to 'Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs')
-rw-r--r--Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs56
1 files changed, 28 insertions, 28 deletions
diff --git a/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs b/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs
index 27362ac3..c8bec266 100644
--- a/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs
+++ b/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs
@@ -1,28 +1,28 @@
-using Microsoft.AspNetCore.Mvc.Testing;
-using Newtonsoft.Json;
-using System.Net.Http;
-using System.Threading.Tasks;
-using Timeline.Entities.Http;
-
-namespace Timeline.Tests.Helpers.Authentication
-{
- public static class AuthenticationExtensions
- {
- private const string CreateTokenUrl = "/token/create";
-
- public static async Task<CreateTokenResponse> CreateUserTokenAsync(this HttpClient client, string username, string password, double? expireOffset = null)
- {
- var response = await client.PostAsJsonAsync(CreateTokenUrl, new CreateTokenRequest { Username = username, Password = password, ExpireOffset = expireOffset });
- var result = JsonConvert.DeserializeObject<CreateTokenResponse>(await response.Content.ReadAsStringAsync());
- 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;
- }
- }
-}
+using Microsoft.AspNetCore.Mvc.Testing;
+using Newtonsoft.Json;
+using System.Net.Http;
+using System.Threading.Tasks;
+using Timeline.Entities.Http;
+
+namespace Timeline.Tests.Helpers.Authentication
+{
+ public static class AuthenticationExtensions
+ {
+ private const string CreateTokenUrl = "/token/create";
+
+ public static async Task<CreateTokenResponse> CreateUserTokenAsync(this HttpClient client, string username, string password, double? expireOffset = null)
+ {
+ var response = await client.PostAsJsonAsync(CreateTokenUrl, new CreateTokenRequest { Username = username, Password = password, ExpireOffset = expireOffset });
+ var result = JsonConvert.DeserializeObject<CreateTokenResponse>(await response.Content.ReadAsStringAsync());
+ 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;
+ }
+ }
+}