Exemplo n.º 1
0
        public void RunAsync_IOException()
        {
            // ARRANGE
            byte[] expected = new byte[FactoryNode.Node.Size.Value];
            new Random().NextBytes(expected);
            IInternalDracoonClient c = FactoryClients.InternalDracoonClientMock();
            Stream s = new MemoryStream();
            FileDownloadCallbackMock callback = new FileDownloadCallbackMock();
            FileDownload             f        = new FileDownload(c, "id1", FactoryNode.Node, s);

            f.AddFileDownloadCallback(callback);
            Mock.Arrange(() => c.Builder.PostFileDownload(Arg.AnyLong)).Returns(FactoryRestSharp.PostFileDownloadMock(123)).OnAllThreads();
            Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiDownloadToken>(Arg.IsAny <IRestRequest>(), RequestType.PostDownloadToken, 0))
            .Returns(FactoryNode.ApiDownloadToken).OnAllThreads();
            DracoonWebClientExtension wc = Mock.Create <DracoonWebClientExtension>();

            Mock.Arrange(() => Mock.Create <DownloadProgressChangedEventArgs>().BytesReceived).IgnoreInstance().Returns(expected.Length);
            Mock.Arrange(() => c.Executor.ExecuteWebClientDownload(Arg.IsAny <WebClient>(), Arg.IsAny <Uri>(),
                                                                   RequestType.GetDownloadChunk, Arg.IsAny <Thread>(), Arg.AnyInt))
            .Raises(() => wc.DownloadProgressChanged += null, null, Mock.Create <DownloadProgressChangedEventArgs>()).Returns(expected).OnAllThreads();
            Mock.Arrange(() => s.Write(Arg.IsAny <byte[]>(), Arg.AnyInt, Arg.AnyInt)).Throws(new IOException()).OnAllThreads();
            Mock.Arrange(() => c.Builder.ProvideChunkDownloadWebClient(Arg.AnyLong, Arg.AnyLong)).Returns(wc).OnAllThreads();
            Mock.Arrange(() => callback.OnFailed(Arg.AnyString, Arg.IsAny <DracoonException>())).Occurs(1);

            // ACT
            f.RunAsync();
            while (f.RunningThread.IsAlive)
            {
            }
            s.Close();

            // ASSERT
            Mock.Assert(callback);
        }
Exemplo n.º 2
0
        public void StartDownloadFileAsync(string actionId, long nodeId, Stream output, IFileDownloadCallback callback)
        {
            FileDownload download = CreateFileDownloadInternally(actionId, nodeId, output, callback);

            download.RunAsync();
        }