This is a migrated thread and some comments may be shown as answers.

Trying to Raise an Event throws an exception

1 Answer 145 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Javier
Top achievements
Rank 2
Javier asked on 19 Nov 2013, 09:55 AM
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).
StorageAndInventoryService is the class that raises the event.
BatchManager is the class subscribed to that event

My test:

[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);
 
        }
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:
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
                                }
                        });
                }
 
            }
 
 
        }

1 Answer, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 20 Nov 2013, 03:51 PM
Hi Javier,

Normally, the CallOriginal should not prevent you from raising an event with Mock.Raise(). However, this could be a bug in JustMock which we are not aware of.

Is it possible to isolate the issue in a simple project and send it over for further investigation?

Thank you for the understanding in advance.

Regards,
Kaloyan
Telerik
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Tags
General Discussions
Asked by
Javier
Top achievements
Rank 2
Answers by
Kaloyan
Telerik team
Share this question
or