I am using Visual Studio 2013 and MsTest for unit test and Rhino Mocks for mocking an object.
Is there any way, we can mock other class object
public class Organization
{
public DataSet GetUsers()
{
DataSet ds = new DataSet();
// Added some columns and rows here
// This class is interacting with the database. That's why I want to create
// mock of this class.
return ds;
}
}
My Main class is as below
public class Users
{
public DataSet GetUsers(Organization org)
{
DataSet ds = org.GetUsers();
return ds;
}
}
My Test method is as below
[TestMethod]
public void GetUsersTest()
{
DataSet ds = new DataSet();
//added some mock rows and columns to this dataset
var objOrg = MockRepository.GenerateMock<Organization>();
objOrg.Expect(x => x.GetUsers()).Return(ds);
Users obj = new Users();
DataSet dsResult = obj.GetUsers(objOrg);
}
It is giving me error. Can anyone help me to write unit test for above class's GetUsers method please?