A class with a nested collection - how can I populate a nested class?

I'm a little confused to remove a class with a nested collection of another class. I get an error message:

AutoFixture failed to create an instance from System.Collections.Generic.IList`1 [typename ...]

I tried using Fixture.Register() to register the type to populate the inner class. I could just do with a sample that shows

  • Main class
  • A nested collection (IList / IEnumerable) of another class.

I also noticed that Register() marked obsolete, but there is no documentation on the Inject() method in CodePlex, so I donโ€™t understand how this should work.

+4
source share
1 answer

AutoFixture makes no assumptions about how to instantiate interfaces, but you can pretty easily resolve the behavior you're looking for . for integers:

 fixture.Register(() => fixture.CreateMany<int>()); 

In the upcoming AutoFixture 2.1, you can also just enable conventions for different collections with a single method call:

 var fixture = new Fixture().Customize(new MultipleCustomization()); 

Regarding deprecation of the Register method, note that this is only one overload of the Register method, which is marked as deprecated. The Inject method is a direct replacement - it has the same signature and usage, just a different name. All other Registry overloads are not obsolete and should be used as โ€œdocumentedโ€.

+4
source

Source: https://habr.com/ru/post/1345529/


All Articles