Beispiel #1
0
// ReSharper disable InconsistentNaming
        public void ProgressFileDownloader_Download_Completed_HasNoError_ExpectSuccessAndShutDown()
// ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var webClient        = new Mock <IDev2WebClient>();
            var file             = new Mock <IFile>();
            var crytpto          = new Mock <ICryptoProvider>();
            var progressNotifier = new Mock <IProgressNotifier>();

            ProgressFileDownloader.GetProgressDialogViewModel = (x, y) => progressNotifier.Object;
            var ax     = new ProgressFileDownloader(webClient.Object, file.Object, crytpto.Object);
            var stream = new MemoryStream();

            stream.WriteByte(1);
            stream.WriteByte(2);
            stream.WriteByte(3);
            crytpto.Setup(a => a.ComputeHash(It.IsAny <Stream>())).Returns(new byte[] { 0, 1, 2 });
            file.Setup(a => a.Open("bob", FileMode.Open)).Returns(new MemoryStream());
            bool shutdown = false;

            //------------Execute Test---------------------------
            ax.Download(new Uri("http://bob"), "dave", false, "moo", "012");
            ax.ShutDownAction = s => shutdown = true;
            webClient.Raise(a => a.DownloadFileCompleted += null, new AsyncCompletedEventArgs(null, false, "moo"));

            //------------Assert Results-------------------------
            file.Verify(a => a.Move("dave", "moo"));

            Assert.IsTrue(shutdown);
            Assert.IsFalse(ax.IsBusyDownloading);
        }
Beispiel #2
0
        // ReSharper disable InconsistentNaming
        public void ProgressFileDownloader_Download_Cancel_HasNoError_ExpectSuccessAndFileDeleted()
        // ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var webClient = new Mock <IDev2WebClient>();
            var file      = new Mock <IFile>();
            var crytpto   = new Mock <ICryptoProvider>();

            ProgressFileDownloader.GetProgressDialogViewModel = ((a, b) => new Mock <IProgressNotifier>().Object);
            var ax     = new ProgressFileDownloader(webClient.Object, file.Object, crytpto.Object);
            var stream = new MemoryStream();

            stream.WriteByte(1);
            stream.WriteByte(2);
            stream.WriteByte(3);
            crytpto.Setup(a => a.ComputeHash(It.IsAny <Stream>())).Returns(new byte[] { 0, 1, 2 });
            file.Setup(a => a.Open("bob", FileMode.Open)).Returns(new MemoryStream());


            //------------Execute Test---------------------------
            ax.Download(new Uri("http://bob"), "dave", false, "moo", "012");
            ax.Cancel();

            //------------Assert Results-------------------------
            file.Verify(a => a.Delete("dave"), Times.Never());
            webClient.Verify(a => a.CancelAsync());
        }
Beispiel #3
0
// ReSharper disable InconsistentNaming
        public void ProgressFileDownloader_UnitTest_Download_AsyncDownloadStartedAndProgressDialogShown()
// ReSharper restore InconsistentNaming
        {
            //init
            var mockWebClient = new Mock <IDev2WebClient>();

            mockWebClient.Setup(c => c.DownloadFileAsync(It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <string>())).Verifiable();
            var mockProgressDialog = new Mock <IProgressDialog>();

            mockProgressDialog.Setup(c => c.Show()).Verifiable();
            ProgressFileDownloader.GetProgressDialogViewModel = (x, y) => mockProgressDialog.Object;
            var testProgressFileDownloader = new ProgressFileDownloader(mockWebClient.Object, new Mock <IFile>().Object, new Mock <ICryptoProvider>().Object);

            //exe
            testProgressFileDownloader.Download(It.IsAny <Uri>(), It.IsAny <string>(), false, It.IsAny <string>(), "");

            //assert
            mockWebClient.Verify(c => c.DownloadFileAsync(It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <string>()));
        }