Esempio n. 1
0
        /// <summary>
        /// Creates a new specimen based on a requested range.
        /// </summary>
        /// <param name="request">The request that describes what to create.</param>
        /// <param name="context">A container that can be used to create other specimens.</param>
        /// <returns>
        /// A specimen created from a <see cref="RangedRequest"/> encapsulating the operand
        /// type, the minimum and the maximum of the requested value, if possible; otherwise,
        /// a <see cref="NoSpecimen"/> instance.
        /// </returns>
        public object Create(object request, ISpecimenContext context)
        {
            if (request == null)
            {
                return(new NoSpecimen());
            }

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var rangeAttribute = TypeEnvy.GetAttribute <RangeAttribute>(request);

            if (rangeAttribute == null)
            {
                return(new NoSpecimen());
            }

            var memberType    = GetMemberType(rangeAttribute, request);
            var rangedRequest =
                new RangedRequest(
                    memberType,
                    rangeAttribute.OperandType,
                    rangeAttribute.Minimum,
                    rangeAttribute.Maximum);

            return(context.Resolve(rangedRequest));
        }
Esempio n. 2
0
 private static TimeSpanRange ParseTimeSpanRange(RangedRequest rangedRequest)
 {
     return(new TimeSpanRange
     {
         Min = TimeSpan.Parse((string)rangedRequest.Minimum, CultureInfo.CurrentCulture),
         Max = TimeSpan.Parse((string)rangedRequest.Maximum, CultureInfo.CurrentCulture)
     });
 }
Esempio n. 3
0
        private static object CreateRangedTimeSpanSpecimen(RangedRequest rangedRequest, ISpecimenContext context)
        {
            if (!(rangedRequest.Minimum is string) || !(rangedRequest.Maximum is string))
            {
                return(new NoSpecimen());
            }

            var range = ParseTimeSpanRange(rangedRequest);

            return(RandomizeTimeSpanInRange(range, context));
        }