Have a unit test that tests that navigation is only allowed if Jobs.Count > 0
.
GetJobsAsync()
is called during construction and clears the Jobs list if not null (gets fresh list each time it is called). It appears that the Jobs list is cleared after I manually add a new job as a condition for the unit test to pass. How do I get this timing correct so that the Jobs list isn't cleared during the running of the test?
In MyClass constructor:
this.GetJobsAsync();
GetJobsAsync:
private async void GetJobsAsync()
{
var jobs = await this.dataService.GetJobs();
if (jobs != null)
{
this.Jobs.Clear();
foreach (var job in jobs)
{
this.Jobs.Add(new JobViewModel(job));
}
}
// have the select job command rerun its condition
this.SelectJobCommand.RaiseCanExecuteChanged();
}
Unit test (must have at least one job for navigation, Jobs is cleared after job is added):
var vm = new MyClass();
vm.Jobs.Add(new JobVM(new JobModel()));
vm.SelectJobCommand.Execute(null);
Assert.AreEqual(
NavigationKeys.WizardJob,
this.navigationService.CurrentPageKey);