public void SetUp() { if (Directory.Exists(SavePathRoot)) { Directory.Delete(SavePathRoot, true); } if (!Directory.Exists(SavePathRoot)) { Directory.CreateDirectory(SavePathRoot); } m_DirectoryInfo = new DirectoryInfo(SavePathRoot); m_ObjectPoolModule = new RefPoolModule(); m_ObjectPoolModule.Init(); m_DownloadModule = new DownloadModule(); m_DownloadModule.ChunkSizeToSave = 32; m_DownloadModule.ConcurrentDownloadCountLimit = 2; m_DownloadModule.TempFileExtension = ".tmp"; m_DownloadModule.Timeout = 10000f; m_DownloadTaskPool = Substitute.For <IDownloadTaskPool>(); m_DownloadTaskPool.Acquire().Returns(callInfo => new DownloadTask()); m_DownloadTaskImplFactory = new MockDownloadTaskImplFactory(); var mockDownloadTaskImplFactory = m_DownloadTaskImplFactory as MockDownloadTaskImplFactory; mockDownloadTaskImplFactory.TaskShouldNeverStart = false; m_DownloadModule.DownloadTaskPool = m_DownloadTaskPool; m_DownloadModule.RefPoolModule = m_ObjectPoolModule; m_DownloadModule.DownloadTaskImplFactory = m_DownloadTaskImplFactory; m_DownloadModule.Init(); }
public void TestSimpleSuccessfulDownload() { m_DownloadTaskPool.Acquire().Returns(anyCallInfo => { return(new MockSuccessfulDownloadTask(1f)); }); int successCount = 0; int failureCount = 0; int taskId = m_DownloadModule.StartDownloading(new DownloadTaskInfo("url", "savePath", new DownloadCallbackSet { OnSuccess = (theTaskId, taskInfo) => { ++successCount; }, OnFailure = (theTaskId, taskInfo, errorCode, errorMessage) => { ++failureCount; } })); Assert.AreEqual(0, successCount); Assert.AreEqual(0, failureCount); m_DownloadModule.Update(new TimeStruct(0f, 0f, 0f, 0f)); m_DownloadModule.Update(new TimeStruct(1.1f, 1.1f, 0f, 0f)); m_DownloadModule.Update(new TimeStruct(.1f, 0f, 0f, 0f)); Assert.AreEqual(1, successCount); Assert.AreEqual(0, failureCount); }