Hi,
I would like to Mock a Property of a class that has some protected methods , to do so I have created a Mock for exposing those methods in my tests:
I would like to Mock a Property of a class that has some protected methods , to do so I have created a Mock for exposing those methods in my tests:
And this is the Mock:publicclassBatchManager{publicIStorageInventoryService StorageInventoryService {get;set; }protectedvirtualvoidAddOrUpdateLoadCarrierRequest(LoadCarrierRequest loadCarrierRequest){List<DestinationStatus> destinationStatuses = StorageInventoryService.GetDestinationStatus(newList<string> { loadCarrierRequest.DestinationAddress });AddOrUpdateDestinationDictionary(destinationStatuses, loadCarrierRequest);AddOrUpdateBatchDictionary(loadCarrierRequest);AddOrUpdateLoadCarrierRequestDictionary(loadCarrierRequest);ExecuteNextTransport(destinationStatuses.Select(d => d.Address).ToList());}}
I am getting a null, instead of a List initialized..My test:publicclassMockBatchManager : BatchManager{publicnewvoidAddOrUpdateLoadCarrierRequest(LoadCarrierRequest loadCarrierRequest){base.AddOrUpdateLoadCarrierRequest(loadCarrierRequest);}}if I take a look on the line:[TestMethod]publicvoidAddOrUpdateLoadCarrierRequestAddsAnElementToEveryDictionary(){//ArrengeMockBatchManager mockBatchManager =newMockBatchManager{StorageInventoryService = Mock.Create<StorageInventoryService>()};//Mock.Arrange(() => mockBatchManager.ExecuteNextTransport(Arg.IsAny<List<string>>())).DoNothing();Mock.Arrange(() => mockBatchManager.StorageInventoryService.GetDestinationStatus(Arg.IsAny<List<string>>())).ReturnsCollection(newList<DestinationStatus>());//ActmockBatchManager.AddOrUpdateLoadCarrierRequest(loadCarrierRequest);//AssertAssert.IsTrue(mockBatchManager.DestinationDic.Count == 1);Assert.IsTrue(mockBatchManager.LoadCarrierRequestsDic.Count == 1);Assert.IsTrue(mockBatchManager.ConcurrentDestinationStatuses.Count == 1);Assert.IsTrue(mockBatchManager.BatchDic.Count == 1);}List<DestinationStatus> destinationStatuses = StorageInventoryService.GetDestinationStatus(newList<string> { loadCarrierRequest.DestinationAddress });
