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 new to TypeMock and have been trying to figure this out. If someone could help me I would greatly appreciate it.

So I have a Method in the MasterOrderBPO class:
public PoeordersCollection GetOrders(Int32 inID)
{
   IPredicateExpression Filter = new PredicateExpression();
   Filter.Add(PoeordersFields.MasterOrderId == inID);

   PoeordersCollection Orders = new PoeordersCollection();
   Orders.GetMulti(Filter);

   return Orders;
}


and I want to run a test on it and always get the count as 1 for Orders.Count

so here is the test:
public void ValidGetOrders()
{
   bool hasErrors = true;

   Mock orderMock = MockManager.MockAll(typeof(PoeordersCollection));
   orderMock.ExpectGetAlways("Count", 1);

   PoeordersCollection order = new PoeordersCollection();

   MasterOrderBPO orderCol = MasterOrderBPO.getInstance();

   PoeordersCollection Order = orderCol.GetOrders(1);

   if (Order.Count > 0)
   {
      hasErrors = false;
   }

   Assert.IsTrue(hasErrors == false, "The Master Order: " + moValid.MasterOrderId + " - Does Not Exist");
}


however, when it hits GetMulti I get:

failed: System.NullReferenceException : Object reference not set to an instance of an object.
   at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.Clear()


What am I doing wrong? Please help me.
asked by mjourdan (600 points)

1 Answer

0 votes
Welcome to TypeMock.

Here is what happens:
When you use MockManager.MockAll you are mocking the constructor too.
So when you call Orders.GetMulti() some field is not initialized.

(Note: You are only mocking one instance and can use MockManager.Mock)
To solve do one of the following:
Mock orderMock = MockManager.Mock(typeof(PoeordersCollection),Constructor.NotMocked);

or mock the GetMulti() method.
orderMock.ExpectCall("GetMulti");
answered by scott (32k points)
...