I'm mocking a concrete class.... the CreateMock method passed, but when
i call
Expect.Call(any method or any property of my mock object).Return(any
object);
the framework throws System.InvalidOperationException: Invalid call,
the last call has been used or no call has been made.
what really annoys me is that the sample of mocking the ArrayList in
the documentation works fine, i even created an empty class with one
method
func() which simply returns an integer and it still throws the same
exception
Please help me is there anything i did wrong....!!!!!
Here is my code
public class MyClass
{
public int func()
{
return 90;
}
public MyClass()
{
}
}
[Test]
public void testMyClass()
{
MyClass MyClass1;
MockRepository mocks = new MockRepository();
MyClass1 = (MyClass)mocks.CreateMock(typeof(MyClass));
Expect.Call(MyClass1.func()).Return(994);
mocks.ReplayAll();
Assert.AreEqual(999, MyClass1.func());
mocks.VerifyAll();
}
public class MyClass
{
virtual public int func()
{
return 90;
}
public MyClass()
{
}
}
Teo
On 1/25/06, fokosh <fok...@yahoo.com> wrote:
>
> thanx Teo for replying but can you tell me please why it restricted to
> virtual methods only, is it only in this framework (because of the
> design i mean). so i want to test my class methods and properties i
public virtual DataTable GetData(out string queryState, out string
queryException)
{
DataTable outTable;
outTable = new DataTable();
try
{
this.OpenConnection();
this.ExecuteReader();
outTable = this.GetTableFromReader();
queryState = "Finished";
queryException = "None";
sqlReader.Close();
this.CloseConnection();
}
catch(System.Exception ex)
{
System.Diagnostics.Debug.Write(ex.Message);
queryState = "Finished";
queryException = "None";
}
finally
{
this.CloseConnection();
}
return outTable;
}
can you show me a sample plz here is my code:
I used the Callback method but it didnt work... it kept throwing this
exception: TestCase 'FactoriesUnitTests.FactoriesManagerTest.GetData'
failed: System.InvalidOperationException: This action is invalid when
the mock object is in record state.
Here is my test method
[Test]
public void GetData()
{
GetDataDelegate getDataDelegate = new
GetDataDelegate(SetQueryStateAndException);
Expect.Call(Helper.RunInstanceMethod(typeof(DatabaseManager),
"OpenConnection",
databaseManagerMock, null)).Return(true);
Expect.Call(Helper.RunInstanceMethod(typeof(DatabaseManager),
"ExecuteReader",
databaseManagerMock, null)).Return(true);
// The exception is thrown in the next method call
Expect.Call(databaseManagerMock.GetData(out queryState, out
queryException)).Return(outTable).Callback(getDataDelegate);
Expect.Call(Helper.RunInstanceMethod(typeof(DatabaseManager),
"CloseConnection",
databaseManagerMock, null)).Return(true);
mocks.ReplayAll();
//......Assert calls here
}
-----Original Message-----
From: Rhino...@googlegroups.com [mailto:Rhino...@googlegroups.com] On Behalf Of fokosh
Sent: Wednesday, February 01, 2006 11:43 AM
To: Rhino.Mocks
Subject: Re: Mocking concrete classes Rhino Mocks 2.5.9