I have simple class with simple method like this:
partial class SimpleClass
{
private readonly ISimpleManager _simpleManager;
public SimpleClass(ISimpleManager simpleManager)
{
_simpleManager = simpleManager;
}
public async void SimpleMethod()
{
IsInProgress = true;
DoSomeWork();
Task<int> hardWork0Task = _simpleManager.DoHardWork0Async();
Task<int> hardWork1Task = _simpleManager.DoHardWork1Async();
DoIndependentWork();
int hardWork0Result = await hardWork0Task.ConfigureAwait(false);
DoDependentWork(hardWork0Result);
int hardWork1Result = await hardWork1Task.ConfigureAwait(false);
DoDependentWork(hardWork1Result);
IsInProgress = false;
}
}
Let's assume that property IsInProgress is just bool property notifying GUI about its state to allow refreshing progress bar. DoSomeWork, DoDependentWork and DoIndependentWork are some methods using or not results of hard work.
ISimpleManager is the most simple interface you can imagine in this case:
interface ISimpleManager
{
Task<int> DoHardWork0Async();
Task<int> DoHardWork1Async();
}
I have to write some unit tests using Moq and NUnit. How can I write unit tests for this case? I would like to check if state of IsInProgress property hasn't changed to false during entire code running asynchronously with GUI. Does it make sense? Is it possible? What if my async method returns Task or generic Task<T>? What if I configure awaits for true?
Aucun commentaire:
Enregistrer un commentaire