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); } }
private Range?GetRange(IValidationError e) { try { return(_document.EditorBuffer.ToLineRange(e.Start, e.End)); } catch (ArgumentException) { } return(null); }
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("不明なエラー"); } }
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); } }
/// <inheritdoc/> public IValidationResult Remove(IValidationError error) { if (_erros.Contains(error)) { _erros.Remove(error); } return(this); }
internal MappedValidationError(IValidationError error) { MappedError = error; Tags = MappedError.Tags; PropertyPath = MappedError.PropertyPath; Value = MappedError.Value; Message = MappedError.Message; }
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; } }
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); }
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); }
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; } }
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); } }
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(); }
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)); }
public void AddError(IValidationError error) { this.Errors.Add(error); }
public ValidationResult(string rule, bool? passed, IValidationError[] errors) : this(rule) { Passed = passed; Errors = errors; }
public void AddRule(ISpecification <T> specification, IValidationError error) { this.ValidationRules.Add(new ValidationRule <T>(specification, error)); }
/// <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); }
/// <summary> /// Constructs validation error based on existing error. /// </summary> public ValidationError(IValidationError error) : base(error, error.Message, error.Location, error.Severity, error.SnapshotVersion) { }
/// <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; }
public static bool IsError(this IValidationError validationError) { return(validationError != NoError.Value); }
public ValidationErrorEventArgs(string propertyName, IValidationError error, object value) { PropertyName = propertyName; Error = error; Value = value; }
public QuestionService(IQuestionRepository questionRepository, IValidationError validator) { this.QuestionRepository = questionRepository; this.Validator = validator; }
protected void ConsumeError(IValidationError error) { ModelState.AddModelError(error.Field, error.Error); }