So.. I've got WPF and MVVM pattern. A thread in the ViewModel is running a task to update an observable collection, so when it adds to the collection I do so like this:
Application.Current.Dispatcher.Invoke((Action) (() =>
{
_files.Add(toAdd);
}));
which works... the issue is when I have NUnit tests and there is no UI thread as I understand it, so I have to run this first to add the files to the collection without an invoke:
if (Application.Current == null) {
_files.Add(toAdd);
}));
So just to clarify this is how it looks
if (Application.Current == null) {
_files.Add(toAdd);
return;
}));
Application.Current.Dispatcher.Invoke((Action) (() =>
{
_files.Add(toAdd);
}));
This feels wrong because I'm adding two lines of logic to the viewmodel, one where there is a UI and one purely for testing.
Anyone got any insight as to where my approach is going wrong, or if this is actually acceptable?
Thanks