コード例 #1
0
        /// <summary>Compares by value.</summary>
        /// <param name="other">Instance to compare with.</param>
        /// <param name="valuer">Handles callback behavior for child values.</param>
        /// <returns>True if equal; false otherwise.</returns>
        public virtual bool ValuesEqual(object other, IValuer valuer)
        {
            if (valuer == null)
            {
                throw new ArgumentNullException(nameof(valuer));
            }

            return((other is ValuerEquatableSample sample) &&
                   valuer.Equals(StringValue, sample.StringValue) &&
                   valuer.Equals(NumberValue, sample.NumberValue));
        }
コード例 #2
0
        /// <inheritdoc/>
        public object Variant(Type type, object instance, params object[] extraInstances)
        {
            IEnumerable <object> values = (extraInstances ?? Enumerable.Empty <object>()).Prepend(instance);

            object result = default;

            try
            {
                _limiter.StallUntil(
                    () => result = _randomizer.Create(type),
                    () => values.All(o => !_valuer.Equals(result, o))).Wait();
            }
            catch (AggregateException e)
            {
                throw new TimeoutException($"Could not create different instance of type '{type}'.", e);
            }
            return(result);
        }
コード例 #3
0
        /// <summary>Determines if the call args match the expected ones.</summary>
        /// <param name="inputArgs">Args used in the call.</param>
        /// <returns>True if matched; false otherwise.</returns>
        private bool ArgsMatch(object[] inputArgs)
        {
            bool matches = (inputArgs.Length == _args.Length);

            for (int i = 0; matches && i < inputArgs.Length; i++)
            {
                if (_args[i] is Arg exp)
                {
                    matches &= exp.Matches(inputArgs[i]);
                }
                else if (_valuer != null)
                {
                    matches &= _valuer.Equals(inputArgs[i], _args[i]);
                }
                else
                {
                    matches &= Equals(inputArgs[i], _args[i]);
                }
            }
            return(matches);
        }