I'm getting an exception that really makes no sense to me whatsoever.
I have an Expect call for a method that takes 3 arguments into it: The types are called CallContext, IDal, and List.
NUnit throws me 2 exceptions: One for not expecting a method call that happened where the types are CallContext, System.Object, and List, and one for expecting a call that didn't happen where the types are the correct ones. The fun thing is that the only way to call the method is with the 3 types mentioned above. There is no method call with type object!
Here is the code:
private IDal mockDal;
private CallContext mockContext;
private IWorkbooksLogic mockWLogic;
private ICommercialSpaceLogic mockCLogic;
private CmWorkbook mockWorkbook;
private IList<Workbook> mockList;
private MockRepository mock;
private Random random;
[SetUp]
public void Setup() {
mock = new MockRepository();
random = new Random();
this.mockDal = mock.StrictMock<IDal>() as IDal;
this.mockContext = new CallContext();
this.mockWLogic = mock.StrictMock<IWorkbooksLogic>() as IWorkbooksLogic;
this.mockCLogic = mock.StrictMock<ICommercialSpaceLogic>() as ICommercialSpaceLogic;
this.mockWorkbook = new CmWorkbook();
this.mockList = mock.StrictMock<IList<Workbook>>() as IList<Workbook>;
}
[Test]
public void ShouldFailWhenCreateWorkbookFails() {
int randBudget = random.Next(50);
int randEntity = random.Next(50);
int randWork = random.Next(50);
WorkbookDefinitions work = new WorkbookDefinitions {
WorkbookDefinitionID = randWork
};
Budget budget = new Budget {
BudgetID = randBudget,
WorkbookDefinitions = new List<WorkbookDefinitions> { work },
};
CommercialProperty property = new CommercialProperty {
CommercialPropertyID = randEntity,
CMEntity = new CMEntity {
EntityBase = new EntityEntity { EntityCode = "random.Next(50)" }
}
};
CmWorkbook book = new CmWorkbook {
WorkbookName = String.Format("CM — {0}", property.CMEntity.EntityBase.EntityCode)
};
OperationResults results = new OperationResults();
this.mockList.Add(book);
using (mock.Record()) {
Expect.On(this.mockDal).Call(this.mockDal.GetObject<Budget, int>(randBudget)).Return(budget);
Expect.On(this.mockDal).Call(this.mockDal.GetObject<CommercialProperty, int>(randEntity)).Return(property);
Expect.On(this.mockWLogic).Call(this.mockWLogic.Create(this.mockContext, this.mockDal, this.mockList)).Return(null);
}
using (mock.Playback()) {
results = CmWorkbookLogic.CreateWorkbook(mockContext, mockDal, mockWLogic, mockCLogic, randBudget, randEntity);
}
Assert.IsFalse(results.AllSuccessful);
}
The method being called is: workbooksLogic.Create(context, dal, new List { workbook }) Here is the NUnit error:
ShouldFailWhenCreateWorkbookFails:
Rhino.Mocks.Exceptions.ExpectationViolationException : ICRUDBaseLogic`1.Create(CallContext, System.Object, System.Collections.Generic.List`1[Workbook]); Expected #0, Actual #1.
ICRUDBaseLogic`1.Create(CallContext, IDalProxy8768e63f86da4601993b4791c696ada6, System.Collections.Generic.List`1[Workbook]); Expected #1, Actual #0.
I have no idea what the heck is going on with this. Anyone have any ideas?