我有迭代图像的课程。
public class PictureManager
{
private int _current;
public List<BitmapImage> _images = new List<BitmapImage>(5);
public static string ImagePath = "dataImages";
public async void LoadImages()
{
_images = await GetImagesAsync();
}
public async Task<List<BitmapImage>> GetImagesAsync()
{
var files = new List<BitmapImage>();
StorageFolder picturesFolder = await KnownFolders.PicturesLibrary.GetFolderAsync("dataImages");
IReadOnlyList<IStorageItem> itemsList = await picturesFolder.GetItemsAsync();
foreach(var item in itemsList)
{
if(!(item is StorageFile)) continue;
var tempImage = new BitmapImage(new Uri(item.Path));
Debug.WriteLine(string.Format("add {0}", item.Path));
files.Add(tempImage);
}
return files;
}
}
我写了这个测试方法(我使用 nUnit):
[TestFixture]
public class PictureManagerTest
{
private PictureManager _pic;
[SetUp]
public void Init()
{
_pic = new PictureManager();
_pic.LoadImages();
}
[Test]
public void ElementOfImagesIsNotNull()
{
_pic.GetImagesAsync().ContinueWith(r =>
{
BitmapImage image = r.Result[0];
image = null;
Assert.IsNotNull(image);
});
}
}
为什么这个测试成功?