chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
I am getting the following error:

TestCase 'MakeMyPledge.BusinessObjects.UnitTest.CreateMembershipProvider.CreateUserButDatabaseFails'
failed: TypeMock.TypeMockException :
*** Cannot use CallOriginal in this sequence, there must be a mocked statement first
Perhaps you are trying to mock a method from mscorlib
at TypeMock.RecordExpectations.b(String A_0)
at TypeMock.RecordExpectations.a(String A_0)
at TypeMock.RecordExpectations.CallOriginal()
C:\Documents and Settings\dougc\My Documents\Visual Studio 2005\Projects\MakeMyPledge\MakeMyPledge.BusinessObjects\UnitTest\CreateMembershipProvider.cs(233,0): at MakeMyPledge.BusinessObjects.UnitTest.CreateMembershipProvider.CreateUserButDatabaseFails()

But ONLY under these circumstances:
1) I am running using TestDriven.NET (latest version) and VS2005 SP1
2) I am running unit tests WITH coverage (NCover included in TD)
3) I am running all unit tests in the fixture (there are 23)

If I do this:
4) Run ONLY this unit test WITH coverage...it works
5) Run ALL unit tests WITHOUT coverage...it works

This makes be think I have some side effects. How can I be sure that any mocks used in other unit tests are not affecting the current test?

I have tried adding this to the TestFixture:
[TearDown]
public void AfterEachTest()
{
MockManager.Verify();
MockManager.ClearAll();
}
...but it seems to have no effect.

Here is the test:
[Test]
public void CreateUserButDatabaseFails()
{
MakeMyPledgeMembershipProvider provider = new MakeMyPledgeMembershipProvider();
provider.Initialize(null, null);

Exception ex = new Exception();
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
BusinessTransaction tran = new BusinessTransaction();
recorder.CallOriginal();
DevExpress.Xpo.UnitOfWork x = tran.UnitOfWork;
recorder.CallOriginal();
tran.CommitChanges();
recorder.Throw(ex);
}
MembershipCreateStatus status;
MembershipUser user = provider.CreateUser("doug", "Hair1234", "dougc@test.com",
"Mothers maiden name", "Franklin", true, Guid.NewGuid(), out status);
Expect(user == null);
Expect(status == MembershipCreateStatus.ProviderError);
}

Any ideas would be greatly appreciated.
asked by (3.5k points)

10 Answers

0 votes
Hi,
Which line did the test fail?
Try running the Tracer to see what methods have been recorded.
answered by (32k points)
0 votes
It fails on this line:

MembershipUser user = provider.CreateUser("doug", "Hair1234", "dougc@douglas-associates.com",
"Mothers maiden name", "Franklin", true, Guid.NewGuid(), out status);

I cannot run the Tracer nor the Configuration from within VS. Sorry.
answered by (3.5k points)
0 votes
Open the tracer from the Start Menu.
Start Menu->All Programs->TypeMock->TypeMock Tracer.

I am not sure that I follow. The test fails with "Cannot use CallOriginal " when calling the provider.CreateUser method?
According to the error message it should be in line 233 in CreateMembershipProvider.cs. Could you point out line 233 in the code you posted.
answered by (32k points)
0 votes
I opened the Tracer from the Start Menu, but the only output was the TypeMock Initialized line.

I know it sounds crazy, but it fails on provider.CreateUser. What else can I do to isolate this?
answered by (3.5k points)
0 votes
Could you please run TypeMock with logging.
Run the test, then zip and send the log to the support e-mail.
answered by (32k points)
0 votes
Done. I sent to info at typemock because I didn't have the support email address.
answered by (3.5k points)
0 votes
Thanks Doug,
Taken offline.
We will post the solution when we find it.
answered by (32k points)
0 votes
Scott --- To add to the weirdness of all this...it is working now.

I had the function that was failing tagged with Ignore so it wouldn't get in the way. I uncommented it this morning to create the test run you requested...and I must have forgot to recomment it. The darn thing has been working all day.

Tis up to you whether you pursue the bug, but for right now, I'm in business. Thanks for working with me on this.
answered by (3.5k points)
0 votes
That is great.
If anyone encounters this bug please post about it.
In any case please make sure that HKEY_CLASSES_ROOT\CLSID\{6287B5F9-08A1-45E7-9498-B5B2E7B02995}\InprocServer32
(Default) key is C:\PROGRA~1\NCover\CoverLib.dll
answered by (32k points)
0 votes
That key contains "NCover Coverage Profiler" on my system.

BTW, I am using the copy of NCover that ships with the latest version of TestDriven.NET...so I think the DLL is in C:\Program Files\TestDriven.NET 2.0\NCover\1.5.6 on my box.

Hope this helps, Doug
answered by (3.5k points)
...