示例#1
0
        public void TestSimpleDownload()
        {
            string fileName   = "simple_file";
            long   size       = 100L;
            float  timeNeeded = 1f;
            string savePath   = Path.Combine(m_DirectoryInfo.FullName, fileName);
            var    mockDownloadTaskImplFactory = m_DownloadTaskImplFactory as MockDownloadTaskImplFactory;

            mockDownloadTaskImplFactory.TaskSize       = size;
            mockDownloadTaskImplFactory.TaskTimeNeeded = timeNeeded;
            int successCount = 0;
            int failureCount = 0;

            m_DownloadModule.StartDownloading(new DownloadTaskInfo(
                                                  urlStr: "urlStr",
                                                  savePath: savePath,
                                                  size: size,
                                                  crc32: null,
                                                  callbackSet: new DownloadCallbackSet
            {
                OnSuccess = (taskId, taskInfo) => { ++successCount; },
                OnFailure = (taskId, taskInfo, errorCode, errorMessage) => { ++failureCount; }
            },
                                                  context: null
                                                  ));

            for (float time = 0f; time < timeNeeded + 0.5f; time += 0.1f)
            {
                m_DownloadModule.Update(new TimeStruct(.1f, .1f, time, time));
            }

            Assert.AreEqual(0, failureCount);
            Assert.AreEqual(1, successCount);
            Assert.IsTrue(File.Exists(savePath));
            var bytes = File.ReadAllBytes(savePath);

            CheckBufferContent(size, bytes);
        }
        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);
        }