I am using Win10, VS Community 2019, latest .NET Core WPF app. I have a very simple WPF app. I would like to test it's ViewModel. I kept MVVM model and keep view and ViewModel separated. Now I would like to unit test the ViewModel. But I can't refer to my project's ViewModel. I have a simple code for as follows:-
namespace Multiples.ViewModel
{
class MultiplesViewModel
{
public MultiplesViewModel()
{
}
public long GetMultiples(long input)
{
long total = 0;
for (long i = 1; i < input; ++i)
{
if (i % 3 == 0 || i % 5 == 0)
{
total += i;
}
};
return total;
}
}
}
Later I add a reference to the unit test project. As you can see in the following pic. I can't reference MultiplesViewModel.
So how do I add to MultiplesViewModel for the unit testing?
You must set class MultiplesViewModel
as public, otherwise you cannot use it in your unit test project.