Discussion:
Can you AssertWasNotCalled and also IgnoreArguments()?
Hegg
2010-02-17 21:02:48 UTC
Permalink
Greetings,

I have been building some tests and thought I'd try out the new
"AssertWasNotCalled" extension method. It seems to work as I'd expect
on methods with no parameters, but when I have a method with a
parameter, I can't seem to find a way to have it ignore those
parameters - that is, I want to assert that a specific method was
never called with any parameter ever.

For example, I'm using a interface which has a .List() method and
a .Delete(string name) method. Using the AAA style syntax, my test
uses AssertWasCalled(x => x.List()) and then attempts to
AssertWasNotCalled(x => x.Delete("test")). Since my code was awesome,
it succeeded, but I also like to "break" my methods sometimes just to
be sure I wrote a test correctly. I added a call to
the .Delete("test") in the method and the test now fails as expected.
However, if I change to .Delete("any other text"), the test passes
because "any other text" does not equal "test". Essentially I want to
ensure that the .Delete() method was never called, regardless of
parameters.

Is there a way to IgnoreArguments() on the AssertWasNotCalled()
somehow, or would I be looking at making a strict mock (and
consequently setting up expectations on every method call)?

Just more of a "how do I" question than anything. :)
--
You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to rhinomocks+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
Chris Missal
2010-02-17 21:32:53 UTC
Permalink
Sure, use it like this:

mock.AssertWasNotCalled(x => x.Delete("test"), y => y.IgnoreArguments());

hope that helps.
Post by Hegg
Greetings,
I have been building some tests and thought I'd try out the new
"AssertWasNotCalled" extension method. It seems to work as I'd expect
on methods with no parameters, but when I have a method with a
parameter, I can't seem to find a way to have it ignore those
parameters - that is, I want to assert that a specific method was
never called with any parameter ever.
For example, I'm using a interface which has a .List() method and
a .Delete(string name) method. Using the AAA style syntax, my test
uses AssertWasCalled(x => x.List()) and then attempts to
AssertWasNotCalled(x => x.Delete("test")). Since my code was awesome,
it succeeded, but I also like to "break" my methods sometimes just to
be sure I wrote a test correctly. I added a call to
the .Delete("test") in the method and the test now fails as expected.
However, if I change to .Delete("any other text"), the test passes
because "any other text" does not equal "test". Essentially I want to
ensure that the .Delete() method was never called, regardless of
parameters.
Is there a way to IgnoreArguments() on the AssertWasNotCalled()
somehow, or would I be looking at making a strict mock (and
consequently setting up expectations on every method call)?
Just more of a "how do I" question than anything. :)
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en.
--
Chris Missal
http://chrismissal.lostechies.com/
--
You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to rhinomocks+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
Jeff Greenland
2010-02-17 21:36:33 UTC
Permalink
Awesome! I knew it'd be simple! Thanks!
Post by Chris Missal
mock.AssertWasNotCalled(x => x.Delete("test"), y => y.IgnoreArguments());
hope that helps.
Post by Hegg
Greetings,
I have been building some tests and thought I'd try out the new
"AssertWasNotCalled" extension method. It seems to work as I'd expect
on methods with no parameters, but when I have a method with a
parameter, I can't seem to find a way to have it ignore those
parameters - that is, I want to assert that a specific method was
never called with any parameter ever.
For example, I'm using a interface which has a .List() method and
a .Delete(string name) method. Using the AAA style syntax, my test
uses AssertWasCalled(x => x.List()) and then attempts to
AssertWasNotCalled(x => x.Delete("test")). Since my code was awesome,
it succeeded, but I also like to "break" my methods sometimes just to
be sure I wrote a test correctly. I added a call to
the .Delete("test") in the method and the test now fails as expected.
However, if I change to .Delete("any other text"), the test passes
because "any other text" does not equal "test". Essentially I want to
ensure that the .Delete() method was never called, regardless of
parameters.
Is there a way to IgnoreArguments() on the AssertWasNotCalled()
somehow, or would I be looking at making a strict mock (and
consequently setting up expectations on every method call)?
Just more of a "how do I" question than anything. :)
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en.
--
Chris Missal
http://chrismissal.lostechies.com/
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en.
--
You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to rhinomocks+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
Alex McMahon
2010-02-18 08:25:49 UTC
Permalink
Or you can also use the Arg<T> syntax:
mock.AssertWasNotCalled(x => x.Delete(Arg<string>.is.Anything));
Post by Jeff Greenland
Awesome! I knew it'd be simple! Thanks!
Post by Chris Missal
mock.AssertWasNotCalled(x => x.Delete("test"), y => y.IgnoreArguments());
hope that helps.
Post by Hegg
Greetings,
I have been building some tests and thought I'd try out the new
"AssertWasNotCalled" extension method. It seems to work as I'd expect
on methods with no parameters, but when I have a method with a
parameter, I can't seem to find a way to have it ignore those
parameters - that is, I want to assert that a specific method was
never called with any parameter ever.
For example, I'm using a interface which has a .List() method and
a .Delete(string name) method. Using the AAA style syntax, my test
uses AssertWasCalled(x => x.List()) and then attempts to
AssertWasNotCalled(x => x.Delete("test")). Since my code was awesome,
it succeeded, but I also like to "break" my methods sometimes just to
be sure I wrote a test correctly. I added a call to
the .Delete("test") in the method and the test now fails as expected.
However, if I change to .Delete("any other text"), the test passes
because "any other text" does not equal "test". Essentially I want to
ensure that the .Delete() method was never called, regardless of
parameters.
Is there a way to IgnoreArguments() on the AssertWasNotCalled()
somehow, or would I be looking at making a strict mock (and
consequently setting up expectations on every method call)?
Just more of a "how do I" question than anything. :)
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en.
--
Chris Missal
http://chrismissal.lostechies.com/
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en.
--
You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to rhinomocks+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
Loading...