I wanted to check that in a multi-step process the log is accurately reflects the state of the processing:
Received.InOrder(
() =>
{
dal.UpdateLoaderJobStepLog(Arg.Is<LoaderJobStepLog>(
ljsl => ljsl.ExecutionStatus == JobExecutionStatus.Running
&& ljsl.ExecutionStatusSp1 == JobExecutionStatus.FinishedSuccessfully
&& ljsl.ExecutionStatusSp2 == JobExecutionStatus.Running
&& ljsl.ExecutionStatusSp3 == JobExecutionStatus.NotStarted
));
dal.UpdateLoaderJobStepLog(Arg.Is<LoaderJobStepLog>(
ljsl => ljsl.ExecutionStatus == JobExecutionStatus.Running
&& ljsl.ExecutionStatusSp1 == JobExecutionStatus.FinishedSuccessfully
&& ljsl.ExecutionStatusSp2 == JobExecutionStatus.FinishedSuccessfully
&& ljsl.ExecutionStatusSp3 == JobExecutionStatus.Running
));
...
);
This is not working as expected, because the class calling dal.UpdateLoaderJobStepLog modifies the passed LoaderJobStepLog at every step, and persists it using the dal instance. Naturally Received.InOrder checks args after all steps already happened, so it observes the final LoaderJobStepLog object which does not have the desired properties at that time, it reflects the last effect of its last modification.
I know testing method call order is somewhat controversial in testing, but in this case it is in important part of the specification, so I felt i have to test it.
When I clone the LoaderJobStepLog every time I pass it to the dal interface the test obviously becomes green, because all calls got a distinct object.
I suppose the correct way to test order in this case to use Arg.Do, because in this case I prepare asserts before running the target method, so I got callbacks for all steps.
The test using Arg.Do is a bit more verbose, but works:
var callOrder = 0;
dal.UpdateLoaderJobStepLog(Arg.Do<LoaderJobStepLog>(
ljsl =>
{
callOrder++;
if (ljsl.LoaderJobStepId == 0
&& ljsl.ExecutionStatus == JobExecutionStatus.Running
&& ljsl.ExecutionStatusSp1 == JobExecutionStatus.FinishedSuccessfully
&& ljsl.ExecutionStatusSp2 == JobExecutionStatus.Running
&& ljsl.ExecutionStatusSp3 == JobExecutionStatus.NotStarted)
{
Assert.AreEqual(1, callOrder);
return;
}
if (ljsl.LoaderJobStepId == 0
&& ljsl.ExecutionStatus == JobExecutionStatus.Running
&& ljsl.ExecutionStatusSp1 == JobExecutionStatus.FinishedSuccessfully
&& ljsl.ExecutionStatusSp2 == JobExecutionStatus.FinishedSuccessfully
&& ljsl.ExecutionStatusSp3 == JobExecutionStatus.Running)
{
Assert.AreEqual(2, callOrder);
return;
}
Is this the preferred way to test method sequencing?
Thanks,
Zsolt