Skip to content

Instantly share code, notes, and snippets.

@GraemeF
Created February 10, 2011 12:25
Show Gist options
  • Save GraemeF/820437 to your computer and use it in GitHub Desktop.
Save GraemeF/820437 to your computer and use it in GitHub Desktop.
How can I check that "_log.Offset = newOffset" happened?
Fake.GetCalls(_log).
Single(call => call.Method.Name == "set_Offset").
GetArgument<TimeSpan>(0).
Should().Equal(newOffset);
@GraemeF
Copy link
Author

GraemeF commented Feb 10, 2011

Looking for the equivalent to Moq:
Mock.Get(_log).VerifySet(x => x.Offset = newOffset);

and NSubstitute:
_log.Received().Offset = newOffset;

@GraemeF
Copy link
Author

GraemeF commented Feb 10, 2011

My attempt above was based on this issue report: http://code.google.com/p/fakeiteasy/issues/detail?id=14 (although my property has a getter too).

@patrik-hagne
Copy link

This should do what you want:

NextCall.To(_log).MustHaveHappened(Repeated.Once.Exactly);
_log.Offset = newOffset;

However, I'm slightly opinionated in this case and I would argue that in general it would be better to just check the value of the property (in NUnit):

Assert.That(_log.Offset, Is.EqualTo(newOffset));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment