Ejemplo n.º 1
0
 /// <summary>
 /// Override model nullable double property.
 /// </summary>
 /// <param name="expression">The expression.</param>
 /// <param name="min">The minimum.</param>
 /// <param name="max">The maximum.</param>
 /// <returns>Returns this.</returns>
 public IAutoBuilderOverrides <TModel> With(
     Expression <Func <TModel, double?> > expression,
     double min,
     double max)
 {
     this.Actions.Add(() => SetDoublePropertyUsingNewRandomizerSetting(() => NAuto.GetRandomDouble(min, max), expression));
     return(this);
 }
Ejemplo n.º 2
0
        private decimal GetDecimalValue(string propertyName)
        {
            if (AutoBuilderConfiguration.Conventions.MatchesConvention(propertyName, typeof(decimal)))
            {
                return((decimal)AutoBuilderConfiguration.Conventions.GetConventionResult(propertyName, typeof(decimal), AutoBuilderConfiguration));
            }

            return((decimal)NAuto.GetRandomDouble(AutoBuilderConfiguration.DoubleMinimum, AutoBuilderConfiguration.DoubleMaximum));
        }
Ejemplo n.º 3
0
        private static double GenerateRandomDoubleFromDataAnnotations(PropertyInfo propertyInfo, AutoBuilderConfiguration autoBuilderConfiguration)
        {
            var min = autoBuilderConfiguration.DoubleMinimum;
            var max = autoBuilderConfiguration.DoubleMaximum;

            var rangeAttribute = propertyInfo.GetCustomAttributes(typeof(RangeAttribute), false).FirstOrDefault();

            if (rangeAttribute != null)
            {
                min = double.Parse(((RangeAttribute)rangeAttribute).Minimum.ToString());
                max = double.Parse(((RangeAttribute)rangeAttribute).Maximum.ToString());
            }

            return(NAuto.GetRandomDouble(min, max));
        }
        private double?GetDoubleValue(string propertyName, PropertyInfo propertyInfo)
        {
            if (AutoBuilderConfiguration.Conventions.MatchesConvention(propertyName, typeof(double?)))
            {
                return((double?)AutoBuilderConfiguration.Conventions.GetConventionResult(propertyName, typeof(double?), AutoBuilderConfiguration));
            }

            var annotatedType = dataAnnotationConventionMapper.TryGetValue(typeof(double), propertyInfo, AutoBuilderConfiguration);

            if (annotatedType != null)
            {
                return((double)annotatedType);
            }

            return(NAuto.GetRandomDouble(AutoBuilderConfiguration.DoubleMinimum, AutoBuilderConfiguration.DoubleMaximum));
        }
Ejemplo n.º 5
0
        public void Should_Return_A_Random_Double_Which_Is_Between_Min_And_Max()
        {
            // Arrange
            const double min = 123456.123456;
            const double max = 456789.789456;

            // Act
            var result1 = NAuto.GetRandomDouble(min, max);
            var result2 = NAuto.GetRandomDouble(min, max);

            // Assert
            result1.ShouldNotEqual(result2);
            result1.ShouldBeGreaterThanOrEqualTo(min);
            result1.ShouldBeLessThanOrEqualTo(max);
            result2.ShouldBeGreaterThanOrEqualTo(min);
            result2.ShouldBeLessThanOrEqualTo(max);
        }