public INameParameterInfo FormatNameParameter() { if (!IsEvaluated) { return(NameParameterInfo.Unknown); } if (Value is IComplexParameter p) { return(new NameParameterInfo(true, _formattingService.FormatValue(Value), p.Details.VerificationStatus)); } return(new NameParameterInfo(true, _formattingService.FormatValue(Value), ParameterVerificationStatus.NotApplicable)); }
/// <summary> /// Formats <paramref name="value"/> as dictionary, where key-value pairs will be formatted in order based on key. /// </summary> public string FormatValue(object value, IValueFormattingService formattingService) { var dictionary = (IDictionary)value; var keyValues = dictionary .Keys .Cast <object>() .OrderBy(k => k) .Select(key => string.Format( _pairFormat, formattingService.FormatValue(key), formattingService.FormatValue(dictionary[key]))); return(string.Format(_containerFormat, string.Join(_separator, keyValues))); }
public override ExpectationResult Verify(T value, IValueFormattingService formattingService) { if (_predicateFn(value)) { return(ExpectationResult.Success); } return(FormatFailure(formattingService, $"got: '{formattingService.FormatValue(value)}'")); }
/// <summary> /// Sets the actual value and performs the validation against the expectation, updating <see cref="Status"/> property. /// The value specified by <paramref name="value"/> parameter can be retrieved by <see cref="GetActual"/> method. /// /// If actual value is already set, an exception is thrown. /// </summary> /// <param name="value">Value to set.</param> /// <returns>Self.</returns> /// <exception cref="InvalidOperationException">Thrown when actual value is already set.</exception> public Verifiable <T> SetActual(T value) { if (Status != ParameterVerificationStatus.NotProvided) { throw new InvalidOperationException("Actual value has been already specified"); } _exception = null; _actual = value; _actualText = _formattingService.FormatValue(value); _result = Expectation.Verify(value, _formattingService); return(this); }
public override ExpectationResult Verify(IEnumerable <T> collection, IValueFormattingService formattingService) { if (collection == null) { return(FormatFailure(formattingService, $"got: '{formattingService.FormatValue(null)}'")); } var details = new List <string>(); var i = 0; var actual = (collection).ToArray(); if (_expected.Length != actual.Length) { details.Add($"expected collection of {_expected.Length} item(s), but got one of {actual.Length} item(s)"); } foreach (var item in actual) { if (_expected.Length > i) { if (!Equals(_expected[i], item)) { details.Add($"[{i}]: expected: '{formattingService.FormatValue(_expected[i])}', but got: '{formattingService.FormatValue(item)}'"); } } else { details.Add($"[{i}]: surplus: '{formattingService.FormatValue(item)}'"); } ++i; } for (; i < _expected.Length; ++i) { details.Add($"[{i}]: missing: '{formattingService.FormatValue(_expected[i])}'"); } return(details.Any() ? FormatFailure(formattingService, $"got: '{formattingService.FormatValue(actual)}'", details) : ExpectationResult.Success); }
public override ExpectationResult Verify(IEnumerable <T> collection, IValueFormattingService formattingService) { if (collection == null) { return(FormatFailure(formattingService, $"got: '{formattingService.FormatValue(null)}'")); } var details = new List <string>(); var actual = collection.ToArray(); var remainingActual = actual.ToList(); if (_expected.Length != actual.Length) { details.Add($"expected collection of {_expected.Length} item(s), but got one of {actual.Length} item(s)"); } foreach (var value in _expected) { var index = remainingActual.IndexOf(value); if (index >= 0) { remainingActual.RemoveAt(index); } else { details.Add($"missing: '{formattingService.FormatValue(value)}'"); } } foreach (var value in remainingActual) { details.Add($"surplus: '{formattingService.FormatValue(value)}'"); } return(details.Any() ? FormatFailure(formattingService, $"got: '{formattingService.FormatValue(actual)}'", details) : ExpectationResult.Success); }
public override ExpectationResult Verify(T value, IValueFormattingService formattingService) { var details = new List <string>(); foreach (var expectation in _expectations) { var result = expectation.Verify(value, formattingService); if (result) { return(ExpectationResult.Success); } details.Add(result.Message); } return(FormatFailure(formattingService, $"got: '{formattingService.FormatValue(value)}'", details)); }
public override ExpectationResult Verify(IEnumerable <TValue> collection, IValueFormattingService formattingService) { List <string> errors = new List <string>(); int i = 0; foreach (var item in collection ?? Enumerable.Empty <TValue>()) { var result = _itemExpectation.Verify(item, formattingService); if (result) { return(ExpectationResult.Success); } errors.Add($"[{i++}]: {result.Message}"); } return(FormatFailure(formattingService, $"got: '{formattingService.FormatValue(collection)}'", errors)); }
/// <inheritdoc /> public string Format(IValueFormattingService formattingService) { return(HasValue ? formattingService.FormatValue(Value) : "<none>"); }
private ITabularParameterRow GetRow(TRow row, int index) { return(new TabularParameterRow(index, _columns.Select(x => _formattingService.FormatValue(x.GetValue(row))))); }
public override string Format(IValueFormattingService formattingService) { return($"equals collection '{formattingService.FormatValue(_expected)}'"); }
/// <summary> /// Formats provided <paramref name="value"/> as collection. /// </summary> public override string FormatValue(object value, IValueFormattingService formattingService) { return(string.Join(_separator, ((IEnumerable)value).Cast <object>().Select(o => string.Format(_valueFormat, formattingService.FormatValue(o))))); }