Ejemplo n.º 1
0
        public RulesetValidator(IValidationRuleset ruleset, string text) :
            this(ruleset)
        {
            iCalendarText = text;

            try
            {
                iCalendarSerializer serializer = new iCalendarSerializer();

                // Turn off speed optimization so line/col from
                // antlr are accurate.
                serializer.OptimizeForSpeed = false;

                iCalendar = serializer.Deserialize(new StringReader(text), typeof(iCalendar)) as iCalendar;
            }
            catch (antlr.RecognitionException ex)
            {
                _RecognitionError = new ValidationErrorWithLookup(
                    "calendarParseError",
                    ValidationErrorType.Error,
                    true,
                    ex.line,
                    ex.column);
            }
        }
Ejemplo n.º 2
0
 private Range?GetRange(IValidationError e)
 {
     try {
         return(_document.EditorBuffer.ToLineRange(e.Start, e.End));
     } catch (ArgumentException) { }
     return(null);
 }
Ejemplo n.º 3
0
        static string BuildErrorMessage(IValidationError validationError)
        {
            switch (validationError.Code)
            {
            case ErrorCodes.UnallowedImageMimeType:
                return($"{validationError.Resource}の画像は使用できません。");

            case ErrorCodes.UnallowedShader:
                return($"{validationError.Resource}は使用できないシェーダーです。");

            case ErrorCodes.UnallowedVrmVersion:
                return("サポートされていないバージョンのVRMで作成されたデータです。");

            case ErrorCodes.TooLargeImageResolution:
                return($"{validationError.Resource}のサイズが大きすぎます。");

            case ErrorCodes.InvalidValue:
                return($"{validationError.Resource}は{validationError.Meta["expected"]}である必要があります。");

            case ErrorCodes.NullMaterial:
                return($"{validationError.Resource}にnullなマテリアルが含まれています。");

            case ErrorCodes.TooLargeCount:
                return($"{validationError.Resource}の数が多すぎます。" +
                       $"{validationError.Resource}の数は{validationError.Meta["max"]}以下にする必要があります。");

            case ErrorCodes.Unknown:
            default:
                return("不明なエラー");
            }
        }
Ejemplo n.º 4
0
        public RulesetValidator(IValidationRuleset ruleset, string text) :
            this(ruleset)
        {
            iCalendarText = text;

            try
            {
                iCalendarSerializer serializer = new iCalendarSerializer();
                
                // Turn off speed optimization so line/col from
                // antlr are accurate.
                serializer.OptimizeForSpeed = false;

                iCalendar = serializer.Deserialize(new StringReader(text), typeof(iCalendar)) as iCalendar;                
            }
            catch (antlr.RecognitionException ex)
            {
                _RecognitionError = new ValidationErrorWithLookup(
                    "calendarParseError", 
                    ValidationErrorType.Error, 
                    true, 
                    ex.line, 
                    ex.column);
            }
        }
Ejemplo n.º 5
0
 /// <inheritdoc/>
 public IValidationResult Remove(IValidationError error)
 {
     if (_erros.Contains(error))
     {
         _erros.Remove(error);
     }
     return(this);
 }
Ejemplo n.º 6
0
 internal MappedValidationError(IValidationError error)
 {
     MappedError  = error;
     Tags         = MappedError.Tags;
     PropertyPath = MappedError.PropertyPath;
     Value        = MappedError.Value;
     Message      = MappedError.Message;
 }
Ejemplo n.º 7
0
        public EditorErrorTag(IEditorTree editorTree, IValidationError error)
            : base(GetErrorType(error), error.Message)
        {
            _textBuffer = editorTree.TextBuffer;

            Description = error.Message;
            TaskType    = GetTaskType(error);

            _range = error;

            if (_range == null || _range.Start < 0)
            {
                _range = TextRange.EmptyRange;
            }
        }
Ejemplo n.º 8
0
        public async Task GetError_WithValidatedPropertyWithError_ShouldReturnCorrectValue(
            [Frozen] Mock <IValidator> validator,
            SampleValidable sut,
            IValidationError error,
            string value)
        {
            //arrange
            validator.Setup(v => v.Validate(value, "Property", It.IsAny <CancellationToken>()))
            .ReturnsTask(error);
            //act
            await sut.SetValueAsyncPublic(value, "Property", new CancellationTokenSource());

            var actual = sut.GetError("Property");

            //assert
            actual.Should().Be(error);
        }
Ejemplo n.º 9
0
        static TaskType GetTaskType(IValidationError error)
        {
            switch (error.Severity)
            {
            case ErrorSeverity.Fatal:
            case ErrorSeverity.Error:
                return(TaskType.Error);

            case ErrorSeverity.Warning:
                return(TaskType.Warning);

            case ErrorSeverity.Informational:
                return(TaskType.Informational);
            }

            return(TaskType.Error);
        }
Ejemplo n.º 10
0
        public EditorErrorTag(IEditorTree editorTree, IValidationError error)
            : base(GetErrorType(error), error.Message)
        {
            _textBuffer = editorTree.TextBuffer;

            var document = REditorDocument.FromTextBuffer(editorTree.TextBuffer);

            FileName = document?.FilePath;

            Description = error.Message;
            TaskType    = GetTaskType(error);

            _range = error;

            if (_range == null || _range.Start < 0)
            {
                _range = TextRange.EmptyRange;
            }
        }
Ejemplo n.º 11
0
        public static void MissingOutletValidationError_ReturnsExpected()
        {
            GameObject           gameObject      = new GameObject();
            ArrayOutletComponent outletComponent = gameObject.AddComponent <ArrayOutletComponent>();

            outletComponent.Outlets = new GameObject[1];

            IList <IValidationError> errors = Validator.Validate(gameObject);

            Assert.That(errors, Is.Not.Null);
            Assert.That(errors.Count, Is.EqualTo(1));

            IValidationError error = errors[0];

            Assert.That(error.ObjectLocalId, Is.EqualTo(outletComponent.GetLocalId()));
            Assert.That(error.ObjectType, Is.EqualTo(typeof(ArrayOutletComponent)));
            Assert.That(error.MemberInfo, Is.EqualTo(typeof(ArrayOutletComponent).GetField("Outlets")));
            Assert.That(error.ContextObject, Is.EqualTo(gameObject));
        }
        private static void SelectContextInEditor(IValidationError validationError)
        {
            object context = validationError.ContextObject;

            if (context == null)
            {
                Debug.LogWarning("Cannot select context for null context! Error: " + validationError);
                return;
            }

            UnityEngine.Object contextObject = context as UnityEngine.Object;
            if (contextObject == null)
            {
                Debug.LogWarning("Cannot select null UnityEngine.Object context: " + contextObject);
                return;
            }

            Selection.activeObject = contextObject;
            EditorGUIUtility.PingObject(contextObject);
        }
 // PRAGMA MARK - Public Interface
 public static Texture2D GetContextIcon(this IValidationError validationError)
 {
     if (validationError.ContextObject is GameObject)
     {
         return(DTValidatorIcons.PrefabIcon);
     }
     else if (validationError.ContextObject is SceneAsset)
     {
         return(DTValidatorIcons.SceneIcon);
     }
     else if (validationError.ContextObject is ScriptableObject)
     {
         return(DTValidatorIcons.ScriptableObjectIcon);
     }
     else
     {
         Debug.LogWarning("Failed to get image because context object is not recognized type: " + validationError.ContextObject + "!");
         return(Texture2DUtil.ClearTexture);
     }
 }
Ejemplo n.º 14
0
        public async Task HasError_WithPropertyValidatedTwice_ShouldReturnFalse(
            [Frozen] Mock <IValidator> validator,
            SampleValidable sut,
            IValidationError error1,
            string value1,
            string value2)
        {
            //arrange
            validator.Setup(v => v.Validate(value1, "Property", It.IsAny <CancellationToken>())).ReturnsTask(error1);
            validator.Setup(v => v.Validate(value2, "Property", It.IsAny <CancellationToken>())).ReturnsTask(NoError.Value);

            //act
            await sut.SetValueAsyncPublic(value1, "Property", new CancellationTokenSource());

            await sut.SetValueAsyncPublic(value2, "Property", new CancellationTokenSource());

            var actual = await sut.HasError(() => sut.Property);

            //assert
            actual.Should().BeFalse();
        }
Ejemplo n.º 15
0
        static string GetErrorType(IValidationError error)
        {
            string errorType = PredefinedErrorTypeNames.SyntaxError;

            switch (error.Severity)
            {
            case ErrorSeverity.Fatal:
            case ErrorSeverity.Error:
                errorType = PredefinedErrorTypeNames.SyntaxError;
                break;

            case ErrorSeverity.Warning:
                errorType = PredefinedErrorTypeNames.Warning;
                break;

            case ErrorSeverity.Informational:
                errorType = PredefinedErrorTypeNames.OtherError;
                break;
            }

            return(errorType);
        }
        public static void RecursivePrefabValidationError_ReturnsExpected()
        {
            GameObject gameObject = new GameObject();

            var outletComponent = gameObject.AddComponent <OutletComponent>();

            GameObject missingOutletPrefab = Resources.Load <GameObject>("DTValidatorTests/TestMissingOutletPrefab");

            outletComponent.Outlet = missingOutletPrefab;

            IList <IValidationError> errors = Validator.Validate(gameObject, recursive: true);

            Assert.That(errors, Is.Not.Null);
            Assert.That(errors.Count, Is.EqualTo(1));

            IValidationError error = errors[0];

            Assert.That(error.ObjectLocalId, Is.EqualTo(missingOutletPrefab.GetComponentInChildren <TestOutletComponent>().GetLocalId()));
            Assert.That(error.ObjectType, Is.EqualTo(typeof(TestOutletComponent)));
            Assert.That(error.MemberInfo, Is.EqualTo(typeof(TestOutletComponent).GetField("Outlet")));
            Assert.That(error.ContextObject, Is.EqualTo(missingOutletPrefab));
        }
        public static void MissingNestedOutletValidationError_ReturnsExpected()
        {
            GameObject gameObjectA = new GameObject("A");
            GameObject gameObjectB = new GameObject("B");

            var outletComponent = gameObjectB.AddComponent <OutletComponent>();

            outletComponent.Outlet = null;

            gameObjectB.transform.SetParent(gameObjectA.transform);

            IList <IValidationError> errors = Validator.Validate(gameObjectA);

            Assert.That(errors, Is.Not.Null);
            Assert.That(errors.Count, Is.EqualTo(1));

            IValidationError error = errors[0];

            Assert.That(error.ObjectLocalId, Is.EqualTo(outletComponent.GetLocalId()));
            Assert.That(error.ObjectType, Is.EqualTo(typeof(OutletComponent)));
            Assert.That(error.MemberInfo, Is.EqualTo(typeof(OutletComponent).GetField("Outlet")));
            Assert.That(error.ContextObject, Is.EqualTo(gameObjectA));
        }
        public static void MissingScriptableObjectValidationError_ReturnsExpected()
        {
            GameObject             gameObject             = new GameObject();
            OutletScriptableObject outletScriptableObject = ScriptableObject.CreateInstance <OutletScriptableObject>();

            outletScriptableObject.Outlet = null;

            var outletComponent = gameObject.AddComponent <OutletScriptableObjectComponent>();

            outletComponent.Outlet = outletScriptableObject;

            IList <IValidationError> errors = Validator.Validate(gameObject, recursive: true);

            Assert.That(errors, Is.Not.Null);
            Assert.That(errors.Count, Is.EqualTo(1));

            IValidationError error = errors[0];

            Assert.That(error.ObjectLocalId, Is.EqualTo(outletScriptableObject.GetLocalId()));
            Assert.That(error.ObjectType, Is.EqualTo(typeof(OutletScriptableObject)));
            Assert.That(error.MemberInfo, Is.EqualTo(typeof(OutletScriptableObject).GetField("Outlet")));
            Assert.That(error.ContextObject, Is.EqualTo(outletScriptableObject));
        }
Ejemplo n.º 19
0
 public void AddError(IValidationError error)
 {
     this.Errors.Add(error);
 }
Ejemplo n.º 20
0
 public ValidationResult(string rule, bool? passed, IValidationError[] errors) :
     this(rule)
 {
     Passed = passed;
     Errors = errors;
 }
Ejemplo n.º 21
0
 public void AddRule(ISpecification <T> specification, IValidationError error)
 {
     this.ValidationRules.Add(new ValidationRule <T>(specification, error));
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"/>.
 /// </summary>
 /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.</exception>
 public void Add(IValidationError item)
 {
     _errors.Add(item);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Constructs validation error based on existing error.
 /// </summary>
 public ValidationError(IValidationError error) :
     base(error, error.Message, error.Location, error.Severity, error.SnapshotVersion)
 {
 }
Ejemplo n.º 24
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ValidationException"/> class.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="errors">The errors.</param>
		/// <param name="entityType">Type of the entity.</param>
		public ValidationException(Type entityType, string message)
			: base(message)
		{
			ValidationErrors = new IValidationError[] {};
			EntityType = entityType;
		}
Ejemplo n.º 25
0
 public static bool IsError(this IValidationError validationError)
 {
     return(validationError != NoError.Value);
 }
Ejemplo n.º 26
0
        public ValidationErrorEventArgs(string propertyName, IValidationError error, object value)
        {
            PropertyName = propertyName;
            Error = error;
	        Value = value;
        }
Ejemplo n.º 27
0
 public QuestionService(IQuestionRepository questionRepository,
                        IValidationError validator)
 {
     this.QuestionRepository = questionRepository;
     this.Validator          = validator;
 }
Ejemplo n.º 28
0
 protected void ConsumeError(IValidationError error)
 {
     ModelState.AddModelError(error.Field, error.Error);
 }