1

I have to use a specific constructor with auto fixture customization. The application logic requires to change the temperature unit through the constructor. Otherwise the temperature values will be converted and i can't determine the minimum temperature. Is it possible to modify the used constructor parameter?

Update

This seems to be a work around for me:

var tempUnit = new Fixture().Create<TemperatureUnit>();
var temperatureFixture = new Fixture();
//... 
temperatureFixture.Customizations.Add(new RandomNumericSequenceGenerator(Convert.ToInt64(GetMinTemperatureForUnit(tempUnit)), long.MaxValue));   

//workaround to force autofixture to create weather with unit
weatherFixture.Register<TemperatureUnit>(() => tempUnit);
weatherFixture.Customize<Weather>(weather => weather.FromFactory(new MethodInvoker(new GreedyConstructorQuery()))
            .With(x => x.Temperature, temperatureFixture.Create<double>())
            .Without(x => x.TempUnit)
Community
  • 1
  • 1
  • 1
    This is most likely a duplicate, but I can't quite divine from the question exactly what the scenario is, so I'll start with suggesting this one: http://stackoverflow.com/q/28603831/126014 – Mark Seemann Nov 15 '16 at 19:01
  • My problem description was unclear, I edited the question –  Nov 16 '16 at 13:23
  • 1
    It's not clear what the question is. Could you share a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve)? – Mark Seemann Nov 16 '16 at 14:04

0 Answers0