Exemple #1
0
        public void AsTextTest()
        {
            ErrorDictionary target = new ErrorDictionary();
            string          actual;

            actual = target.AsText();
            Assert.AreEqual(string.Empty, actual);

            ErrorCollection field1 = new ErrorCollection();

            field1.Add("Test 1");
            target.Add("field1", field1);
            actual = target.AsText();
            Assert.AreEqual("* Test 1", actual);

            ErrorCollection field2 = new ErrorCollection();

            field2.Add("Test 2");
            target.Add("field2", field2);
            actual = target.AsText();
            Assert.AreEqual("* Test 1\n* Test 2", actual);

            target["field1"].Add("Test 3");
            actual = target.AsText();
            Assert.AreEqual("* Test 1\n* Test 3\n* Test 2", actual);
        }
Exemple #2
0
        public void AsULTest()
        {
            ErrorDictionary target = new ErrorDictionary();
            string          actual;

            actual = target.AsUL();
            Assert.AreEqual(string.Empty, actual);

            ErrorCollection field1 = new ErrorCollection();

            field1.Add("Test 1");
            target.Add("field1", field1);
            actual = target.AsUL();
            Assert.AreEqual("<ul class=\"errorlist\"><li><ul class=\"errorlist\"><li><label for=\"id_field1\">Test 1</label></li></ul></li></ul>", actual);

            ErrorCollection field2 = new ErrorCollection();

            field2.Add("Test 2");
            target.Add("field2", field2);
            actual = target.AsUL();
            Assert.AreEqual("<ul class=\"errorlist\"><li><ul class=\"errorlist\"><li><label for=\"id_field1\">Test 1</label></li></ul></li><li><ul class=\"errorlist\"><li><label for=\"id_field2\">Test 2</label></li></ul></li></ul>", actual);

            target["field1"].Add("Test 3");
            actual = target.AsUL();
            Assert.AreEqual("<ul class=\"errorlist\"><li><ul class=\"errorlist\"><li><label for=\"id_field1\">Test 1</label></li><li><label for=\"id_field1\">Test 3</label></li></ul></li><li><ul class=\"errorlist\"><li><label for=\"id_field2\">Test 2</label></li></ul></li></ul>", actual);
        }
Exemple #3
0
 private void BuildDictionary()
 {
     //add custom errors here
     dictionary.Add <PlayerPrivacyException>(new DictionaryObject {
         ResultCode = 1, Title = "Player has turned on privacy", StatusCode = 404
     });
     dictionary.Add <UnResolvedException>(new DictionaryObject {
         ResultCode = 2, Title = "Failed to handle Ret message", StatusCode = 500
     });
 }
Exemple #4
0
 public void AddErrors(Dictionary <Type, DictionaryObject> dictionary)
 {
     foreach (KeyValuePair <Type, DictionaryObject> entry in dictionary)
     {
         exceptionContainer.Add(entry.Value, entry.Key);
     }
 }
Exemple #5
0
 protected ErrorDictionary <DictionaryObject> AddCoreErrors(ErrorDictionary <DictionaryObject> exceptionContainer)
 {
     exceptionContainer.Add <AppSettingsMisConfigurationException>(new DictionaryObject
     {
         ResultCode = Codes.ResultCodes.AppSettings,
         StatusCode = (int)HttpStatusCode.InternalServerError,
         Title      = "Failed App Settings configuration"
     });
     exceptionContainer.Add <EmptyValidationListException>(new DictionaryObject
     {
         ResultCode = Codes.ResultCodes.EmptyValidationList,
         StatusCode = (int)HttpStatusCode.InternalServerError,
         Title      = "Validation functionality requires populated list"
     });
     exceptionContainer.Add <MalformedValidationAttributeException>(new DictionaryObject
     {
         ResultCode = Codes.ResultCodes.MalformedValidation,
         StatusCode = (int)HttpStatusCode.InternalServerError,
         Title      = "Validation Exception: Malformed"
     });
     return(exceptionContainer);
 }
Exemple #6
0
        public void AsULTest1()
        {
            ErrorDictionary target = new ErrorDictionary();
            string          actual;
            string          errorClass = "errors";

            ErrorCollection field1 = new ErrorCollection();

            field1.Add("Test 1");
            target.Add("field1", field1);
            actual = target.AsUL(errorClass);
            Assert.AreEqual("<ul class=\"errors\"><li><ul class=\"errors\"><li><label for=\"id_field1\">Test 1</label></li></ul></li></ul>", actual);
        }
        public static ErrorDictionary GetErrorDictionary(this ModelStateDictionary modelState)
        {
            var errors = new ErrorDictionary();

            foreach (var model in modelState)
            {
                foreach (var error in model.Value.Errors)
                {
                    errors.Add(model.Key, error.ErrorMessage);
                }
            }

            return errors;
        }
 public override void AddError(string key, string errorMessage)
 {
     ErrorDictionary.Add(new ValidationError(key, errorMessage));
 }