Backing store difficult to use with AutoFixture
Would be nicer for writing tests to have some fluent syntax for setting up tests:
Right now, I have to write:
var component = Fixture.Build<Component>()
.Without(x => x.WeightingValue)
.Do(x => x.Weighting = null)
.Do(x => x.WeightingValueSpecified = false)
.Without(x => x.Weighting)
.Without(x => x.WeightingValueSpecified)
.Create();
I wish I could just write:
var component = Fixture.Build<Component>()
.Do(x => x.Weighting = null)
.Without(x => x.Weighting)
.Create();
I thought about creating this issue two weeks ago, but rested on it - now that I'm back from vacation, I see this tripped me up again.
As one suggestion, there could be an ISpecimenBuilder that intercepts the request and checks for [System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.0.0.0")] on the requested type. If it is there, it gathers all properties and looks for ones with XmlIgnoredAttribute that implement Nullable<T> or a reference type. It should only populate these properties, I believe.
Where do you see this fit into XmlSchemaClassGenerator? AFAICT the ISpecimenBuilder implementation would a generic class that can be applied to all generated classes. So perhaps this could be a separate package that you can install into the project where you use AutoFixture with the code that's generated by XmlSchemaClassGenerator?
I think there is a fixed set of constraints that work well with Xml serialization and XmlSchemaClassGenerator that probably don't work for other, random "generated classes".
It makes sense to ship as part of XmlSchemaClassGenerator such that the sln contains a separate nuget package XmlSchemaClasGenerator.TestHelpers that people can easily plug-in to AutoFixture. If something changes in how XmlSchemaClassGenerator generates types, the unit tests in the sln would detect those contract breaks, and require fixing the SpecimenBuilder.
Sounds good. Would be great if you could provide a PR.