I recently encountered a requirement whereby I had to set the value for a property that had a private setter in my Mock objects.
Fortunately, Moq has a solution for this!
You can use the .SetupGet method to set a private property as follows:
If you want to read more about how to accomplish things using Moq, you can read the QuickStart and API Docs here:
https://github.com/Moq/moq4/wiki/Quickstart
http://www.nudoq.org/#!/Packages/Moq/Moq/Mock(T)/M/SetupGet(TProperty)
Fortunately, Moq has a solution for this!
You can use the .SetupGet method to set a private property as follows:
myMock.SetupGet(m => m.MyPrivateSetter).Returns(myValue);
If you want to read more about how to accomplish things using Moq, you can read the QuickStart and API Docs here:
https://github.com/Moq/moq4/wiki/Quickstart
http://www.nudoq.org/#!/Packages/Moq/Moq/Mock(T)/M/SetupGet(TProperty)
No comments:
Post a Comment