aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/Helpers/Authentication
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-11-07 22:57:04 +0800
committer杨宇千 <crupest@outlook.com>2019-11-07 22:57:04 +0800
commite1757f98c0f5a337f1b5c44ef1638210a59f2811 (patch)
treeef1873d7e6b86d9cbeded9a5c84e63e3cd6b3baa /Timeline.Tests/Helpers/Authentication
parent2f36e9a1c8d6db2a808f874134c9cb7d57c3ef16 (diff)
downloadtimeline-e1757f98c0f5a337f1b5c44ef1638210a59f2811.tar.gz
timeline-e1757f98c0f5a337f1b5c44ef1638210a59f2811.tar.bz2
timeline-e1757f98c0f5a337f1b5c44ef1638210a59f2811.zip
Add Get method tests for PersonalTimelineController.
Diffstat (limited to 'Timeline.Tests/Helpers/Authentication')
-rw-r--r--Timeline.Tests/Helpers/Authentication/PrincipalHelper.cs23
1 files changed, 23 insertions, 0 deletions
diff --git a/Timeline.Tests/Helpers/Authentication/PrincipalHelper.cs b/Timeline.Tests/Helpers/Authentication/PrincipalHelper.cs
new file mode 100644
index 00000000..214472a2
--- /dev/null
+++ b/Timeline.Tests/Helpers/Authentication/PrincipalHelper.cs
@@ -0,0 +1,23 @@
+using System.Linq;
+using System.Security.Claims;
+using Timeline.Models;
+
+namespace Timeline.Tests.Helpers.Authentication
+{
+ public static class PrincipalHelper
+ {
+ internal const string AuthScheme = "TESTAUTH";
+
+ internal static ClaimsPrincipal Create(string username, bool administrator)
+ {
+ var identity = new ClaimsIdentity(AuthScheme);
+ identity.AddClaim(new Claim(identity.NameClaimType, username, ClaimValueTypes.String));
+ identity.AddClaims(UserRoleConvert.ToArray(administrator).Select(role => new Claim(identity.RoleClaimType, role, ClaimValueTypes.String)));
+
+ var principal = new ClaimsPrincipal();
+ principal.AddIdentity(identity);
+
+ return principal;
+ }
+ }
+}