-
|
For really large object graphs with lots of top-level properties, where I only care about about one path through the object graph, it would be nice to write this: Fixture.Build<Foo>(omitAutoProperties: true)
.With(s => s.PropertyICareAbout, Fixture.Create<PropertyICareAbout>())
.Create();The advantage is that the omission is scoped to the Build command, so the context is captured under which auto-properties should be omitted. I don't like writing this, since it mutates global state and doesn't tie that mutation to a particular reason: Fixture.OmitAutoProperties = true;
Fixture.Build<Foo>()
.With(s => s.PropertyICareAbout, Fixture.Create<PropertyICareAbout>())
.Create();
Fixture.OmitAutoProperties = false;I actually have been using AutoFixture for about 4 years and never realized what auto properties were, until I read #222 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
@jzabroski this functionality is already present in AutoFixture. It is enabled via the [Fact]
public void Foo()
{
var fixture = new Fixture();
var person = fixture.Build<Person>()
.OmitAutoProperties()
.With(x => x.Photo, fixture.Create<Photo>())
.Create();
Assert.NotNull(person.Photo);
Assert.Null(person.FirstName);
}You can also selectively omit specific properties using the |
Beta Was this translation helpful? Give feedback.
@jzabroski this functionality is already present in AutoFixture. It is enabled via the
OmitAutoProperties()method of theIPostprocessComposer<T>.You can also selectively omit specific properties using the
.Without()method while usingBuild<T>().