Cancel() public method

public Cancel ( ) : void
return void
コード例 #1
0
        public void ProgressFileDownloader_Download_Cancel_HasNoError_ExpectSuccessAndFileDeleted()
        {
            //------------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());
        }
コード例 #2
0
        // ReSharper disable InconsistentNaming
        public void ProgressFileDownloader_Download_Cancel_HasNoErrorFileDoesNotExist_ExpectSuccess()
        // 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());
            file.Setup(a => a.Exists("dave")).Returns(true);
            //------------Execute Test---------------------------
            ax.Download(new Uri("http://bob"), "dave", false, "moo", "012");
            ax.Cancel();

            //------------Assert Results-------------------------
            file.Verify(a => a.Delete("dave")); // once because it exists and then when cancelling
            webClient.Verify(a=>a.CancelAsync());
      
            
        }