public string GetRedirectionPage(ErrorCase errorCase) { switch (errorCase) { case ErrorCase.UserNotFound: return("/Account/Login"); case ErrorCase.InvalidUserData: return("/Account/Login"); case ErrorCase.DuplicateEmail: return("/Account/Registration"); case ErrorCase.UnauthorizedAccess: return("/Account/Login"); case ErrorCase.CourseNotExist: return("/Study/Courses"); case ErrorCase.UndefilenError: return("/Account/Login"); default: return("/Account/Login"); } }
public Error LogError(ErrorCase errorCase) { var error = GetError(errorCase); //DataAccess.LogError(error); return(error); }
public ActionResult Error(ErrorCase errorCase = ErrorCase.UserNotFound) { var error = ErrorUtilities.LogError(errorCase); Response.StatusCode = 500; return(View(error)); }
public TaskFromAsyncTest(TestParameters parameters) { _api = parameters.Api; _sourceType = parameters.SourceTaskType; _fromAsyncType = parameters.FromAsyncTaskType; _errorCase = parameters.ErrorCase; _overloadChoice = parameters.OverloadChoice; }
public TestParameters(API api, TaskType sourceTask, TaskType fromAsyncTask, OverloadChoice overloadChoice, ErrorCase errorCase) { Api = api; SourceTaskType = sourceTask; FromAsyncTaskType = fromAsyncTask; ErrorCase = errorCase; OverloadChoice = overloadChoice; }
public void InvalidGlobGeneratesException(ErrorCase testCase) { var compiler = new GlobToRegexCompiler(); var exception = Assert.Throws <GlobFormatException>(() => compiler.CompileRegex(testCase.Glob, FileSystemCasing.CaseSensitive)); Assert.That(exception.Message, Is.EqualTo(testCase.ErrorMessage)); Assert.That(exception.ErrorPosition, Is.EqualTo(testCase.ErrorPosition)); }
public string GetErrorDescriptionFromAttribute(ErrorCase errorCase) { var memberInfo = typeof(ErrorCase). GetMember(errorCase.ToString()).FirstOrDefault(); if (memberInfo != null) { var attribute = (ErrorDescriptionAttribute)memberInfo. GetCustomAttributes(typeof(ErrorDescriptionAttribute), false).FirstOrDefault(); if (attribute != null) return attribute.Text; } return null; }
public Error GetError(ErrorCase errorCase) { var errorAction = HttpContext.Current.Request.UrlReferrer != null ? HttpContext.Current.Request.UrlReferrer.AbsolutePath : string.Empty; var errorDescription = GetErrorDescriptionFromAttribute(errorCase); var errorPageToRedirect = GetRedirectionPage(errorCase); return new Error() { DateAdded = DateTime.Now, ErrorDescription = errorDescription, RedirectActionName = errorPageToRedirect, ErrorActionName = errorAction, UserId = UserContext.CurrentUserId }; }
public Error GetError(ErrorCase errorCase) { var errorAction = HttpContext.Current.Request.UrlReferrer != null ? HttpContext.Current.Request.UrlReferrer.AbsolutePath : string.Empty; var errorDescription = GetErrorDescriptionFromAttribute(errorCase); var errorPageToRedirect = GetRedirectionPage(errorCase); return(new Error() { DateAdded = DateTime.Now, ErrorDescription = errorDescription, RedirectActionName = errorPageToRedirect, ErrorActionName = errorAction, UserId = UserContext.CurrentUserId }); }
public string GetErrorDescriptionFromAttribute(ErrorCase errorCase) { var memberInfo = typeof(ErrorCase). GetMember(errorCase.ToString()).FirstOrDefault(); if (memberInfo != null) { var attribute = (ErrorDescriptionAttribute)memberInfo. GetCustomAttributes(typeof(ErrorDescriptionAttribute), false).FirstOrDefault(); if (attribute != null) { return(attribute.Text); } } return(null); }
public string GetRedirectionPage(ErrorCase errorCase) { switch (errorCase) { case ErrorCase.UserNotFound: return "/Account/Login"; case ErrorCase.InvalidUserData: return "/Account/Login"; case ErrorCase.DuplicateEmail: return "/Account/Registration"; case ErrorCase.UnauthorizedAccess: return "/Account/Login"; case ErrorCase.CourseNotExist: return "/Study/Courses"; case ErrorCase.UndefilenError: return "/Account/Login"; default: return "/Account/Login"; } }
public void InvalidOtherUriTests() { var errorCases = new ErrorCase[] { #region invalid expand scenarios new ErrorCase() { RequestUri = String.Format("/People?$expand={0}", EmployeeTypeName), StatusCode = HttpStatusCode.BadRequest, ErrorMessage = ODataLibResourceUtil.GetString("MetadataBinder_PropertyNotDeclared", PeopleTypeName, EmployeeTypeName) }, #endregion #region invalid orderby scenarios new ErrorCase() { RequestUri = String.Format("/People?$orderby={0}", EmployeeTypeName), StatusCode = HttpStatusCode.BadRequest, ErrorMessage = ODataLibResourceUtil.GetString("MetadataBinder_OrderByExpressionNotSingleValue") }, new ErrorCase() { RequestUri = String.Format("/People?$orderby={0}/Manager/{0}", EmployeeTypeName), StatusCode = HttpStatusCode.BadRequest, ErrorMessage = ODataLibResourceUtil.GetString("MetadataBinder_OrderByExpressionNotSingleValue") }, new ErrorCase() { RequestUri = String.Format("/People?$orderby={0}/Manager/{0}", ManagerTypeName), StatusCode = HttpStatusCode.BadRequest, ErrorMessage = ODataLibResourceUtil.GetString("MetadataBinder_OrderByExpressionNotSingleValue") }, new ErrorCase() { RequestUri = String.Format("/People?$orderby={0}/DirectReports/{0}/Manager", ManagerTypeName), StatusCode = HttpStatusCode.BadRequest, ErrorMessage = ODataLibResourceUtil.GetString("MetadataBinder_PropertyAccessSourceNotSingleValue", "Manager") }, #endregion #region invalid filter scenarios //new ErrorCase() { // RequestUri = String.Format("/People?$filter={0} eq null", EmployeeTypeName), // StatusCode = HttpStatusCode.BadRequest, // ErrorMessage = DataServicesResourceUtil.GetString("RequestQueryProcessor_QueryParametersPathCannotEndInTypeIdentifier", "$filter", EmployeeTypeName) }, //new ErrorCase() { // RequestUri = String.Format("/People?$filter={0}/Manager/{0} eq null", EmployeeTypeName), // StatusCode = HttpStatusCode.BadRequest, // ErrorMessage = DataServicesResourceUtil.GetString("RequestUriProcessor_InvalidTypeIdentifier_MustBeASubType", EmployeeTypeName, ManagerTypeName) }, //new ErrorCase() { // RequestUri = String.Format("/People?$filter={0}/Manager/{0} eq null", ManagerTypeName), // StatusCode = HttpStatusCode.BadRequest, // ErrorMessage = DataServicesResourceUtil.GetString("RequestQueryProcessor_QueryParametersPathCannotEndInTypeIdentifier", "$filter", ManagerTypeName) }, new ErrorCase() { RequestUri = String.Format("/People?$filter={0}/DirectReports/Name eq 'Shyam'", ManagerTypeName), StatusCode = HttpStatusCode.BadRequest, ErrorMessage = ODataLibResourceUtil.GetString("MetadataBinder_PropertyAccessSourceNotSingleValue", "Name") }, new ErrorCase() { RequestUri = String.Format("/People?$filter={0}/DirectReports/{0}/{0}/any()", ManagerTypeName), StatusCode = HttpStatusCode.BadRequest, ErrorMessage = DataServicesResourceUtil.GetString("RequestUriProcessor_TypeIdentifierCannotBeSpecifiedAfterTypeIdentifier", ManagerTypeName, ManagerTypeName) }, new ErrorCase() { RequestUri = String.Format("/People?$filter={0}/DirectReports/{0}", ManagerTypeName), StatusCode = HttpStatusCode.BadRequest, ErrorMessage = ODataLibResourceUtil.GetString("MetadataBinder_FilterExpressionNotSingleValue") }, #endregion #region invalid POST scenarios // ODataLib was fixed and reports missing type name as an annotation. new ErrorCase() { // Type Name must be specified if the resource type has derived types - Atom Format RequestUri = "/People/" + EmployeeTypeName, StatusCode = HttpStatusCode.BadRequest, HttpMethodNames = new string[] { "POST" }, ErrorMessage = DataServicesResourceUtil.GetString("BadRequest_TypeInformationMustBeSpecifiedForInhertiance"), Payload = PayloadGenerator.Generate( new PayloadBuilder() .AddProperty("ID", 10) .AddProperty("Name", "Sarah"), UnitTestsUtil.AtomFormat), RequestContentType = UnitTestsUtil.AtomFormat }, // ODataLib was fixed and reports missing type name as an annotation. new ErrorCase() { // Type Name must be specified if the resource type has derived types - Json Format RequestUri = "/People/" + EmployeeTypeName, StatusCode = HttpStatusCode.BadRequest, HttpMethodNames = new string[] { "POST" }, ErrorMessage = DataServicesResourceUtil.GetString("BadRequest_TypeInformationMustBeSpecifiedForInhertiance"), Payload = PayloadGenerator.Generate( new PayloadBuilder() .AddProperty("ID", 10) .AddProperty("Name", "Sarah"), UnitTestsUtil.JsonLightMimeType), RequestContentType = UnitTestsUtil.JsonLightMimeType }, new ErrorCase() { // Type Name specified must be assignable to the type specified in the uri - Atom Format RequestUri = "/People/" + ManagerTypeName, StatusCode = HttpStatusCode.BadRequest, HttpMethodNames = new string[] { "POST" }, ErrorMessage = DataServicesResourceUtil.GetString("BadRequest_InvalidTypeSpecified", EmployeeTypeName, ManagerTypeName), Payload = PayloadGenerator.Generate( new PayloadBuilder() { TypeName = EmployeeTypeName } .AddProperty("ID", 10) .AddProperty("Name", "Sarah"), UnitTestsUtil.AtomFormat), RequestContentType = UnitTestsUtil.AtomFormat }, new ErrorCase() { // Type Name specified must be assignable to the type specified in the uri - Json Format RequestUri = "/People/" + ManagerTypeName, StatusCode = HttpStatusCode.BadRequest, HttpMethodNames = new string[] { "POST" }, ErrorMessage = DataServicesResourceUtil.GetString("BadRequest_InvalidTypeSpecified", EmployeeTypeName, ManagerTypeName), Payload = PayloadGenerator.Generate( new PayloadBuilder() { TypeName = EmployeeTypeName } .AddProperty("ID", 10) .AddProperty("Name", "Sarah"), UnitTestsUtil.JsonLightMimeType), RequestContentType = UnitTestsUtil.JsonLightMimeType }, #endregion }; VerifyInvalidRequest(errorCases); }
public CurrencyConvertException(ErrorCase errorCase, string message) : base(message) { HResult = (int)errorCase; }
public CurrencyConverterInnerException(ErrorCase errorCase) { HResult = (int)errorCase; }
public CurrencyConverterInnerException(string message, Exception innerException, ErrorCase errorCase) : base(message, innerException) { HResult = (int)errorCase; }
void PrintError(ErrorCase errorCase) { //Ytq_Compiler.instance.LightLineText(currentLineIndex - 1); string errorStr = "错误的行数是" + (currentLineIndex - 1) + "\r\n"; //Ytq_Compiler.instance. switch (errorCase) { case ErrorCase.TooMuchDigit: errorStr += "当前数字位数太多"; break; case ErrorCase.NeedSemicolon: errorStr += "缺少';'"; break; case ErrorCase.NeedBeginSym: errorStr += "缺少'{'"; break; case ErrorCase.NeedIdent: errorStr += "当前行需要变量"; break; case ErrorCase.NeedLparen: errorStr += "缺少'('"; break; case ErrorCase.NeedRparen: errorStr += "缺少')'"; break; case ErrorCase.NeedBecomes: errorStr += "缺少'='"; break; case ErrorCase.NeedVariable: errorStr += "只有变量能被赋值'"; break; case ErrorCase.NeedInSym: errorStr += "缺少 in "; break; case ErrorCase.NeedRangeSym: errorStr += "缺少 ... "; break; case ErrorCase.NeedCompare: errorStr += "缺少关系运算符"; break; case ErrorCase.NeedFactor: errorStr += "因子只能为数字、变量和表达式"; break; case ErrorCase.Undefine: errorStr += (currentIdent + " 该变量不存在"); break; } Ytq_Compiler.instance.AnswerAppendStr(errorStr, Color.Red); }
public CurrencyConvertException(ErrorCase errorCase) : base() { HResult = (int)errorCase; }
public void InvalidUriPathTests() { var errorCases = new ErrorCase[] { new ErrorCase() { RequestUri = "/People(3)/" + ManagerTypeName, StatusCode = HttpStatusCode.NotFound, ErrorMessage = DataServicesResourceUtil.GetString("RequestUriProcessor_ResourceNotFound", ManagerTypeName) }, new ErrorCase() { RequestUri = "/People(3)/" + ManagerTypeName + "(3)", StatusCode = HttpStatusCode.BadRequest, ErrorMessage = DataServicesResourceUtil.GetString("RequestUriProcessor_SyntaxError") }, new ErrorCase() { RequestUri = "/People(2)/DirectReports", StatusCode = HttpStatusCode.NotFound, ErrorMessage = DataServicesResourceUtil.GetString("RequestUriProcessor_ResourceNotFound", "DirectReports") }, new ErrorCase() { RequestUri = "/People(2)/" + EmployeeTypeName + "/DirectReports", StatusCode = HttpStatusCode.NotFound, ErrorMessage = DataServicesResourceUtil.GetString("RequestUriProcessor_ResourceNotFound", "DirectReports") }, new ErrorCase() { RequestUri = String.Format("/People/{0}/Manager/{0}", EmployeeTypeName), StatusCode = HttpStatusCode.BadRequest, ErrorMessage = DataServicesResourceUtil.GetString("RequestUriProcessor_CannotQueryCollections", EmployeeTypeName) }, }; VerifyInvalidRequest(errorCases); }
private static void VerifyInvalidRequest(ErrorCase[] errorCases) { using (TestWebRequest request = services[1].CreateForInProcess()) { request.StartService(); test.TestUtil.RunCombinations(errorCases, (error) => { string[] methodNames = error.HttpMethodNames == null ? new string[] { "GET" } : error.HttpMethodNames; foreach (var httpMethodName in methodNames) { request.RequestUriString = error.RequestUri; request.Accept = UnitTestsUtil.MimeAny; request.HttpMethod = httpMethodName; if (error.Payload != null) { request.SetRequestStreamAsText(error.Payload); request.RequestContentType = error.RequestContentType; } Exception exception = test.TestUtil.RunCatching(request.SendRequest); UnitTestsUtil.VerifyTestException(exception, (int)error.StatusCode, error.ErrorMessage); } }); } }
public Error LogError(ErrorCase errorCase) { var error = GetError(errorCase); //DataAccess.LogError(error); return error; }
public ActionResult Error(ErrorCase errorCase = ErrorCase.UserNotFound) { var error = ErrorUtilities.LogError(errorCase); Response.StatusCode = 500; return View(error); }