public void NullValueReturnsNull()
        {
            var    converter = new ByteArrayToImageSourceConverter();
            object value     = null;
            var    ex        = Record.Exception(() => value = converter.Convert(null, typeof(ImageSource), null, CurrentCulture));

            Assert.Null(ex);
            Assert.Null(value);
        }
コード例 #2
0
        public void ByteArrayToImageSourceConverter()
        {
            var byteArray = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 };

            var memoryStream = new MemoryStream(byteArray);

            var expectedValue = ImageSource.FromStream(() => memoryStream);

            var byteArrayToImageSourceConverter = new ByteArrayToImageSourceConverter();

            var result = byteArrayToImageSourceConverter.Convert(byteArray, typeof(ByteArrayToImageSourceConverter), null, CultureInfo.CurrentCulture);

            Assert.IsTrue(StreamEquals(GetStreamFromImageSource((ImageSource?)result), memoryStream));
        }
コード例 #3
0
        public async Task AddImageCommand()
        {
            FileData filedata = await CrossFilePicker.Current.PickFile();

            //Getting the filename and the data info from the image picked
            FileName   = filedata.FileName;
            _imageData = filedata.DataArray;

            //Convert from data info to image
            ByteArrayToImageSourceConverter converter = new ByteArrayToImageSourceConverter();

            //Image that will be displayed
            ImgSource = converter.Convert(_imageData, null, null, culture: System.Globalization.CultureInfo.CurrentCulture);
        }
        public async Task ConvertedImageSourceReturnsSameImage()
        {
            var image     = GetAvantiPointLogo();
            var converter = new ByteArrayToImageSourceConverter();
            StreamImageSource imageSource = null;
            var ex = Record.Exception(() => imageSource = (StreamImageSource)converter.Convert(image, typeof(ImageSource), null, CurrentCulture));

            Assert.Null(ex);
            Assert.NotNull(imageSource);
            var stream = await imageSource.Stream(CancellationToken.None);

            var convertedStream = ReadFully(stream);

            Assert.Equal(image, convertedStream);
        }
コード例 #5
0
        public void InvalidConverterValuesReturnsNull(object value)
        {
            var byteArrayToImageSourceConverter = new ByteArrayToImageSourceConverter();

            Assert.Throws <ArgumentException>(() => byteArrayToImageSourceConverter.Convert(value, typeof(ByteArrayToImageSourceConverter), null, CultureInfo.CurrentCulture));
        }