I have a class that takes two parameters, as shown:
public double X { get; private set; }
public double Y { get; private set; }
public Point(double x, double y)
{
if (x > 90 || x < -90)
throw new ArgumentOutOfRangeException("latitude");
if (y > 180 || y < -180)
throw new ArgumentOutOfRangeException("longitude");
X = x;
Y = y;
}
The corresponding properties are set in the constructor, so I need to tell AutoFixture to create a Point class with parameters in the range specified in the guard clauses. I managed to confuse the use of the RandomRangedNumberCustomization class a bit. I have done the following:
var xRange = new RangedNumberRequest(typeof(double), -90.0, 90.0);
var yRange = new RangedNumberRequest(typeof (double), -180.0, 180.0);
var dummyContext = new DelegatingSpecimenContext();
var generator = new RandomRangedNumberGenerator();
var x = (double)generator.Create(latitudeRange, dummyContext);
var y = (double) generator.Create(longitudeRange, dummyContext);
which will generate numbers in my range, so I could just create a point and feed in these generated numbers, but I am missing something in terms of customization. Any help and / or guidance would be greatly appreciated.
Thank!
source
share