I have a viewmodel class that is used as a base class for a ton of subclasses. I now added code to one of the base class's methods.
protected virtual void OnLanguageChanged(CultureInfo culture)
{
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
}
This is to set the default culture on new threads.
I want to make sure that all derived classes, when they override this method, that they call "base.OnLanguageChanged". How can I write a unit test (I'm using Moq) that will fail when at least one derived class does not call this base method. The viewmodel has a property called ChildViewModelCollection which lists all child view models. The method that I'm overriding is called OnLanguageChanged(). Here is an idea of what I'm trying to do:
[TestMethod]
public void OnLanguageChangeCalledByDerivedClasses()
{
var compositeViewModel = Container.Resolve<CompositeViewModel>();
var children = compositeViewModel.ChildViewModelCollection;
var newCulture = new CultureInfo("fr-CA");
// Call method so that children run their overridden methods
compositeViewModel.OnLanguageChanged(newCulture);
// Now how do I check if base.OnLanguageChanged was called by all children
foreach (var childViewModel in children)
{
}
Assert.AreEqual(CultureInfo.DefaultThreadCurrentCulture, CultureInfo.DefaultThreadCurrentUICulture);
}