Last active
August 29, 2015 14:15
-
-
Save johnmmoss/8ed74a2fdc63807518f9 to your computer and use it in GitHub Desktop.
Example Rhino Mock Asserts
This file contains hidden or 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
public void RhinoMockExampleAsserts() | |
{ | |
// Example assert _principal.IsInRole(..) wasn't called | |
_principal.AssertWasNotCalled(x => x.IsInRole(Arg<string>.Is.Anything)) | |
// Assert API call was made | |
_apiClient.AssertWasCalled(x => x.GetCustomerStatement(Arg<int>.Is.Anything)); | |
// Assert API call was made with a specific ID | |
_apiClient.AssertWasCalled(x => x.GetCustomerStatement(Arg<int>.Is.Equal(200)); | |
// Was called 3 times | |
_principal.AssertWasCalled(x => x.IsInRole(Arg<string>.Is.Anything), x => x.Repeat.Times(3)); | |
// Was called once | |
_principal.AssertWasCalled(x => x.IsInRole(Arg<string>.Is.Equal(usersGroup)), x => x.Repeat.Once()); | |
// Accessing parameters from a called method using Rhino Mock | |
// _sessionTokenWriter.WriteSessionTokenToCookie(ClaimsPrincipal cp) | |
var mockArgs = _mockSessionTokenWriter | |
.GetArgumentsForCallsMadeOn( | |
x => x.WriteSessionTokenToCookie(Arg<ClaimsPrincipal>.Is.Anything), | |
x => x.IgnoreArguments()); // setupConstraints(?) is of type Action<IMethodOptions<object>> | |
// mockArgs is IList<object[]> a list of arrays. | |
// Where mock[i][n] where i is number of calls? And n is the nth parameter in that call? | |
var claims = (mockArgs[0][0] as ClaimsPrincipal).Claims; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment