IList <something> and AutoFixture Constructor Parameter
Using autofixture , I am trying to build an anonymous instance Project:
_f=new Fixture().Customize(new AutoMoqCustomization());
_p=_f.CreateAnonymous<Project>();
It fails, the constructor is called Project IList<Partner>
public Project(/*.....*/,IList<Partner> partners){
Guard.AgainstEmpty(partners);
}
Stack tracing doesn't make sense (at least for me). Just some reflection of the poison:
failed: System.Reflection.TargetInvocationException: An exception was thrown by the target of the call.
---- System.ArgumentException: value is not in the expected range.
in System.RuntimeMethodHandle._InvokeConstructor (IRuntimeMethodInfo method, Object [] args, SignatureStruct & signature, RuntimeType declaringType)
So, how do you make sure autoFixture allows an anonymous collection of partners to create it?
IList<Partners>. Priority. Priority Measure, Measure IList<Indicator> Guard.AgainstEmpty(indicators) .
, :
fixture.CreateAnonymous<Foo>(); //kaboom!
public class Foo{
public Foo(IList<Bar> bars){
Guard.AgainstEmpty(bars); //just checks count for ienumerable & throws if 0
Bars=bars;
}
public IList<Bar> Bars {get;private set;} //should be readonly collection...
}
public class Fizz{
public Fizz(Foo foo){
Foo=foo;
}
public Foo{get;private set;}
}
public class Bar{}
Guard.AgainstEmpty. - - , AutoFixture foos?
. source .
var indicators=_f.CreateMany<Indicator>();
_f.Register<IList<Indicator>>(()=>indicators.ToList());
.
, :
_f=new Fixture().Customize(new AutoMoqCustomization());
var indicators=_f.CreateMany<Indicator>();
_f.Register<IList<Indicator>>(()=>indicators.ToList());
var regionName=_f.CreateAnonymous<string>();
_f.Register<string,Country,bool,Region>((name,country,call)=>
new Region(regionName,_f.CreateAnonymous<Country>(),true));
_c.Set(x=>x.Regions,_f.CreateMany<Region>().ToList());
_f.Register<IList<ManagementBoardEntry>>(()=>
_f.CreateMany<ManagementBoardEntry>().ToList());
_f.Register<IList<FinancialInfoEntry>>(()=>
_f.CreateMany<FinancialInfoEntry>().ToList());
_f.Register<IList<Partner>>(()=>_f.CreateMany<Partner>().ToList());
_p=_f.CreateAnonymous<Project>();
( ), , .
IList, . - IList . , , .
params . ( ). ( Excel DOM), , .
. ( , , - ).
, . , TDD. , , . , . , .
- . AutoFixture.