示例#1
0
        public void RunSync_Aborted()
        {
            // 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.NonPublic.Arrange(f, "StartDownload").Throws(Mock.Create <ThreadAbortException>());
            Mock.Arrange(() => callback.OnCanceled(Arg.AnyString)).Occurs(1);

            // ACT
            f.RunSync();

            // ASSERT
            Mock.Assert(f);
            Mock.Assert(callback);
        }
示例#2
0
        public void RunAsync_IOException_Interrupted()
        {
            // 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).OnAllThreads();
            Mock.Arrange(() => c.Executor.ExecuteWebClientDownload(Arg.IsAny <WebClient>(), Arg.IsAny <Uri>(),
                                                                   RequestType.GetDownloadChunk, Arg.IsAny <Thread>(), Arg.AnyInt)).DoInstead(() => { while (f.RunningThread.IsAlive)
                                                                                                                                                      {
                                                                                                                                                      }
                                                                                                                                              }).OnAllThreads();
            Mock.Arrange(() => c.Builder.ProvideChunkDownloadWebClient(Arg.AnyLong, Arg.AnyLong)).Returns(wc).OnAllThreads();
            Mock.Arrange(() => callback.OnStarted(Arg.AnyString)).Occurs(1);
            Mock.Arrange(() => callback.OnCanceled(Arg.AnyString)).Occurs(1);


            // ACT
            f.RunAsync();
            Thread.Sleep(5000);
            f.CancelDownload();
            s.Close();

            // ASSERT
            Mock.Assert(callback);
        }