예제 #1
0
        /// <summary>
        /// Retrieves a list of arguments which can be passed to the specified parameter.
        /// </summary>
        /// <param name="fixtureType">The point of context in the fixture’s inheritance hierarchy.</param>
        /// <param name="parameter">The parameter of a parameterized test.</param>
        public IEnumerable GetData(Type fixtureType, ParameterInfo parameter)
        {
            var from = ParamAttributeTypeConversions.Convert(_from, parameter.ParameterType);
            var to   = ParamAttributeTypeConversions.Convert(_to, parameter.ParameterType);

            var valueGenerator = ValueGenerator.Create(parameter.ParameterType);

            ValueGenerator.Step step;
            if (!valueGenerator.TryCreateStep(_step, out step))
            {
                // ValueGenerator.CreateStep has the responsibility to enable Byte values to be incremented
                // by the Int32 value -1. Or perhaps in the future, DateTime values to be incremented by a TimeSpan.
                // It handles scenarios where the incrementing type is fundamentally different in its most natural form.

                // However, ParamAttributeTypeConversions has the responsibility to convert attribute arguments
                // that are only of a different type due to IL limitations or NUnit smoothing over overload differences.
                // See the XML docs for the ParamAttributeTypeConversions class.

                object stepValueToRequire;
                if (!ParamAttributeTypeConversions.TryConvert(_step, parameter.ParameterType, out stepValueToRequire))
                {
                    // This will cause CreateStep to throw the same exception as it would throw if TryConvert
                    // succeeded but the value generator still didn’t recognize the step value.
                    stepValueToRequire = _step;
                }

                step = valueGenerator.CreateStep(stepValueToRequire);
            }

            return(valueGenerator.GenerateRange(from, to, step));
        }