Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize a Task<List<string>> parameter?

I'm trying to write a unit test for function but I need to initiate some variables before testing it.

The function that I need to test has a parameter Task<List<string>> list

I want to initiate this variable.

Here is what I've tried so far:

Task<List<string>> list = new List<string>();
like image 602
Saadi Avatar asked Dec 29 '16 14:12

Saadi


1 Answers

If you just want Task with empty List of string, you could call Task.FromResult like this:

Task<List<string>> list = Task.FromResult(new List<string>());
like image 192
Maksim Simkin Avatar answered Oct 20 '22 08:10

Maksim Simkin