Skip to content

Instantly share code, notes, and snippets.

@stephen-james
Last active December 21, 2015 10:59
Show Gist options
  • Save stephen-james/6296221 to your computer and use it in GitHub Desktop.
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
// 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