Hi I am trying to Raise an event but I am getting this exception:
System.NotImplementedException: You can't call the original implementation of a method that does not have one (abstract or interface method).
System.NotImplementedException: You can't call the original implementation of a method that does not have one (abstract or interface method).
StorageAndInventoryService is the class that raises the event. BatchManager is the class subscribed to that event My test:I know that the issue is that we are Mocking as CallOriginal the BatchManager, but we are looking for an alternative, because as you can see is the class that we are trying to unit test. This is the callBack that I want to be executed in the BatchManager class:[TestMethod]
public
void
DestinationUnLockUpdatesBatchesStatus()
{
batchManager = Mock.Create<BatchManager>(Behavior.CallOriginal);
batchManager.StorageInventoryService = Mock.Create<StorageInventoryService>();
//Mock data
List<DestinationStatus> destinationStatuses =
new
List<DestinationStatus>
{
new
DestinationStatus(
"D1"
,
false
, 1, 2,
new
List<
string
>())
};
Mock.Arrange(() => batchManager.StorageInventoryService.GetDestinationStatus(Arg.IsAny<List<
string
>>())).Returns(destinationStatuses).OccursOnce();
batchManager.AddLoadCarrierRequestToBatch(materialFlowContext).Wait();
DestinationInfo destinationInfo = batchManager.BatchRepository.GetDestination(
"D1"
);
List<BatchInfo> batchInfos = batchManager.BatchRepository.GetBatchesByDestination(destinationInfo, 99).ToList();
batchManager.SelectAndReserveLoadCarrierRequests(
new
string
[] {
"D1"
}).Wait();
Assert.IsTrue(destinationInfo.IsAvailable ==
false
);
Assert.IsTrue(batchInfos.FirstOrDefault().Status == BatchStatus.Suspended);
MfsLocationLockChangedDataEventArgs mfsLocationLockChangedDataEventArgs =
new
MfsLocationLockChangedDataEventArgs(
new
MfsLocationLockChangedData(
"D1"
,
true
,
string
.Empty));
Mock.Raise(() => batchManager.StorageInventoryService.LocationLockChanged +=
null
, mfsLocationLockChangedDataEventArgs);
Assert.IsTrue(batchInfos.FirstOrDefault().Status == BatchStatus.InProgress);
}
private
void
StorageInventoryServiceOnLocationLockChanged(
object
sender, MfsLocationLockChangedDataEventArgs mfsLocationLockChangedDataEventArgs)
{
Log.Debug(
"** StorageInventoryServiceOnLocationLockChanged has changed**"
);
if
(!mfsLocationLockChangedDataEventArgs.MfsLocationLockChangedData.IsLocked)
{
DestinationInfo destinationInfo = BatchRepository.GetDestination(mfsLocationLockChangedDataEventArgs.MfsLocationLockChangedData.AddressName);
if
(destinationInfo !=
null
)
{
BatchRepository.UpdateDestinationAvailability(destinationInfo.Address,
true
);
List<BatchInfo> batchInfos = BatchRepository.GetBatchesByDestination(destinationInfo, 99).ToList();
foreach
(BatchInfo batch
in
batchInfos)
{
BatchRepository.UpdateBatchStatus(batch.BatchId, BatchStatus.InProgress);
foreach
(
string
loadCarrier
in
batch.LoadCarriers)
{
BatchRepository.UpdateLoadCarrierRequestStatus(loadCarrier, LoadCarrierRequestStatus.New);
}
}
OnDestinationUnLocked(
new
DestinationStatusChangedEventArgs
{
Destinations =
new
List<
string
>
{
mfsLocationLockChangedDataEventArgs.MfsLocationLockChangedData.AddressName
}
});
}
}
}