AutoFixture/AutoFixture — pull request #314 by dcastro (2014-10-04 08:01:57+00:00)
Title: Stub moq properties

At the moment, AutoMoq configures a property' getter, but not its setter.
I think it would be a good idea to "stub" properties, to make them behave as normal properties. I believe this is a pretty common use case, so much so that @ploeh wrote an [article][0] about this.

To illustrate the behaviour I'm referring to:

```csharp
var sut = fixture.Create();
sut.Property = "Hello";
Assert.Equal("Hello", sut.Property);
```

My first thought was to simply use moq's `SetupProperty`, but I realized that the property's initial value would then have to be evaluated eagerly. This would break users' current expectations *and* the test suite (particularly, the `CircularDependenciesAreAllowed` integration test).

So I came up with a way to stub a property whilst generating its initial value lazily. In fact, if the property's setter is called before the getter, then the `context` will never be asked to resolve a value at all.

```csharp
var lazy = new Lazy(() => (string) context.Resolve(typeof (string)));

mock.SetupGet(x => x.Property)
.Returns(() => lazy.Value);

mock.SetupSet(x => x.Property = It.IsAny())
.Callback(value => lazy = new Lazy(() => value));
```

[0]: http://blog.ploeh.dk/2013/04/05/how-to-configure-automoq-to-set-up-all-properties/