public void DataValid() { // 随机产生bytes数组 // 写入文件作为测试数据 byte[] bytes = RandomData.Build(2048, 512); // 写入文件 const string targetPath = "WWWDownloader.Dat"; bool writed = RandomData.WriteToFile(bytes, TestData.testResource_path + targetPath); Assert.IsTrue(writed); WWWDownloader fd = downloader as WWWDownloader; Assert.IsNotNull(fd); bool runned = false; IEnumerator enumerator = fd.ResourceTask(targetPath + "?" + System.Environment.TickCount.ToString(), (results, error) => { Assert.IsNotNull(results); Assert.AreEqual(bytes.Length, results.Length); Assert.IsTrue(string.IsNullOrEmpty(error)); for (int i = 0; i < bytes.Length; i++) { Assert.AreEqual(bytes [i], results [i]); } // 删除文件 System.IO.File.Delete(TestData.testResource_path + targetPath); runned = true; }); bool completed = enumerator.RunCoroutineWithoutYields(int.MaxValue); Assert.IsTrue(completed); Assert.IsTrue(runned); }
public void ReadError() { WWWDownloader fd = downloader as WWWDownloader; Assert.IsNotNull(fd); bool runned = false; IEnumerator enumerator = fd.ResourceTask("NotExistFile.Dat", (bytes, error) => { Assert.IsNull(bytes); Assert.IsFalse(string.IsNullOrEmpty(error)); runned = true; }); bool completed = enumerator.RunCoroutineWithoutYields(int.MaxValue); Assert.IsTrue(completed); Assert.IsTrue(runned); }