public void CreateSchemaError_SetExtension() { // arrange var message = "FooBar"; var key = "foo"; var value = "bar"; // act ISchemaError schemaError = SchemaErrorBuilder.New() .SetMessage(message) .SetExtension(key, value) .Build(); // assert Assert.Equal(message, schemaError.Message); Assert.Empty(schemaError.SyntaxNodes); Assert.Collection(schemaError.Extensions, t => { Assert.Equal(key, t.Key); Assert.Equal(value, t.Value); }); Assert.Null(schemaError.Exception); Assert.Null(schemaError.TypeSystemObject); Assert.Null(schemaError.Path); Assert.Null(schemaError.Code); }
// TODO : resources private static string CreateErrorMessage(IReadOnlyList <ISchemaError> errors) { if (errors is null || errors.Count == 0) { return("Unexpected schema exception occurred."); } var message = new StringBuilder(); message.AppendLine("For more details look at the `Errors` property."); message.AppendLine(); for (int i = 0; i < errors.Count; i++) { ISchemaError error = errors[i]; message.Append($"{i + 1}. {error.Message}"); if (error.TypeSystemObject is not null) { message.Append($" ({error.TypeSystemObject.GetType().GetTypeName()})"); } message.AppendLine(); } return(message.ToString()); }
public void ReportError(ISchemaError error) { if (error is null) { throw new ArgumentNullException(nameof(error)); } _initializationContext.ReportError(error); }
public void ReportError(ISchemaError error) { if (error == null) { throw new ArgumentNullException(nameof(error)); } Errors.Add(error); }
private static string CreateErrorMessage(ISchemaError error) { if (error.TypeSystemObject == null) { return error.Message; } else { return $"{error.Message} - Type: {error.TypeSystemObject.Name}"; } }
private static string CreateErrorMessage(ISchemaError error) { if (error.TypeSystemObject == null || error.TypeSystemObject.Name.IsEmpty) { return(error.Message); } else { return($"{error.Message} - Type: {error.TypeSystemObject.Name}"); } }
public void CreateSchemaError_Exception() { // arrange var exception = new Exception("FooBar"); // act ISchemaError schemaError = SchemaErrorBuilder.New() .SetException(exception) .Build(); // assert Assert.Equal(exception.Message, schemaError.Message); Assert.Equal(exception, schemaError.Exception); Assert.Empty(schemaError.SyntaxNodes); Assert.Empty(schemaError.Extensions); Assert.Null(schemaError.TypeSystemObject); Assert.Null(schemaError.Path); Assert.Null(schemaError.Code); }
public void CreateSchemaError_AddSyntaxNode() { // arrange var message = "FooBar"; var node = new NameNode("foo"); // act ISchemaError schemaError = SchemaErrorBuilder.New() .SetMessage(message) .AddSyntaxNode(node) .Build(); // assert Assert.Equal(message, schemaError.Message); Assert.Collection(schemaError.SyntaxNodes, t => Assert.Equal(node, t)); Assert.Empty(schemaError.Extensions); Assert.Null(schemaError.Exception); Assert.Null(schemaError.TypeSystemObject); Assert.Null(schemaError.Path); Assert.Null(schemaError.Code); }
public void CreateSchemaError_ThreeArguments_PopertiesAreSet() { // arrange var message = "FooBar"; var exception = new Exception(); var type = new StringType(); // act ISchemaError schemaError = SchemaErrorBuilder.New() .SetMessage(message) .SetException(exception) .SetTypeSystemObject(type) .Build(); // assert Assert.Equal(message, schemaError.Message); Assert.Equal(exception, schemaError.Exception); Assert.Equal(type, schemaError.TypeSystemObject); Assert.Empty(schemaError.SyntaxNodes); Assert.Empty(schemaError.Extensions); Assert.Null(schemaError.Path); Assert.Null(schemaError.Code); }
/// <summary> /// Determines whether the <see cref="SchemaErrorCollection"/> /// contains the specified <see cref="ISchemaError"/> element. /// </summary> /// <param name="value"> /// The <see cref="ISchemaError"/> object to locate /// in the <see cref="SchemaErrorCollection"/>. /// This argument may be a null reference. /// </param> /// <returns> /// <c>true</c> if <paramref name="value"/> is found in the /// <see cref="SchemaErrorCollection"/>; otherwise, <c>false</c>. /// </returns> /// <remarks> /// Please refer to <see cref="ArrayList.Contains"/> for details. /// </remarks> public bool Contains(ISchemaError value) { return (IndexOf(value) >= 0); }
/// <summary> /// Searches a section of the sorted /// <see cref="SchemaErrorCollection"/> for an /// <see cref="ISchemaError"/> element using the /// specified comparer and returns the zero-based index of the element. /// </summary> /// <param name="index"> /// The zero-based starting index of the range of elements to search. /// </param> /// <param name="count">The number of elements to search.</param> /// <param name="value"> /// The <see cref="ISchemaError"/> object to locate /// in the <see cref="SchemaErrorCollection"/>. /// This argument may be a null reference. /// </param> /// <param name="comparer"> /// <para>The <see cref="IComparer"/> implementation /// to use when comparing elements.</para> /// <para>-or-</para> /// <para>A null reference to use the <see cref="IComparable"/> /// implementation of each element.</para></param> /// <returns> /// The zero-based index of <paramref name="value"/> in the sorted /// <see cref="SchemaErrorCollection"/>, if <paramref name="value"/> /// is found; otherwise, a negative number, which is the bitwise /// complement of the index of the next element that is larger than /// <paramref name="value"/> or, if there is no larger element, the /// bitwise complement of <see cref="Count"/>.</returns> /// <exception cref="ArgumentException"><para> /// <paramref name="index"/> and <paramref name="count"/> /// do not denote a valid range of elements in the /// <see cref="SchemaErrorCollection"/>. /// </para><para>-or-</para><para> /// <paramref name="comparer"/> is a null reference, /// and SchemaError does not implement /// the <see cref="IComparable"/> interface. /// </para></exception> /// <exception cref="ArgumentOutOfRangeException"> /// <para><paramref name="index"/> is less than zero.</para> /// <para>-or-</para> /// <para><paramref name="count"/> is less than zero.</para> /// </exception> /// <remarks> /// Please refer to /// <see cref="ArrayList.BinarySearch(Int32, Int32, Object, IComparer)"/> /// for details. /// </remarks> public int BinarySearch(int index, int count, ISchemaError value, IComparer comparer) { if (index < 0) throw new ArgumentOutOfRangeException("index", index, "Argument cannot be negative."); if (count < 0) throw new ArgumentOutOfRangeException("count", count, "Argument cannot be negative."); if (index + count > _data.Count) throw new ArgumentException( "Arguments denote invalid range of elements."); return Array.BinarySearch(_data.Items, index, _data.Count, value, comparer); }
/// <overloads> /// Uses a binary search algorithm to locate a specific element /// in the sorted <see cref="SchemaErrorCollection"/> /// or a portion of it. /// </overloads> /// <summary> /// Searches the entire sorted <see cref="SchemaErrorCollection"/> /// for an <see cref="ISchemaError"/> element using the /// specified comparer and returns the zero-based index of the element. /// </summary> /// <param name="value"> /// The <see cref="ISchemaError"/> object to locate /// in the <see cref="SchemaErrorCollection"/>. /// This argument may be a null reference. /// </param> /// <param name="comparer"> /// <para>The <see cref="IComparer"/> implementation /// to use when comparing elements.</para> /// <para>-or-</para> /// <para>A null reference to use the <see cref="IComparable"/> /// implementation of each element.</para></param> /// <returns> /// The zero-based index of <paramref name="value"/> in the sorted /// <see cref="SchemaErrorCollection"/>, if <paramref name="value"/> /// is found; otherwise, a negative number, which is the bitwise /// complement of the index of the next element that is larger than /// <paramref name="value"/> or, if there is no larger element, the /// bitwise complement of <see cref="Count"/>.</returns> /// <exception cref="ArgumentException"> /// <paramref name="comparer"/> is a null reference, /// and SchemaError does not implement /// the <see cref="IComparable"/> interface.</exception> /// <remarks> /// Please refer to /// <see cref="ArrayList.BinarySearch(Object, IComparer)"/> /// for details. /// </remarks> public int BinarySearch( ISchemaError value, IComparer comparer) { return Array.BinarySearch(_data.Items, 0, _data.Count, value, comparer); }
/// <summary> /// Adds the elements of a <see cref="ISchemaError"/> array /// to the end of the <see cref="SchemaErrorCollection"/>. /// </summary> /// <param name="array"> /// An <see cref="Array"/> of <see cref="ISchemaError"/> /// elements that should be added to the end of the /// <see cref="SchemaErrorCollection"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <exception cref="NotSupportedException"><para> /// The <see cref="SchemaErrorCollection"/> /// is read-only or has a fixed size. /// </para><para>-or-</para><para> /// The <b>SchemaErrorCollection</b> already contains /// one or more elements in <paramref name="array"/>, /// and the <b>SchemaErrorCollection</b> /// ensures that all elements are unique. /// </para></exception> /// <remarks> /// Please refer to <see cref="ArrayList.AddRange"/> for details. /// </remarks> public virtual void AddRange(ISchemaError[] array) { if (array == null) throw new ArgumentNullException("array"); AddRange(array, array.Length); }
/// <summary> /// Adds a <see cref="ISchemaError"/> to the end /// of the <see cref="SchemaErrorCollection"/>. /// </summary> /// <param name="value"> /// The <see cref="ISchemaError"/> object to be added /// to the end of the <see cref="SchemaErrorCollection"/>. /// This argument may be a null reference. /// </param> /// <returns> /// The <see cref="SchemaErrorCollection"/> /// index at which the <paramref name="value"/> has been added. /// </returns> /// <exception cref="NotSupportedException"><para> /// The <see cref="SchemaErrorCollection"/> /// is read-only or has a fixed size. /// </para><para>-or-</para><para> /// The <b>SchemaErrorCollection</b> /// already contains <paramref name="value"/>, /// and the <b>SchemaErrorCollection</b> /// ensures that all elements are unique.</para></exception> /// <remarks> /// Please refer to <see cref="ArrayList.Add"/> for details. /// </remarks> public virtual int Add(ISchemaError value) { if (_data.IsUnique) CheckUnique(value); int count = _data.Count; if (count == _data.Items.Length) _data.EnsureCapacity(count + 1); _data.Items[count] = value; return _data.Count++; }
/// <summary> /// Inserts a <see cref="ISchemaError"/> element into the /// <see cref="SchemaErrorCollection"/> at the specified index. /// </summary> /// <param name="index"> /// The zero-based index at which <paramref name="value"/> /// should be inserted.</param> /// <param name="value"> /// The <see cref="ISchemaError"/> object to insert /// into the <see cref="SchemaErrorCollection"/>. /// This argument may be a null reference. /// </param> /// <exception cref="ArgumentOutOfRangeException"> /// <para><paramref name="index"/> is less than zero.</para> /// <para>-or-</para><para> /// <paramref name="index"/> is greater than <see cref="Count"/>. /// </para></exception> /// <exception cref="NotSupportedException"><para> /// The <see cref="SchemaErrorCollection"/> /// is read-only or has a fixed size. /// </para><para>-or-</para><para> /// The <b>SchemaErrorCollection</b> /// already contains <paramref name="value"/>, /// and the <b>SchemaErrorCollection</b> /// ensures that all elements are unique. /// </para></exception> /// <remarks> /// Please refer to <see cref="ArrayList.Insert"/> for details. /// </remarks> public virtual void Insert(int index, ISchemaError value) { int count = _data.Count; if (index < 0) throw new ArgumentOutOfRangeException("index", index, "Argument cannot be negative."); if (index > count) throw new ArgumentOutOfRangeException("index", index, "Argument cannot exceed Count."); if (_data.IsUnique) CheckUnique(value); if (count == _data.Items.Length) _data.EnsureCapacity(count + 1); if (index < count) Array.Copy(_data.Items, index, _data.Items, index + 1, count - index); _data.Items[index] = value; _data.Count++; }
public void ReportError(ISchemaError error) { throw new NotImplementedException(); }
public void SetCapacity(int capacity) { if (capacity == Items.Length) return; if (capacity == 0) { Items = new ISchemaError[DefaultCapacity]; return; } ISchemaError[] items = new ISchemaError[capacity]; Array.Copy(Items, items, Count); Items = items; }
/// <overloads> /// Copies the <see cref="SchemaErrorCollection"/> /// or a portion of it to a one-dimensional array. /// </overloads> /// <summary> /// Copies the entire <see cref="SchemaErrorCollection"/> /// to a one-dimensional <see cref="Array"/> /// of <see cref="ISchemaError"/> elements, /// starting at the beginning of the target array. /// </summary> /// <param name="array"> /// The one-dimensional <see cref="Array"/> that is the destination /// of the <see cref="ISchemaError"/> elements copied from the /// <see cref="SchemaErrorCollection"/>. /// The <b>Array</b> must have zero-based indexing.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <exception cref="ArgumentException"> /// The number of elements in the source /// <see cref="SchemaErrorCollection"/> is greater than /// the available space in the destination <paramref name="array"/>. /// </exception> /// <remarks> /// Please refer to <see cref="ArrayList.CopyTo"/> for details. /// </remarks> public void CopyTo(ISchemaError[] array) { ((ICollection) this).CopyTo(array, 0); }
private void CheckUnique(ISchemaError value, int index) { int existing = IndexOf(value); if (existing >= 0 && existing != index) throw new NotSupportedException( "Unique collections cannot contain duplicate elements."); }
private void CheckUnique(ISchemaError value) { if (IndexOf(value) >= 0) throw new NotSupportedException( "Unique collections cannot contain duplicate elements."); }
private void AddRange(ISchemaError[] array, int range) { if (range == 0) return; if (_data.IsUnique) foreach (ISchemaError value in array) CheckUnique(value); if (_data.Count + range > _data.Items.Length) _data.EnsureCapacity(_data.Count + range); Array.Copy(array, 0, _data.Items, _data.Count, range); _data.Count += range; }
/// <summary> /// Copies the elements of the <see cref="SchemaErrorCollection"/> /// to a new <see cref="Array"/> of /// <see cref="ISchemaError"/> elements. /// </summary> /// <returns> /// A one-dimensional <see cref="Array"/> of /// <see cref="ISchemaError"/> elements containing copies of the /// elements of the <see cref="SchemaErrorCollection"/>. /// </returns> /// <remarks> /// Please refer to <see cref="ArrayList.ToArray"/> for details. /// </remarks> public ISchemaError[] ToArray() { ISchemaError[] array = new ISchemaError[_data.Count]; Array.Copy(_data.Items, array, _data.Count); return array; }
/// <summary> /// Removes the first occurrence of the specified /// <see cref="ISchemaError"/> from the /// <see cref="SchemaErrorCollection"/>. /// </summary> /// <param name="value"> /// The <see cref="ISchemaError"/> object to remove /// from the <see cref="SchemaErrorCollection"/>. /// This argument may be a null reference. /// </param> /// <exception cref="NotSupportedException"> /// The <see cref="SchemaErrorCollection"/> /// is read-only or has a fixed size.</exception> /// <remarks> /// Please refer to <see cref="ArrayList.Remove"/> for details. /// </remarks> public void Remove(ISchemaError value) { int index = IndexOf(value); if (index >= 0) RemoveAt(index); }
/// <summary> /// Copies the entire <see cref="SchemaErrorCollection"/> /// to a one-dimensional <see cref="Array"/> /// of <see cref="ISchemaError"/> elements, /// starting at the specified index of the target array. /// </summary> /// <param name="array"> /// The one-dimensional <see cref="Array"/> that is the destination /// of the <see cref="ISchemaError"/> elements copied from the /// <see cref="SchemaErrorCollection"/>. /// The <b>Array</b> must have zero-based indexing.</param> /// <param name="arrayIndex"> /// The zero-based index in <paramref name="array"/> /// at which copying begins.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="arrayIndex"/> is less than zero.</exception> /// <exception cref="ArgumentException"><para> /// <paramref name="arrayIndex"/> is equal to or /// greater than the length of <paramref name="array"/>. /// </para><para>-or-</para><para> /// The number of elements in the source /// <see cref="SchemaErrorCollection"/> is greater /// than the available space from <paramref name="arrayIndex"/> /// to the end of the destination <paramref name="array"/>. /// </para></exception> /// <remarks> /// Please refer to <see cref="ArrayList.CopyTo"/> for details. /// </remarks> public void CopyTo(ISchemaError[] array, int arrayIndex) { ((ICollection) this).CopyTo(array, arrayIndex); }
public override void AddRange(ISchemaError[] array) { throw new NotSupportedException( "Read-only collections cannot be modified."); }
public override void Insert(int index, ISchemaError value) { throw new NotSupportedException( "Read-only collections cannot be modified."); }
/// <summary> /// Initializes a new instance of the /// <see cref="SchemaErrorCollection"/> class /// that contains elements copied from the specified /// <see cref="ISchemaError"/> array and that has the /// same initial capacity as the number of elements copied. /// </summary> /// <param name="array"> /// An <see cref="Array"/> of <see cref="ISchemaError"/> /// elements that are copied to the new collection.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <remarks> /// Please refer to <see cref="ArrayList(ICollection)"/> for details. /// </remarks> public SchemaErrorCollection(ISchemaError[] array) { if (array == null) throw new ArgumentNullException("array"); _data = new Data(); _data.Items = new ISchemaError[array.Length]; AddRange(array, array.Length); }
public override int Add(ISchemaError value) { throw new NotSupportedException( "Read-only collections cannot be modified."); }
/// <summary> /// Returns the zero-based index of the first occurrence /// of the specified <see cref="ISchemaError"/> in the /// <see cref="SchemaErrorCollection"/>. /// </summary> /// <param name="value"> /// The <see cref="ISchemaError"/> object /// to locate in the <see cref="SchemaErrorCollection"/>. /// This argument may be a null reference. /// </param> /// <returns> /// The zero-based index of the first occurrence of /// <paramref name="value"/> in the <see cref="SchemaErrorCollection"/>, /// if found; otherwise, -1.</returns> /// <remarks> /// Please refer to <see cref="ArrayList.IndexOf"/> for details. /// </remarks> public int IndexOf(ISchemaError value) { int count = _data.Count; ISchemaError[] items = _data.Items; if ( value == null) { for (int i = 0; i < count; i++) if (items[i] == null) return i; return -1; } for (int i = 0; i < count; i++) if (value.Equals(items[i])) return i; return -1; }