public async Task UpdateSourceImageAfterDownloading() { var imageDownloaderViewModel = new ImageDownloaderViewModel(new FileDownloader(), new ViewFactory()); imageDownloaderViewModel.Url = @"http://lifeandjoy.ru/uploads/posts/2015-07/1438256217_lifeandjoy.ru_02.jpg"; await imageDownloaderViewModel.StartDownloadAsync(); Assert.IsNotNull(imageDownloaderViewModel.SourceImage); }
public async Task CreateExceptionMessageWhenDownloadFailed() { var mockFileDownLoader = Substitute.For <IFileDownloader>(); mockFileDownLoader .Download(Arg.Any <string>(), Arg.Any <Action <double> >()) .Throws(new WebException()); var isCReated = false; var mockViewFactory = Substitute.For <IViewFactory>(); mockViewFactory .When(x => x.CreateExceptionViewDialogAsync(Arg.Any <string>())) .Do(_ => isCReated = true); var imageDownloaderViewModel = new ImageDownloaderViewModel(mockFileDownLoader, mockViewFactory); await imageDownloaderViewModel.StartDownloadAsync(); Assert.That(isCReated, Is.True); }
public async Task<double> CalculateTotalProgressWhenTwoDownloading(double firstProgress, double secondProgress) { var mockfirtFileDownloader = Substitute.For<IFileDownloader>(); mockfirtFileDownloader .When(x => x.Download(Arg.Any<string>(), Arg.Any<Action<double>>())) .Do(x => x.Arg<Action<double>>().Invoke(firstProgress)); var mockSecondFileDownloader = Substitute.For<IFileDownloader>(); mockSecondFileDownloader .When(x => x.Download(Arg.Any<string>(), Arg.Any<Action<double>>())) .Do(x => x.Arg<Action<double>>().Invoke(secondProgress)); var firstImageDownloaderViewModel = new ImageDownloaderViewModel(mockfirtFileDownloader, new ViewFactory()); var secondImageDownloaderViewModel = new ImageDownloaderViewModel(mockSecondFileDownloader, new ViewFactory()); var mainViewModel = new MainViewModel(firstImageDownloaderViewModel, secondImageDownloaderViewModel, new ImageDownloaderViewModel(new FileDownloader(), new ViewFactory())); await Task.WhenAll(firstImageDownloaderViewModel.StartDownloadAsync(), secondImageDownloaderViewModel.StartDownloadAsync()); return mainViewModel.TotalDownloadingProgress; }