Trying to Raise an Event throws an exception

2 posts, 0 answers
  1. Javier
    Javier avatar
    10 posts
    Member since:
    Apr 2013

    Posted 19 Nov 2013 Link to this post

    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
                                    }
                            });
                    }
     
                }
     
     
            }
  2. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 20 Nov 2013 Link to this post

    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.
  3. DevCraft R3 2016 release webinar banner
Back to Top