Exemple #1
0
        public void TestImageSourceToNullCancelsLoading()
        {
            var image             = new ImageButton();
            var mockImageRenderer = new MockImageRenderer(image);
            var loader            = new UriImageSource {
                Uri = new Uri("http://www.public-domain-image.com/free-images/miscellaneous/big-high-border-fence.jpg")
            };

            image.Source = loader;
            Assert.IsTrue(image.IsLoading);
            image.Source = null;
            Assert.IsFalse(image.IsLoading);
            Assert.IsTrue(cancelled);
        }
Exemple #2
0
        public void TestImageSourceToNullCancelsLoading()
        {
            var cancelled = false;

            var image             = new ImageButton();
            var mockImageRenderer = new MockImageRenderer(image);
            var loader            = new StreamImageSource {
                Stream = GetStreamAsync
            };

            image.Source = loader;
            Assert.IsTrue(image.IsLoading);

            image.Source = null;
            mockImageRenderer.CompletionSource.Task.Wait();
            Assert.IsFalse(image.IsLoading);
            Assert.IsTrue(cancelled);

            async Task <Stream> GetStreamAsync(CancellationToken cancellationToken)
            {
                try
                {
                    await Task.Delay(5000, cancellationToken);
                }
                catch (TaskCanceledException ex)
                {
                    cancelled = true;
                    throw ex;
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    cancelled = true;
                    throw new TaskCanceledException();
                }

                var stream = typeof(ImageTests).Assembly.GetManifestResourceStream("dummy");

                return(stream);
            }
        }
Exemple #3
0
		public void TestImageSourceToNullCancelsLoading ()
		{
			var image = new Image ();
			var mockImageRenderer = new MockImageRenderer (image);
			var loader = new UriImageSource { Uri = new Uri ("http://www.public-domain-image.com/free-images/miscellaneous/big-high-border-fence.jpg") };
			image.Source = loader;
			Assert.IsTrue (image.IsLoading);
			image.Source = null;
			Assert.IsFalse (image.IsLoading);
			Assert.IsTrue (cancelled);
		}