Unit test is failing when ContinueWith is used with System.Threading.Tasks.Task
The fact here is that you are skipping your continuation by passing the valid task instead of It.IsAny<Task>
. The one example is to do something like this
.NET < v4.6
mock_IServicesFacade
.Setup(sf => sf.SynchronizeDataset(It.IsAny<string>()))
.Returns(Task.FromResult(true)))
.NET >= v4.6
mock_IServicesFacade
.Setup(sf => sf.SynchronizeDataset(It.IsAny<string>()))
.Returns(Task.CompletedTask))
You can even try to make your continuation with option TaskContinuationOptions.OnlyOnFaulted
because you are only interested in IsFaulted
scenario.
Be aware that you are not testing continuation part only skipping it. If you really want to test\verify continuation part be careful with it. It seems that your logic is service side logic so there TaskScheduler
will use default SynchronizationContext
and schedule continuation on the ThreadPool
thread. Of course this is executed within unit test runner context which is the same. Basically your tests could finish even before continuation task is executed.