diff options
author | 杨宇千 <crupest@outlook.com> | 2019-08-08 17:41:59 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-08-08 17:41:59 +0800 |
commit | 6c50630c4d6576446fc2338714feaefbf28c4ed1 (patch) | |
tree | 99f13fac6846a3eb299bbdfa4ff6b193e4873019 /Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs | |
parent | aa7d7d8ce33646dc63afb0c084e7daa14916646a (diff) | |
download | timeline-6c50630c4d6576446fc2338714feaefbf28c4ed1.tar.gz timeline-6c50630c4d6576446fc2338714feaefbf28c4ed1.tar.bz2 timeline-6c50630c4d6576446fc2338714feaefbf28c4ed1.zip |
Reorganize unit tests.
Diffstat (limited to 'Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs')
-rw-r--r-- | Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs b/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs index de88fd35..e31bd51c 100644 --- a/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs +++ b/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using System.Net.Http;
using System.Threading.Tasks;
using Timeline.Models.Http;
+using Timeline.Tests.Mock.Data;
namespace Timeline.Tests.Helpers.Authentication
{
@@ -17,12 +18,22 @@ 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
+ public static async Task<HttpClient> CreateClientWithCredential<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 Task<HttpClient> CreateClientAsUser<T>(this WebApplicationFactory<T> factory) where T : class
+ {
+ return factory.CreateClientWithCredential(MockUsers.UserUsername, MockUsers.UserPassword);
+ }
+
+ public static Task<HttpClient> CreateClientAsAdmin<T>(this WebApplicationFactory<T> factory) where T : class
+ {
+ return factory.CreateClientWithCredential(MockUsers.AdminUsername, MockUsers.AdminPassword);
+ }
}
}
|