From 5b5bb69c3ba2150816f120860be46d49c5bc37aa Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 17 Nov 2019 23:04:21 +0800 Subject: Fix typo in path of personal timeline controller actions. Add timeline permission test. --- .../Authentication/AuthenticationExtensions.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs') diff --git a/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs b/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs index 34d7e460..6a78be7a 100644 --- a/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs +++ b/Timeline.Tests/Helpers/Authentication/AuthenticationExtensions.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc.Testing; using Newtonsoft.Json; +using System; using System.Net.Http; using System.Threading.Tasks; using Timeline.Models.Http; @@ -7,6 +8,13 @@ using Timeline.Tests.Mock.Data; namespace Timeline.Tests.Helpers.Authentication { + public enum AuthType + { + None, + User, + Admin + } + public static class AuthenticationExtensions { private const string CreateTokenUrl = "/token/create"; @@ -36,5 +44,16 @@ namespace Timeline.Tests.Helpers.Authentication { return factory.CreateClientWithCredential(MockUser.Admin.Username, MockUser.Admin.Password); } + + public static Task CreateClientAs(this WebApplicationFactory factory, AuthType authType) where T : class + { + return authType switch + { + AuthType.None => Task.FromResult(factory.CreateDefaultClient()), + AuthType.User => factory.CreateClientAsUser(), + AuthType.Admin => factory.CreateClientAsAdmin(), + _ => throw new InvalidOperationException("Unknown auth type.") + }; + } } } -- cgit v1.2.3