Beispiel #1
0
        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");
            }
        }
Beispiel #2
0
        public Error LogError(ErrorCase errorCase)
        {
            var error = GetError(errorCase);

            //DataAccess.LogError(error);
            return(error);
        }
Beispiel #3
0
        public ActionResult Error(ErrorCase errorCase = ErrorCase.UserNotFound)
        {
            var error = ErrorUtilities.LogError(errorCase);

            Response.StatusCode = 500;
            return(View(error));
        }
Beispiel #4
0
 public TaskFromAsyncTest(TestParameters parameters)
 {
     _api            = parameters.Api;
     _sourceType     = parameters.SourceTaskType;
     _fromAsyncType  = parameters.FromAsyncTaskType;
     _errorCase      = parameters.ErrorCase;
     _overloadChoice = parameters.OverloadChoice;
 }
Beispiel #5
0
 public TaskFromAsyncTest(TestParameters parameters)
 {
     _api = parameters.Api;
     _sourceType = parameters.SourceTaskType;
     _fromAsyncType = parameters.FromAsyncTaskType;
     _errorCase = parameters.ErrorCase;
     _overloadChoice = parameters.OverloadChoice;
 }
Beispiel #6
0
 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));
        }
Beispiel #8
0
        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;
        }
Beispiel #9
0
        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
            };
        }
Beispiel #10
0
        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
            });
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
 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);
        }
Beispiel #14
0
 public CurrencyConvertException(ErrorCase errorCase, string message) : base(message)
 {
     HResult = (int)errorCase;
 }
Beispiel #15
0
 public CurrencyConverterInnerException(ErrorCase errorCase)
 {
     HResult = (int)errorCase;
 }
Beispiel #16
0
 public CurrencyConverterInnerException(string message, Exception innerException, ErrorCase errorCase) : base(message, innerException)
 {
     HResult = (int)errorCase;
 }
Beispiel #17
0
 public TestParameters(API api, TaskType sourceTask, TaskType fromAsyncTask, OverloadChoice overloadChoice, ErrorCase errorCase)
 {
     Api = api;
     SourceTaskType = sourceTask;
     FromAsyncTaskType = fromAsyncTask;
     ErrorCase = errorCase;
     OverloadChoice = overloadChoice;
 }
Beispiel #18
0
        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);
        }
Beispiel #19
0
 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);
                    }
                });
            }
        }
Beispiel #22
0
 public Error LogError(ErrorCase errorCase)
 {
     var error = GetError(errorCase);
     //DataAccess.LogError(error);
     return error;
 }
Beispiel #23
0
        public ActionResult Error(ErrorCase errorCase = ErrorCase.UserNotFound)
        {
            var error = ErrorUtilities.LogError(errorCase);

            Response.StatusCode = 500;
            return View(error);
        }