NMock problem??

G

Guest

Hi,

Can we use NMock to simulate concrete classes?.
In my case, I have to a class with no interfaces and virtual methods.
I've got 2 classes A, B, dependent on each other. That means, one
Class A creates many objects of Class B.

For example..

public class DependenceClass
{
private string name = null;
public DependenceClass(string str)
{
this.name = str;
}

public DependenceClass()
{
}

public void Wish()
{
Console.WriteLine("Hello " + this.name );
}
public string GetName()
{
return this.name;
}
public void SetName(string str)
{
this.name = str;
}
}

public class UnderTest
{
private DependenceClass dC = null;
public UnderTest(DependenceClass dc)
{
this.dC = dc;
}
public string GetName()
{
return this.dC.GetName();
}
public void SetName(string str)
{
this.dC.SetName(str);
}
}

my test class

[TestFixture]
public class TestClass
{

private DependenceClass dependenceClass = null;

[Test]
public void Test1()
{
IMock mock = new DynamicMock(

typeof(DependenceClass));
dependenceClass =

(DependenceClass)mock.MockInstance;

mock.ExpectAndReturn("GetName","Naveen",null);
Assert.AreEqual

("Naveen",dependenceClass.GetName());


}


The test is failing and the excpetion is : System.ArgumentException, Method
GetName is not Virtual.

How do we test class with no vitual methods and Interfaces.
And also, I could not download nmock.dll from the sourceforge.
I have downloaded the source code and compiled it in VS.NET to the dll.
I'm adding this dll to my "references". If this is incorrect, could anyone
please send me the "nmock.dll". My email is "(e-mail address removed)"

Cheers,

Naveen.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top