New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for value types with default constructors #19
Comments
Possibly related: The ability to set the value of individual properties on an immutable type where all setters are private. //This will result in a compile error because of inaccessible setter
//If the "newValue" was injected through the constructor this would work
var x = fixture.Build<MyImmutableClass>()
.With(v => v.MyReadonlyPropery = "newValue")
.CreateAnonymous(); |
I am trying to implement this one. Implementing checking for custom structs without constructors went well. However I have issues with allowing for that unsupported operation. Initial code can be found here: Short description goes as follows: I've created two classes: Generator creates structure itself so it is fine however I would have to pass it to fill all properties. To do this ideally my generator would have to land somewhere before Postprocessor with AutoPropertiesTarget. Any advices how to proceed? |
The Auto-Properties feature is implemented by composing fixture.Customizations.Add(
new Postprocessor(
new SupportStructureDefaultConstructorsGenerator(),
new AutoPropertiesCommand()); You may need to use the |
Available in AutoFixture 3.2.0. |
AutoFixture should optionally support value types with default constructors. See this discussion for more details.
Since I believe in the GOOS paradigm, I think it's a beneficial feature that AutoFixture OOB chokes on such constructs, but we should consider elaborating on this potential issue in the error message. E.g. instead of saying
we should consider adding more information - e.g.
This would obviously also require us to add said SupportValueTypeDefaultConstructors customization to the AutoFixture code base.
The text was updated successfully, but these errors were encountered: