/// <summary> /// Constructor. /// </summary> /// <param name="context">Integration context.</param> protected FeatureCoordinator(IntegrationContext context) { Configuration = context.Configuration; _featureAggregator = new FeatureReportGenerator(Configuration.ReportWritersConfiguration().ToArray()); RunnerRepository = new FeatureRunnerRepository(context); ValueFormattingService = context.ValueFormattingService; }
/// <summary> /// Constructor. /// </summary> /// <param name="runnerRepository">Runner factory instance that would be used for instantiating runners.</param> /// <param name="featureAggregator">Feature aggregator instance used for aggregating feature results on coordinator disposal.</param> /// <param name="configuration"><see cref="LightBddConfiguration"/> instance used to initialize LightBDD tests.</param> protected FeatureCoordinator(FeatureRunnerRepository runnerRepository, IFeatureAggregator featureAggregator, LightBddConfiguration configuration) { _featureAggregator = featureAggregator; RunnerRepository = runnerRepository; Configuration = configuration; //TODO: Rework in LightBDD 3.X to use the same instance as CoreMetadataProvider (introduce IoC?) ValueFormattingService = new ValueFormattingService(Configuration); }
public override ExpectationResult Verify(T value, IValueFormattingService formattingService) { if (_predicateFn(value)) { return(ExpectationResult.Success); } return(FormatFailure(formattingService, $"got: '{formattingService.FormatValue(value)}'")); }
/// <summary> /// Formats provided <paramref name="value"/> as boolean. /// </summary> public override string FormatValue(object value, IValueFormattingService formattingService) { if (value == null) { throw new ArgumentNullException(nameof(value)); } return((bool)value ? _trueValue : _falseValue); }
public override ExpectationResult Verify(T value, IValueFormattingService formattingService) { if (!_expectation.Verify(value, formattingService)) { return(ExpectationResult.Success); } return(FormatFailure(formattingService, "it was")); }
public override ExpectationResult Verify(TBase value, IValueFormattingService formattingService) { if (value == null || value is TDerived) { return(_expectation.Verify((TDerived)value, formattingService)); } return(ExpectationResult.Failure($"value of type '{value.GetType().Name}' cannot be cast to '{typeof(TDerived).Name}'")); }
public MethodArgument(ParameterDescriptor descriptor, IValueFormattingService formattingService) { _formattingService = formattingService; RawName = descriptor.RawName; _valueEvaluator = descriptor.ValueEvaluator; if (descriptor.IsConstant) { Evaluate(null); } }
private string FormatValue(object value, IValueFormattingService formattingService) { if (value == null) { return(FormatSymbols.Instance.NullValue); } var valueFormatter = _formatters.GetOrAdd(value.GetType(), LookupFormatter); return(valueFormatter.FormatValue(value, formattingService)); }
/// <summary> /// A helper methods used to format failure message for the expectation. /// It allows to format a default format failure message and add details in new line, shifted with tabulator character /// </summary> /// <param name="formattingService">Formatting service.</param> /// <param name="failureMessage">Failure message</param> /// <param name="details">Failure details that will be added to the message in new line, shifted with tabulator character.</param> /// <returns>Expectation result.</returns> protected ExpectationResult FormatFailure(IValueFormattingService formattingService, string failureMessage, IEnumerable <string> details) { var builder = new StringBuilder(); builder.Append("expected: ").Append(Format(formattingService)).Append(", but ").Append(failureMessage); foreach (var line in details) { builder.AppendLine().Append('\t').Append(line.Replace(Environment.NewLine, Environment.NewLine + "\t")); } return(ExpectationResult.Failure(builder.ToString())); }
/// <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) { 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)); }
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 void SetValueFormattingService(IValueFormattingService formattingService) { }
/// <inheritdoc /> public string Format(IValueFormattingService formattingService) { return(HasValue ? formattingService.FormatValue(Value) : "<none>"); }
public override string Format(IValueFormattingService formattingService) { return(_descriptionFn(formattingService)); }
#pragma warning disable 618 /// <summary> /// Formats provided <paramref name="value"/> and returns it's string representation. /// The provided <paramref name="formattingService"/> can be used to obtain current <see cref="CultureInfo"/> if needed. It can be also used to format inner values if formatted type is collection or complex object. /// /// By default, this method calls <see cref="Format"/>() for backward-compatibility and it should be overwritten by types extending <see cref="ParameterFormatterAttribute"/>. /// </summary> /// <param name="value">Value to format.</param> /// <param name="formattingService">Formatting service allowing to retrieve current <see cref="CultureInfo"/> or format inner values of provided object.</param> /// <returns>Formatted value.</returns> public virtual string FormatValue(object value, IValueFormattingService formattingService) { return(Format(formattingService.GetCultureInfo(), value)); }
public override string Format(IValueFormattingService formattingService) { return("any item " + _itemExpectation.Format(formattingService)); }
public string FormatValue(object value, IValueFormattingService formattingService) { var asset = (Asset)value; return($"Asset. Name: {asset.Name}, amount: {asset.Amount}"); }
/// <summary> /// Returns inline representation of table. /// </summary> public string Format(IValueFormattingService formattingService) { return("<table>"); }
void IComplexParameter.SetValueFormattingService(IValueFormattingService formattingService) { _formattingService = formattingService; }
public override string Format(IValueFormattingService formattingService) { return($"{_prefix}({string.Join(" and ", _expectations.Select(x => x.Format(formattingService)))})"); }
/// <summary> /// Formats <paramref name="value"/> as collection. /// </summary> public string FormatValue(object value, IValueFormattingService formattingService) { return(string.Format(_containerFormat, string.Join(_separator, ((IEnumerable)value).Cast <object>().Select(formattingService.FormatValue)))); }
public string Format(IValueFormattingService formattingService) { return("my3"); }
public override string Format(IValueFormattingService formattingService) { return("not " + _expectation.Format(formattingService)); }
public string FormatValue(object value, IValueFormattingService formattingService) { return(string.Format(formattingService.GetCultureInfo(), "s{0}", value)); }
public override string Format(IValueFormattingService formattingService) { return($"equals collection '{formattingService.FormatValue(_expected)}'"); }
public override string FormatValue(object value, IValueFormattingService formattingService) { return(string.Format(formattingService.GetCultureInfo(), "--{0}--", value)); }
/// <summary> /// Formats provided <paramref name="value"/> and returns it's string representation. /// The provided <paramref name="formattingService"/> can be used to obtain current <see cref="CultureInfo"/> if needed. It can be also used to format inner values if formatted type is collection or complex object. /// </summary> /// <param name="value">Value to format.</param> /// <param name="formattingService">Formatting service allowing to retrieve current <see cref="CultureInfo"/> or format inner values of provided object.</param> /// <returns>Formatted value.</returns> public abstract string FormatValue(object value, IValueFormattingService formattingService);