Closed j-fritsch closed 4 years ago
Hi.
The fact that the property is writable should mean you shouldn't go down that generation path. I will take a look and push out a fix.
Nick.
Thanks, Nick!
Hey @j-fritsch
I have made a change and pushed v2.7.2. It now generates ISet<>
types through a dedicated generator.
In theory you should have not been seeing that error as you have provided a RuleFor()
for that property. My investigation has showed that the generation process could be optimized, so this is a great catch.
Thanks. Nick.
Glad to hear it! Thank you for the quick response, I appreciate it!
@nickdodd79, looks like IReadOnlyDictionary
types aren't working on v2.7.2. Appears to have stopped working as of v2.7.0 as well.
public class MyClass
{
public IReadOnlyDictionary<int, string> MyDictionary { get; set; }
}
var dictionary = new Dictionary<int, string>
{
{ 1, "value1" },
{ 2, "value2" }
};
var faker = new AutoFaker<MyClass>()
.RuleFor(o => o.MyDictionary, f => dictionary);
var fakes = faker.Generate();
I'm getting this exception:
Unhandled exception. System.InvalidOperationException: Sequence contains more than one element
at System.Linq.ThrowHelper.ThrowMoreThanOneElementException()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at AutoBogus.AutoGeneratorFactory.ResolveGenerator(AutoGenerateContext context)
at AutoBogus.AutoGeneratorFactory.GetGenerator(AutoGenerateContext context)
at AutoBogus.AutoBinder.PopulateInstance[TType](Object instance, AutoGenerateContext context, IEnumerable`1 members)
at AutoBogus.Generators.TypeGenerator`1.AutoBogus.IAutoGenerator.Generate(AutoGenerateContext context)
at AutoBogus.AutoFaker`1.<>c__DisplayClass30_0.<PrepareCreate>b__0(Faker faker)
at Bogus.Faker`1.Generate(String ruleSets)
at AutoBogus.AutoFaker`1.Generate(String ruleSets)
at ConsoleApp1.Program.Main(String[] args) in /ConsoleApp1/ConsoleApp1/Program.cs:line 26
Hey @j-fritsch
You have become the unofficial QA for the project š
I will take a look and get fix out. Also thinking I'm gonna add some more tests around all the different collection types, as they have their own paths through the generation process and need to the sanity checking.
Nick.
š
Thanks, @nickdodd79! I just happened to be updating the dependencies in the project I am working on. Glad I can help.
Hey @j-fritsch
I just pushed v2.7.3 which adds a new generator for the IReadOnlyDictionary
type.
Nick.
All my tests are passing again. Thanks again, @nickdodd79, I appreciate the quick responses!
Starting in v2.7.0, I'm getting a list conversion error when setting an
ISet
property with aHashSet
populated via anIList
within a rule. This is not happening in v2.6.0.The generation throws the conversion error.