This is due to an error introduced in Moq 4.2.1502.911, where SetupAllProperties overrides previous settings made using get-only properties.
Here's a simpler reprogramming:
public interface Interface { string Property { get; } } var a = new Mock<Interface>(); a.Setup(x => x.Property).Returns("test"); a.SetupAllProperties(); Assert.NotNull(a.Object.Property);
This is what AutoFixture does behind the scenes to create an instance of Interface . This test fails with Moq versions equal to or greater than 4.2.1502.911, but passes with lower versions.
Just run this in the package manager console:
install-package Moq -version 4.2.1409.1722
This error is tracked here: https://github.com/Moq/moq4/issues/196
source share