It doesn't work on my machine only!!!

25 views
Skip to first unread message

Mark Whitfeld

unread,
Aug 24, 2010, 3:30:01 AM8/24/10
to Rhino.Mocks
OK, I'm so stumped about this one!
I have been using Rhino Mocks for years and it has never given me
problems.
I run the following simple code and it gives this error message:

(on the line with AssertWasNotCalled)
System.InvalidOperationException : No expectations were setup to be
verified, ensure that the method call in the action is a virtual
(C#) / overridable (VB.Net) method call

Stack Trace:
at Rhino.Mocks.RhinoMocksExtensions.AssertExactlySingleExpectaton[T]
(MockRepository mocks, T mockToRecordExpectation)
at Rhino.Mocks.RhinoMocksExtensions.GetExpectationsToVerify[T](T mock,
Action`1 action, Action`1 setupConstraints)
at Rhino.Mocks.RhinoMocksExtensions.AssertWasNotCalled[T](T mock,
Action`1 action, Action`1 setupConstraints)
at Rhino.Mocks.RhinoMocksExtensions.AssertWasNotCalled[T](T mock,
Action`1 action)
at Habanero.Templates.Test.Processor.TestMocking.Test_ShouldWork()

Here is the code (I know its testing the mocking framework, that's the
point):

[TestFixture]
public class TestMocking
{
[Test]
public void Test_AssertWasNotCalled_ShouldWork()
{
var bob = MockRepository.GenerateStub<IBob>();
bob.AssertWasNotCalled(o => o.Action());
}
}

public interface IBob
{
void Action();
}

The project is compiled for AnyCPU (and I have tried all the others)
and .NET 3.5.
This fails on my PC, but works on every other PC. Aaaargh!

My PC is as follows:
Intel Core i7 CPU 860 @ 2.80GHz
8.00 GB RAM
Windows 7 64-bit OS

I have restarted Visual Studio, and the PC as well as run the tests
from Resharper and the nunit test runner.
All have the same result: It fails!

Please help!

Tuna Toksoz

unread,
Aug 24, 2010, 9:43:16 AM8/24/10
to rhino...@googlegroups.com
[TestFixture]
public class TestMocking
{
       [Test]
       public void Test_AssertWasNotCalled_ShouldWork()
       {
               var bob = MockRepository.GenerateMock<IBob>();
               bob.AssertWasNotCalled(o => o.Action());
       }
}

Can you try that?


Tuna Toksöz
Eternal sunshine of the open source mind.

http://devlicio.us/blogs/tuna_toksoz
http://tunatoksoz.com
http://twitter.com/tehlike





--
You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
To post to this group, send email to rhino...@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.


Mark Whitfeld

unread,
Aug 25, 2010, 3:06:05 AM8/25/10
to Rhino.Mocks
Oh, before I forget to mention. I am using Rhino.Mocks 3.6

Thanks for your reply.
Yeah, I tried that as well. It doesn't work either...
I get:

System.InvalidOperationException : No expectations were setup to be
verified, ensure that the method call in the action is a virtual
(C#) / overridable (VB.Net) method call
at
Rhino.Mocks.RhinoMocksExtensions.AssertExactlySingleExpectaton(MockRepository
mocks, T mockToRecordExpectation)
at Rhino.Mocks.RhinoMocksExtensions.GetExpectationsToVerify(T mock,
Action`1 action, Action`1 setupConstraints)
at Rhino.Mocks.RhinoMocksExtensions.AssertWasNotCalled(T mock,
Action`1 action, Action`1 setupConstraints)
at Rhino.Mocks.RhinoMocksExtensions.AssertWasNotCalled(T mock,
Action`1 action)
at Habanero.Templates.Test.Processor.TestMocking.Test_ShouldWork

It fails in the same place. Could it be an issue with Castle do you
think?
I hope I don't have to use a different mocking framework just because
it doesn't work on my machine!

On Aug 24, 3:43 pm, Tuna Toksoz <tehl...@gmail.com> wrote:
> [TestFixture]
> public class TestMocking
> {
>        [Test]
>        public void Test_AssertWasNotCalled_ShouldWork()
>        {
>                var bob = MockRepository.GenerateMock<IBob>();
>                bob.AssertWasNotCalled(o => o.Action());
>        }
>
> }
>
> Can you try that?
>
> Tuna Toksöz
> Eternal sunshine of the open source mind.
>
> http://devlicio.us/blogs/tuna_toksozhttp://tunatoksoz.comhttp://twitter.com/tehlike
> > rhinomocks+...@googlegroups.com<rhinomocks%2Bunsu...@googlegroups.com>
> > .

Tim Barcz

unread,
Aug 25, 2010, 9:43:52 AM8/25/10
to rhino...@googlegroups.com
Mark,

Please tell me what version of NUnit are you running?

Tim

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.




--
Tim Barcz
Microsoft C# MVP
Microsoft ASPInsider
http://timbarcz.devlicio.us
http://www.twitter.com/timbarcz

Mark Whitfeld

unread,
Aug 26, 2010, 3:31:58 AM8/26/10
to Rhino.Mocks
Hi Tim

I am using NUnit 2.5.6, I have also tried 2.5.3 as well as the
Resharper Test runner.
It doesn't work in any of these... Only on my machine... :(

Thanks
-Mark

On Aug 25, 3:43 pm, Tim Barcz <timba...@gmail.com> wrote:
> Mark,
>
> Please tell me what version of NUnit are you running?
>
> Tim
>
> >http://devlicio.us/blogs/tuna_toksozhttp://tunatoksoz.comhttp://twitt...
> > <rhinomocks%2Bunsu...@googlegroups.com<rhinomocks%252Buns...@googlegroups.com>
>
> > > > .
> > > > 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 rhino...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > rhinomocks+...@googlegroups.com<rhinomocks%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/rhinomocks?hl=en.
>
> --

Tim Barcz

unread,
Aug 26, 2010, 10:55:33 AM8/26/10
to rhino...@googlegroups.com
Oddly I have a Win 7 64-bit system and everything works fine.....

What version of TDD.NET?

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.




--
Tim Barcz
Microsoft C# MVP

Mark Whitfeld

unread,
Aug 27, 2010, 3:11:33 AM8/27/10
to Rhino.Mocks
Yeah, my previous machine was Win 7 64-bit as well and it worked.
It only doesn't run on this machine... Arrgh!

What do you mean by TDD.net? Never heard of it. Unless you mean
TestDriven.net, but I don't use that because I have resharper.

I don't hink that this is an issue with the test runner because it
gives the same result no matter what test runner I use.
The issue is possibly in how Rhino Mocks is determining whether it can
mock the interface.
But something is breaking on my machine only. Do you think it could be
a permissions issue. I am an administrator on this machine though.

I think I will download the Rhino Mocks Source code and try to run
it's tests. Possibly even debug this from the source code.

On Aug 26, 4:55 pm, Tim Barcz <timba...@gmail.com> wrote:
> Oddly I have a Win 7 64-bit system and everything works fine.....
>
> What version of TDD.NET?
>
> > > > <rhinomocks%2Bunsu...@googlegroups.com<rhinomocks%252Buns...@googlegroups.com>
> > <rhinomocks%252Buns...@googlegroups.com<rhinomocks%25252Bun...@googlegroups.com>
>
> > > > > > .
> > > > > > 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 rhino...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > rhinomocks+...@googlegroups.com<rhinomocks%2Bunsu...@googlegroups.com>
> > <rhinomocks%2Bunsu...@googlegroups.com<rhinomocks%252Buns...@googlegroups.com>
>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/rhinomocks?hl=en.
>
> > > --

Mark Whitfeld

unread,
Aug 27, 2010, 8:38:01 AM8/27/10
to Rhino.Mocks
Ok, I checked out the rhino mocks code and ran all the tests.
The tests all pass and if I add my test above, it also passes!

It seems that it is not working in new VS2010 projects.
I will investigate further when I get a chance...

Tim Barcz

unread,
Aug 27, 2010, 8:49:07 AM8/27/10
to rhino...@googlegroups.com
Ah ok ok... So you were in VS 2010? I can run then on my machine as well

> To unsubscribe from this group, send email to rhinomocks+...@googlegroups.com.

Mark Whitfeld

unread,
Sep 2, 2010, 5:35:39 AM9/2/10
to Rhino.Mocks
I have found the problem!!!!!
It is so simple, but so easy to miss!
If you had have run the tests I posted, it would also have failed for
you.
So, it is nothing to do with it not working on my machine, but it is
all about the actual code being tested! Curious...?
Well Have a look at these two tests:

[TestFixture]
public class TestMocking
{
[Test]
public void Test_ThisWorks()
{
IBob bob = MockRepository.GenerateStub<IBob>();
bob.AssertWasNotCalled(bob1 => bob1.Action());
}

[Test]
public void Test_ThisDoesntWork()
{
IBob bob = MockRepository.GenerateStub<IBob>();
bob.AssertWasNotCalled(bob1 => bob.Action());
}
}

public interface IBob
{
void Action();
}

The one works, but the other doesn't... Do you spot the difference?
:)... Dramatic pause...
The second test refers to the outside variable in the lambda instead
of the parameter!
That's it. That is why it is failing! So simple, but so easy to miss.
The reason why it worked on other PCs is because I just typed out the
tests again there instead of copy pasting the code (I was being lazy,
ok).

But this does bring me to that error message:
"No expectations were setup to be verified, ensure that the method
call in the action is a virtual (C#) / overridable (VB.Net) method
call"

It really throws you doesn't it! Well, for me it does.
Would it not be a good thing to add a check on the lambda expression
to see if it calls a method on the actual parameter passed in anywhere
in the lambda.
Or does it not use lambda expressions for this...

Anyway. Problem solved. I don't need to reformat my PC anymore (maybe
just my mind...).
Shot for your efforts.
-Mark

On Aug 27, 2:49 pm, Tim Barcz <timba...@gmail.com> wrote:
> Ah ok ok... So you were in VS 2010? I can run then on my machine as well
>

Tim Barcz

unread,
Sep 2, 2010, 7:55:23 AM9/2/10
to rhino...@googlegroups.com, Rhino.Mocks
You said in your original email that it worked on every PC but the one - were you not running the same code?

Alex McMahon

unread,
Sep 2, 2010, 7:58:34 AM9/2/10
to rhino...@googlegroups.com
and it was also different than what was included in the original email. Which would have worked as it used o=> rather than a name that was almost the same as an existing variable.

Normally copy and paste coding should be avoided, but in this case it might have been a better idea ;)

Tim Barcz

unread,
Sep 2, 2010, 8:04:24 AM9/2/10
to rhino...@googlegroups.com, rhino...@googlegroups.com
I ran the supplied code on several machines and it worked - which is why I went down the path of exploring add-ons.

Mark Whitfeld

unread,
Sep 3, 2010, 3:27:55 AM9/3/10
to Rhino.Mocks
Yeah, thanks everyone for your input.
I messed up when I posted the first post...
I ended up changing the variable names when I posted the code here
because they were specific to other classes and I wanted my test case
not to have names that didn't apply to the test cases classes.
Little did I know that that was the very thing that had caused the
issue. Sorry about that!

The thing about working on every PC but mine... When I experienced the
problem I spoke to other developers in the office and said I would
send them the code, but when they saw how simple the code was they
just typed it out and found it to be working. I had got a new PC the
day before and I hadn't done mocking on it before so it seemed strange
when it "only didn't work on my machine".

Well, I ended up learning to use git and to build rhino mocks in the
process of finding out the solution, so I guess that was good for me
to do.
Thanks again.

On Sep 2, 2:04 pm, Tim Barcz <timba...@gmail.com> wrote:
> I ran the supplied code on several machines and it worked - which is why I went down the path of exploring add-ons.
>
> On Sep 2, 2010, at 6:58 AM, Alex McMahon <fluxmu...@gmail.com> wrote:
>
> > and it was also different than what was included in the original email. Which would have worked as it used o=> rather than a name that was almost the same as an existing variable.
>
> > Normally copy and paste coding should be avoided, but in this case it might have been a better idea ;)
>
> > On 2 September 2010 12:55, Tim Barcz <timba...@gmail.com> wrote:
> > You said in your original email that it worked on every PC but the one - were you not running the same code?
>
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages