Esempio n. 1
0
        public async Task TestLoadSvgImage_NullArgument()
        {
            // run
            var svg = await SvgDataResolver.LoadSvgImage(null);

            // check
            Assert.IsNull(svg, "loaded SKSvg object must be null");
        }
Esempio n. 2
0
        public void TestStreamImageSource_StreamFactoryProducesNullObject()
        {
            // set up
            var imageSource = ImageSource.FromStream(
                (ct) => Task.FromResult <Stream>(null));

            // run + check
            Assert.ThrowsAsync <InvalidOperationException>(
                async() => await SvgDataResolver.LoadSvgImage(imageSource),
                "null Stream object must throw an exception");
        }
Esempio n. 3
0
        public void TestStreamImageSource_StreamFactoryProducesNullStream()
        {
            // set up
            var imageSource = ImageSource.FromStream(
                (ct) => Task.FromResult(Stream.Null));

            // run
            Assert.ThrowsAsync <InvalidOperationException>(
                async() => await SvgDataResolver.LoadSvgImage(imageSource),
                "specifying Stream.Null must throw an exception");
        }
Esempio n. 4
0
        public void TestUriImageSource_InvalidUriScheme()
        {
            // set up
            var uri         = new Uri("https://raw.githubusercontent.com/vividos/Svg.Skia.Forms/main/samples/images/toucan.svg");
            var imageSource = ImageSource.FromUri(uri);

            // run + check
            Assert.ThrowsAsync <NotSupportedException>(
                async() => await SvgDataResolver.LoadSvgImage(imageSource),
                "invalid URI schema must throw an exception");
        }
Esempio n. 5
0
        public void TestUriImageSource_DataUriInvalidText()
        {
            // set up
            var uri         = new Uri("data:image/abc+xml;base65,aaaaaaaaaa");
            var imageSource = ImageSource.FromUri(uri);

            // run + check
            Assert.ThrowsAsync <FormatException>(
                async() => await SvgDataResolver.LoadSvgImage(imageSource),
                "invalid data: URI must throw an exception");
        }
Esempio n. 6
0
        public void TestStreamImageSource_StreamFactoryIsNull()
        {
            // set up
            var imageSource = new StreamImageSource
            {
                Stream = null
            };

            // run
            Assert.ThrowsAsync <InvalidOperationException>(
                async() => await SvgDataResolver.LoadSvgImage(imageSource),
                "specifying null Stream factory must throw an exception");
        }
Esempio n. 7
0
        public async Task TestFileImageSource_FileImageSource()
        {
            var testPath    = Path.GetDirectoryName(this.GetType().Assembly.Location);
            var imageSource = ImageSource.FromFile(
                Path.Combine(testPath, "Assets/cog-outline-as-content.svg"));

            // run
            var svg = await SvgDataResolver.LoadSvgImage(imageSource);

            // check
            Assert.IsNotNull(svg, "loaded SKSvg object must be non-null");
            Assert.IsNotNull(svg.Picture, "SKPicture object must be non-null");
            Assert.IsNotNull(svg.Picture.CullRect, "CullRect must be non-null");
            Assert.IsFalse(svg.Picture.CullRect.IsEmpty, "CullRect must not be empty");
        }
Esempio n. 8
0
        public async Task TestUriImageSource_DataUriPlainText()
        {
            // set up
            var uri         = new Uri(SvgConstants.DataUriPlainPrefix + SvgTestImages.TestSvgImageText);
            var imageSource = ImageSource.FromUri(uri);

            // run
            var svg = await SvgDataResolver.LoadSvgImage(imageSource);

            // check
            Assert.IsNotNull(svg, "loaded SKSvg object must be non-null");
            Assert.IsNotNull(svg.Picture, "SKPicture object must be non-null");
            Assert.IsNotNull(svg.Picture.CullRect, "CullRect must be non-null");
            Assert.IsFalse(svg.Picture.CullRect.IsEmpty, "CullRect must not be empty");
        }
Esempio n. 9
0
        public async Task TestStreamImageSource_MemoryStream()
        {
            // set up
            var imageBytes = System.Text.Encoding.UTF8.GetBytes(
                SvgTestImages.TestSvgImageText);

            var imageSource = ImageSource.FromStream(
                (ct) => Task.FromResult <Stream>(new MemoryStream(imageBytes)));

            // run
            var svg = await SvgDataResolver.LoadSvgImage(imageSource);

            // check
            Assert.IsNotNull(svg, "loaded SKSvg object must be non-null");
            Assert.IsNotNull(svg.Picture, "SKPicture object must be non-null");
            Assert.IsNotNull(svg.Picture.CullRect, "CullRect must be non-null");
            Assert.IsFalse(svg.Picture.CullRect.IsEmpty, "CullRect must not be empty");
        }