From e1757f98c0f5a337f1b5c44ef1638210a59f2811 Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Thu, 7 Nov 2019 22:57:04 +0800 Subject: Add Get method tests for PersonalTimelineController. --- .../Helpers/Authentication/PrincipalHelper.cs | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Timeline.Tests/Helpers/Authentication/PrincipalHelper.cs (limited to 'Timeline.Tests/Helpers/Authentication/PrincipalHelper.cs') 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; + } + } +} -- cgit v1.2.3