/// <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); }
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)); }
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)); }
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); }