public override void WriteActualValueTo(MessageWriter writer) { int startIndex = Math.Max(0, _breakingIndex - MaxDisplayedItems + 2); var actualValueMessage = MsgUtils.FormatCollection((IEnumerable)ActualValue, startIndex, MaxDisplayedItems); writer.Write(actualValueMessage); }
public override void WriteActualValueTo(MessageWriter writer) { // Choose startIndex in such way that '_breakingIndex' is always visible in message. int startIndex = Math.Max(0, _breakingIndex - MsgUtils.DefaultMaxItems + 2); var actualValueMessage = MsgUtils.FormatCollection((IEnumerable)ActualValue, startIndex); writer.Write(actualValueMessage); }
/// <summary> /// Initializes a new instance of the <see cref="IndexerConstraint"/> class. /// </summary> /// <param name="indexerArguments">The argument list for the indexer.</param> /// <param name="baseConstraint">The constraint to apply to the indexer.</param> public IndexerConstraint(IEnumerable <object> indexerArguments, IConstraint baseConstraint) : base(baseConstraint) { _arguments = indexerArguments.ToArray(); _argumentTypes = _arguments.Select(a => a.GetType()).ToArray(); DescriptionPrefix = $"Default indexer accepting arguments {MsgUtils.FormatCollection(_arguments)}"; }
public override void WriteAdditionalLinesTo(MessageWriter writer) { if (this.Status == ConstraintStatus.Failure) { writer.Write(" Not unique items: "); var output = MsgUtils.FormatCollection(NonUniqueItems, 0, MsgUtils.DefaultMaxItems); writer.WriteLine(output); } }
public override void WriteAdditionalLinesTo(MessageWriter writer) { if (_extraItems?.Count > 0) { string extraItemsMessage = "Extra items: "; extraItemsMessage += MsgUtils.FormatCollection(_extraItems); writer.WriteMessageLine(extraItemsMessage); } }
public override void WriteAdditionalLinesTo(MessageWriter writer) { if (_missingItems?.Count > 0) { string missingItemsMessage = "Missing items: "; missingItemsMessage += MsgUtils.FormatCollection(_missingItems); writer.WriteMessageLine(missingItemsMessage); } }
/// <summary> /// Write the actual value for a failing constraint test to a MessageWriter. /// </summary> /// <param name="writer">The writer on which the actual value is displayed</param> public override void WriteActualValueTo(MessageWriter writer) { if (_itemList == null || _itemList.Count == 0) { writer.Write("no items"); return; } writer.Write(_matchCount != 1 ? "{0} items " : "{0} item ", _matchCount); writer.Write(MsgUtils.FormatCollection(_itemList, 0, MaxDisplayCount)); }
/// <summary> /// Returns the string representation of the constraint. /// </summary> protected override string GetStringRepresentation() => $"<indexer {MsgUtils.FormatCollection(_arguments)} {BaseConstraint}>";
/// <summary> /// Test whether the constraint is satisfied by a given value /// </summary> /// <param name="actual">The value to be tested</param> public override ConstraintResult ApplyTo <TActual>(TActual actual) { Guard.ArgumentNotNull(actual, nameof(actual)); object indexedValue; var actualType = actual as Type ?? actual.GetType(); if (actualType.IsArray) { var array = actual as Array; indexedValue = array?.GetValue(_arguments.Cast <int>().ToArray()); } else { var getMethod = Reflect.GetDefaultIndexer(actualType, _argumentTypes) ?? throw new ArgumentException($"Default indexer accepting arguments {MsgUtils.FormatCollection(_arguments)} was not found on {actualType}."); indexedValue = Reflect.InvokeMethod(getMethod, actual, _arguments); } return(BaseConstraint.ApplyTo(indexedValue)); }