SetupSet() is obsolete. In place of what?

Solution 1:

I am using Moq version 3.0.204.1 and SetupSet does is not marked as obsolete for me. However, there are a couple of SetupSet overloads located in MockLegacyExtensions. You can avoid using those and use SetupSet that is defined on the Mock class.

The difference is subtle and you need to use Action<T> as SetupSet parameter, as opposed to Func<T, TProperty>.

The call below will invoke the non-deprecated overload:

myMock.SetupSet(p => p.MyProperty = It.IsAny<string>()).Callback<string>(value => myLocalVariable = value);

The trick is to use It.IsAny<string>, which will intercept a setter call with any value.