jeudi 5 février 2015

JustMock: Mocking Static method call not working

Using JustMock:


I am not sure why my arrange call for a static method is trying to execute the original.



[Test]
public void RunCompleteDivxJob_Negative_Exception()
{
DebugView.IsTraceEnabled = true;
var mediaId = 2000999;
var mediaTypeId = (int)CmtMediaType.Video;
var queueCmtId = 9999;
var cmtFileType = CmtFileType.SourceMediaFile;
var statusError = CmtQueueStatus.Error;
var exception = new Exception("test");

// ARRANGE
var encodeJobStateMachineManager = Mock.Create<EncodeJobStateMachineManager>(Behavior.CallOriginal);
var logger = Mock.Create<Logger>(Behavior.CallOriginal, typeof(EncodeJobStateMachineManager));
var inst = new PrivateAccessor(encodeJobStateMachineManager);
inst.SetProperty("_log", logger);
var createCompleteJobCalled = false;
Mock.Arrange(() => DivxEncodeJob.CreateCompleteJob(mediaId, mediaTypeId, queueCmtId, cmtFileType))
.DoInstead(() => createCompleteJobCalled = true);
Mock.Arrange(() => encodeJobStateMachineManager.EncodeJob.Submit()).Throws(exception).MustBeCalled();
logger.Arrange(x => x.Error(Arg.AnyString, exception)).MustBeCalled();
//Mock.SetupStatic(typeof(QueueDAO));
var updateQueueStatusCalled = false;
Mock.Arrange(() => QueueDAO.UpdateQueueStatus(queueCmtId, statusError)).DoInstead(() => updateQueueStatusCalled = true);

// ACT
encodeJobStateMachineManager.RunCompleteDivxJob(mediaId, mediaTypeId, queueCmtId, cmtFileType);

// ASSERT
Mock.Assert(encodeJobStateMachineManager);
Assert.IsTrue(createCompleteJobCalled);
Assert.IsTrue(updateQueueStatusCalled);
}


The first static call is mocking the method call correctly:



Mock.Arrange(() => DivxEncodeJob.CreateCompleteJob(mediaId, mediaTypeId, queueCmtId, cmtFileType))
.DoInstead(() => createCompleteJobCalled = true);


But the second static call is executing the original code:



Mock.Arrange(() => QueueDAO.UpdateQueueStatus(queueCmtId, statusError)).DoInstead(() => updateQueueStatusCalled = true);


These are essentially called exactly the same. So why is the first one working as expected and the second not?


Aucun commentaire:

Enregistrer un commentaire