Ejemplo n.º 1
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());
        }
Ejemplo n.º 2
0
        protected override void OnExit(ExitEventArgs e)
        {
            Tracker.Stop();

            // this is already handled ;)
            if (_mainViewModel != null)
            {
                _mainViewModel.PersistTabs(true);
            }
            ProgressFileDownloader.PerformCleanup(new DirectoryWrapper(), GlobalConstants.VersionDownloadPath, new FileWrapper());
            HasShutdownStarted = true;
            DebugDispatcher.Instance.Shutdown();
            Browser.Shutdown();
            try
            {
                base.OnExit(e);
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch
            // ReSharper restore EmptyGeneralCatchClause
            {
                // Best effort ;)
            }

            ForceShutdown();
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        protected override void OnExit(ExitEventArgs e)
        {
            var applicationTracker = CustomContainer.Get <IApplicationTracker>();

            //Stop the action tracking
            applicationTracker?.DisableApplicationTracker();

            SplashView.CloseSplash(true);

            // this is already handled ;)
            _shellViewModel?.PersistTabs(true);
            ProgressFileDownloader.PerformCleanup(new DirectoryWrapper(), GlobalConstants.VersionDownloadPath, new FileWrapper());
            HasShutdownStarted = true;
            DebugDispatcher.Instance.Shutdown();
            try
            {
                base.OnExit(e);
            }

            catch

            {
                // Best effort ;)
            }

            ForceShutdown();
        }
Ejemplo n.º 5
0
        public void ProgressFileDownloader_Ctor_AssertCorrectConstruction()
        {
            //------------Setup for test--------------------------
            var webClient = new Mock <IDev2WebClient>();
            var file      = new Mock <IFile>();

#pragma warning disable 168
            var a = new ProgressFileDownloader(webClient.Object, file.Object);

#pragma warning restore 168
        }
Ejemplo n.º 6
0
        public void ProgressFileDownloader_Cleanup_OnlyTempFilesDeleted()
        {
            //------------Setup for test--------------------------
            var dir = new Mock <IDirectory>();

            dir.Setup(a => a.GetFiles("c:\bob")).Returns(new[] { "tmpa", "tmpb", "c" });
            var file = new Mock <IFile>();

            ProgressFileDownloader.PerformCleanup(dir.Object, "c:\bob", file.Object);
            file.Verify(a => a.Delete(It.IsAny <string>()), Times.Exactly(2));
        }
Ejemplo n.º 7
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>()));
        }
Ejemplo n.º 8
0
        public void ProgressFileDownloader_PerformCheckSum_VerifyCryptoProviderCalledAndStringsCompared_ExpectFalseReturned()
        {
            //------------Setup for test--------------------------
            var webClient = new Mock <IDev2WebClient>();
            var file      = new Mock <IFile>();
            var crytpto   = new Mock <ICryptoProvider>();
            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());

            var ax = new ProgressFileDownloader(webClient.Object, file.Object, crytpto.Object);

            //------------Execute test--------------------------
            Assert.IsFalse(ax.PerformCheckSum("bob", "124"));
        }
Ejemplo n.º 9
0
        protected override void OnExit(ExitEventArgs e)
        {
            SplashView.CloseSplash(true);

            // this is already handled ;)
            _shellViewModel?.PersistTabs(true);
            ProgressFileDownloader.PerformCleanup(new DirectoryWrapper(), GlobalConstants.VersionDownloadPath, new FileWrapper());
            HasShutdownStarted = true;
            DebugDispatcher.Instance.Shutdown();
            try
            {
                base.OnExit(e);
            }
            catch
            {
                // Best effort ;)
            }

            ForceShutdown();
        }