コード例 #1
0
        public async Task UpdatingSourceOnlyUpdatesDrawableTwice()
        {
            var image = new ImageStub
            {
                Background = new SolidPaintStub(Colors.Black),
                Source     = new FileImageSourceStub("red.png"),
            };

            await InvokeOnMainThreadAsync(async() =>
            {
                var handler = CreateHandler <CountedImageHandler>(image);

                await image.Wait();

                await handler.NativeView.AssertContainsColor(Colors.Red);

                handler.ImageEvents.Clear();

                image.Source = new FileImageSourceStub("blue.png");
                handler.UpdateValue(nameof(IImage.Source));

                await image.Wait();

                await handler.NativeView.AssertContainsColor(Colors.Blue);

                Assert.Equal(2, handler.ImageEvents.Count);
                Assert.Equal("Image", handler.ImageEvents[0].Member);
                Assert.Null(handler.ImageEvents[0].Value);
                Assert.Equal("Image", handler.ImageEvents[1].Member);
                Assert.IsType <UIImage>(handler.ImageEvents[1].Value);
            });
        }
コード例 #2
0
        public async Task UpdatingSourceOnlyUpdatesDrawableTwice()
        {
            var image = new ImageStub
            {
                BackgroundColor = Colors.Black,
                Source          = new FileImageSourceStub("red.png"),
            };

            await InvokeOnMainThreadAsync(async() =>
            {
                var handler = CreateHandler <CountedImageHandler>(image);

                await image.Wait();

                await handler.NativeView.AssertContainsColor(Colors.Red);

                handler.ImageEvents.Clear();

                image.Source = new FileImageSourceStub("blue.png");
                handler.UpdateValue(nameof(IImage.Source));

                await image.Wait();

                await handler.NativeView.AssertContainsColor(Colors.Blue);

                Assert.Equal(2, handler.ImageEvents.Count);
                Assert.Equal("SetImageResource", handler.ImageEvents[0].Member);
                Assert.Equal(Android.Resource.Color.Transparent, handler.ImageEvents[0].Value);
                Assert.Equal("SetImageDrawable", handler.ImageEvents[1].Member);
                Assert.IsType <BitmapDrawable>(handler.ImageEvents[1].Value);
            });
        }
コード例 #3
0
        public async Task InitializingNullSourceOnlyUpdatesNull(string colorHex)
        {
            var expectedColor = Color.FromHex(colorHex);

            var image = new ImageStub
            {
                Background = new SolidPaintStub(expectedColor),
            };

            await InvokeOnMainThreadAsync(async() =>
            {
                var handler = CreateHandler <CountedImageHandler>(image);

                await image.Wait();

                Assert.Single(handler.ImageEvents);
                Assert.Equal("Image", handler.ImageEvents[0].Member);
                Assert.Null(handler.ImageEvents[0].Value);

                await handler.NativeView.AssertContainsColor(expectedColor);
            });
        }
コード例 #4
0
        public async Task InitializingNullSourceOnlyUpdatesTransparent(string colorHex)
        {
            var expectedColor = Color.FromHex(colorHex);

            var image = new ImageStub
            {
                BackgroundColor = expectedColor,
            };

            await InvokeOnMainThreadAsync(async() =>
            {
                var handler = CreateHandler <CountedImageHandler>(image);

                await image.Wait();

                Assert.Single(handler.ImageEvents);
                Assert.Equal("SetImageResource", handler.ImageEvents[0].Member);
                Assert.Equal(Android.Resource.Color.Transparent, handler.ImageEvents[0].Value);

                await handler.NativeView.AssertContainsColor(expectedColor);
            });
        }
コード例 #5
0
        private static void ProcessImage(string imagePath, Action <string> OnFail)
        {
            IDisposable img = new ImageStub();

            try
            {
                img = Image.FromFile(imagePath);
            }
            catch (Exception e)
            {
                lock (Locker)
                {
                    CorruptedFileListOutput.WriteLine("{0}{1}", imagePath, Opts.Verbose ? ":" + e.Message : "");
                    FailedImages++;
                }

                OnFail(imagePath);
            }
            finally
            {
                img.Dispose();
            }
        }
コード例 #6
0
        public async Task InitializingSourceOnlyUpdatesImageOnce()
        {
            var image = new ImageStub
            {
                BackgroundColor = Colors.Black,
                Source          = new FileImageSourceStub("red.png"),
            };

            await InvokeOnMainThreadAsync(async() =>
            {
                var handler = CreateHandler <CountedImageHandler>(image);

                await image.Wait();

                await handler.NativeView.AssertContainsColor(Colors.Red);

                Assert.Equal(2, handler.ImageEvents.Count);
                Assert.Equal("Image", handler.ImageEvents[0].Member);
                Assert.Null(handler.ImageEvents[0].Value);
                Assert.Equal("Image", handler.ImageEvents[1].Member);
                Assert.IsType <UIImage>(handler.ImageEvents[1].Value);
            });
        }