// 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>())); }
public void ProgressFileDownloader_Ctor_AssertCorrectConstruction() { //------------Setup for test-------------------------- var webClient = new Mock<IDev2WebClient>(); var file = new Mock<IFile>(); var crytpto = new Mock<ICryptoProvider>(); #pragma warning disable 168 var a = new ProgressFileDownloader(webClient.Object, file.Object, crytpto.Object); #pragma warning restore 168 }
public void ProgressFileDownloader_PerformCheckSum_VerifyCryptoProviderCalledAndStringsCompared_ExpectTrueReturned() { //------------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()); #pragma warning disable 168 var ax = new ProgressFileDownloader(webClient.Object, file.Object, crytpto.Object); #pragma warning restore 168 //------------Execute test-------------------------- Assert.IsTrue( ax.PerformCheckSum("bob", "012")); }
public void ProgressFileDownloader_Download_Complted_HasNoError_ExpectSuccess() { //------------Setup for test-------------------------- var webClient = new Mock<IDev2WebClient>(); var progressNotifier = new Mock<IProgressNotifier>(); progressNotifier.Setup(a => a.Close()).Verifiable(); var file = new Mock<IFile>(); var crytpto = new Mock<ICryptoProvider>(); 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()); //------------Execute Test--------------------------- ax.Download(new Uri("http://bob"), "dave",true,"moo","012"); webClient.Raise(a=>a.DownloadFileCompleted+= null,new AsyncCompletedEventArgs(null,false,"moo" )); //------------Assert Results------------------------- file.Verify(a=>a.Move("dave","moo")); progressNotifier.Verify(a=>a.Close(), Times.Once()); Assert.IsFalse(ax.IsBusyDownloading); }
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()); }
// 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()); }