예제 #1
0
 /// <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;
 }
예제 #2
0
 /// <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);
 }
예제 #3
0
 public override ExpectationResult Verify(T value, IValueFormattingService formattingService)
 {
     if (_predicateFn(value))
     {
         return(ExpectationResult.Success);
     }
     return(FormatFailure(formattingService, $"got: '{formattingService.FormatValue(value)}'"));
 }
예제 #4
0
 /// <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);
 }
예제 #5
0
 public override ExpectationResult Verify(T value, IValueFormattingService formattingService)
 {
     if (!_expectation.Verify(value, formattingService))
     {
         return(ExpectationResult.Success);
     }
     return(FormatFailure(formattingService, "it was"));
 }
예제 #6
0
        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}'"));
        }
예제 #7
0
 public MethodArgument(ParameterDescriptor descriptor, IValueFormattingService formattingService)
 {
     _formattingService = formattingService;
     RawName            = descriptor.RawName;
     _valueEvaluator    = descriptor.ValueEvaluator;
     if (descriptor.IsConstant)
     {
         Evaluate(null);
     }
 }
예제 #8
0
        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));
        }
예제 #9
0
        /// <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()));
        }
예제 #10
0
        /// <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)));
        }
예제 #11
0
        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));
        }
예제 #12
0
        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));
        }
예제 #13
0
        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);
        }
예제 #14
0
        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);
        }
예제 #15
0
 public void SetValueFormattingService(IValueFormattingService formattingService)
 {
 }
예제 #16
0
 /// <inheritdoc />
 public string Format(IValueFormattingService formattingService)
 {
     return(HasValue ? formattingService.FormatValue(Value) : "<none>");
 }
예제 #17
0
 public override string Format(IValueFormattingService formattingService)
 {
     return(_descriptionFn(formattingService));
 }
예제 #18
0
#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));
        }
예제 #19
0
 public override string Format(IValueFormattingService formattingService)
 {
     return("any item " + _itemExpectation.Format(formattingService));
 }
예제 #20
0
        public string FormatValue(object value, IValueFormattingService formattingService)
        {
            var asset = (Asset)value;

            return($"Asset. Name: {asset.Name}, amount: {asset.Amount}");
        }
예제 #21
0
 /// <summary>
 /// Returns inline representation of table.
 /// </summary>
 public string Format(IValueFormattingService formattingService)
 {
     return("<table>");
 }
예제 #22
0
 void IComplexParameter.SetValueFormattingService(IValueFormattingService formattingService)
 {
     _formattingService = formattingService;
 }
예제 #23
0
 public override string Format(IValueFormattingService formattingService)
 {
     return($"{_prefix}({string.Join(" and ", _expectations.Select(x => x.Format(formattingService)))})");
 }
예제 #24
0
 /// <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");
 }
예제 #26
0
 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));
 }
예제 #28
0
 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);