From 006d799d2fe5f081c188f95a8590c4b75a93caae Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Mon, 28 Oct 2019 23:35:00 +0800 Subject: Add UserDetailController unit tests. --- Timeline/Filters/User.cs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Timeline/Filters/User.cs (limited to 'Timeline/Filters') diff --git a/Timeline/Filters/User.cs b/Timeline/Filters/User.cs new file mode 100644 index 00000000..22fae938 --- /dev/null +++ b/Timeline/Filters/User.cs @@ -0,0 +1,42 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; +using System; +using Timeline.Models.Http; + +namespace Timeline +{ + public static partial class ErrorCodes + { + public static partial class Http + { + public static partial class Filter // bxx = 1xx + { + public static class User // bbb = 101 + { + public const int NotExist = 11010001; + } + + } + } + } +} + +namespace Timeline.Filters +{ + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] + public class CatchUserNotExistExceptionAttribute : ExceptionFilterAttribute + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "ASP.Net already checked.")] + public override void OnException(ExceptionContext context) + { + var body = new CommonResponse( + ErrorCodes.Http.Filter.User.NotExist, + Resources.Filters.MessageUserNotExist); + + if (context.HttpContext.Request.Method == "GET") + context.Result = new NotFoundObjectResult(body); + else + context.Result = new BadRequestObjectResult(body); + } + } +} -- cgit v1.2.3