Last active
December 21, 2015 10:59
-
-
Save stephen-james/6296221 to your computer and use it in GitHub Desktop.
using Moq and Asserts on a saved object (saved via callback) after call, allows for nice seperation of Arrange,Act,Assert! from http://stackoverflow.com/questions/4956974/verifying-an-specific-parameter-with-moq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Arrange | |
MyObject saveObject; | |
mock.Setup(c => c.Method(It.IsAny<int>(), It.IsAny<MyObject>())) | |
.Callback<int, MyObject>((i, obj) => saveObject = obj) | |
.Returns("xyzzy"); | |
// Act | |
// ... | |
// Assert | |
// Verify Method was called once only | |
mock.Verify(c => c.Method(It.IsAny<int>(), It.IsAny<MyObject>()), Times.Once()); | |
// Assert stuff about saveObject | |
Assert.That(saveObject.TheProperty, Is.EqualTo(2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment