aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/Helpers/PrincipalHelper.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-11-20 00:28:53 +0800
committercrupest <crupest@outlook.com>2019-11-20 00:28:53 +0800
commita72960e54a89bd31dcb8be8f52e097007dfd23e5 (patch)
tree55eaf43bda897148b0fa8a65406e7289aed3832e /Timeline.Tests/Helpers/PrincipalHelper.cs
parentf3c7912caec2e9eee8a685d8751894f357528a71 (diff)
downloadtimeline-a72960e54a89bd31dcb8be8f52e097007dfd23e5.tar.gz
timeline-a72960e54a89bd31dcb8be8f52e097007dfd23e5.tar.bz2
timeline-a72960e54a89bd31dcb8be8f52e097007dfd23e5.zip
Clean and refactor tests.
Diffstat (limited to 'Timeline.Tests/Helpers/PrincipalHelper.cs')
-rw-r--r--Timeline.Tests/Helpers/PrincipalHelper.cs23
1 files changed, 23 insertions, 0 deletions
diff --git a/Timeline.Tests/Helpers/PrincipalHelper.cs b/Timeline.Tests/Helpers/PrincipalHelper.cs
new file mode 100644
index 00000000..89f3f7b1
--- /dev/null
+++ b/Timeline.Tests/Helpers/PrincipalHelper.cs
@@ -0,0 +1,23 @@
+using System.Linq;
+using System.Security.Claims;
+using Timeline.Models;
+
+namespace Timeline.Tests.Helpers
+{
+ 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;
+ }
+ }
+}