So I have a view model that takes an instance of IAdapter right? And when I set a property in the view model I call some method in that IAdapter. This I can easily moq & test and I do. Here is the test method.
[TestMethod]
public void Setting_ExchangePrice_Calls_UpdateExcahngeCosts()
{
var currentItem = new InventoryItem();
bool adapterUpdateExchangeCostsWasCalled = false;
adapterMock.Setup(x => x.CurrentItem).Returns(currentItem);
adapterMock.Setup(x => x.UpdateExchangeCosts()).Callback(() => adapterUpdateExchangeCostsWasCalled = true);
vm.Adapter = adapterMock.Object;
vm.ExchangePrice = 4;
Assert.IsTrue(adapterUpdateExchangeCostsWasCalled);
}
Here is the problem, UpdateExchangeCosts() needs to call UpdateExchangePrices() – They will both live in the concrete instance of the adapter so there isn’t any reason to make it public which means there isn’t any reason to define it in the interface cause we don’t define private methods in interfaces. Sooooo….. I am stuck as to how I test to make sure calling UpdateExchangeCosts() also calls UpdateExchangePrices? I could imagine a state based test but in a lot of cases the UpdateExchangePrices won’t update anything (for various reasons) so there wont be any changed state to test.
Thank you and have a lovely day!
If
UpdateExchangeCostsneeds to callUpdateExchangePrices, you should test that as you test the specificAdapterclasses. When testing whatevervmis, it doesn’t need to care (and shouldn’t care) about what its givenAdapterdoes.