Exemplo n.º 1
0
            public void ShouldSetTheProperties()
            {
                var message = new ImagemapSize(100, 200);

                Assert.AreEqual(100, message.Width);
                Assert.AreEqual(200, message.Height);
            }
            public void ShouldThrowExceptionWhenValueIsNegative()
            {
                var size = new ImagemapSize();

                ExceptionAssert.Throws <InvalidOperationException>("The width should be at least 1.", () =>
                {
                    size.Width = -1;
                });
            }
        public void Height_Zero_ThrowsException()
        {
            ImagemapSize area = new ImagemapSize();

            ExceptionAssert.Throws <InvalidOperationException>("The height should be at least 1.", () =>
            {
                area.Height = 0;
            });
        }
        public void Width_Zero_ThrowsException()
        {
            ImagemapSize area = new ImagemapSize();

            ExceptionAssert.Throws <InvalidOperationException>("The width should be at least 1.", () =>
            {
                area.Width = 0;
            });
        }
            public void ShouldThrowExceptionWhenValueIsZero()
            {
                var size = new ImagemapSize();

                ExceptionAssert.Throws <InvalidOperationException>("The height should be at least 1.", () =>
                {
                    size.Height = 0;
                });
            }
Exemplo n.º 6
0
            public void ShouldNotThrowExceptionWhenValid()
            {
                var size = new ImagemapSize()
                {
                    Height = 1,
                    Width  = 1
                };

                size.Validate();
            }
            public void ShouldThrowExceptionWhenHeightIsNotSet()
            {
                var size = new ImagemapSize()
                {
                    Width = 1
                };

                ExceptionAssert.Throws <InvalidOperationException>("The height should be at least 1.", () =>
                {
                    ImagemapSize.Convert(size);
                });
            }
            public void ShouldNotConvertInstanceToNewInstance()
            {
                var size = new ImagemapSize()
                {
                    Width  = 100,
                    Height = 200
                };

                var imagemapSize = ImagemapSize.Convert(size);

                Assert.AreNotEqual(size, imagemapSize);
            }
Exemplo n.º 9
0
            public void ShouldThrowExceptionWhenWidthIsNotSet()
            {
                var size = new ImagemapSize()
                {
                    Height = 1
                };

                ExceptionAssert.Throws <InvalidOperationException>("The width should be at least 1.", () =>
                {
                    size.Validate();
                });
            }
Exemplo n.º 10
0
        public void Constructor_SerializedCorrectly()
        {
            ImagemapSize size = new ImagemapSize()
            {
                Width  = 10,
                Height = 20
            };

            string serialized = JsonConvert.SerializeObject(size);

            Assert.AreEqual(@"{""width"":10,""height"":20}", serialized);
        }
Exemplo n.º 11
0
            public void ShouldCreateSerializeableObject()
            {
                var size = new ImagemapSize()
                {
                    Width  = 10,
                    Height = 20
                };

                var serialized = JsonConvert.SerializeObject(size);

                Assert.AreEqual(@"{""width"":10,""height"":20}", serialized);
            }
Exemplo n.º 12
0
        private async Task ReplyImagemapAsync(string replyToken, string messageId, string blobDirectoryName)
        {
            var imageStream = await MessagingClient.GetContentStreamAsync(messageId);

            var image = System.Drawing.Image.FromStream(imageStream);

            using (var g = Graphics.FromImage(image))
            {
                g.DrawLine(Pens.Red, image.Width / 2, 0, image.Width / 2, image.Height);
                g.DrawLine(Pens.Red, 0, image.Height / 2, image.Width, image.Height / 2);
            }

            var uri = await UploadImageAsync(1040);

            await UploadImageAsync(700);
            await UploadImageAsync(460);
            await UploadImageAsync(300);
            await UploadImageAsync(240);

            var   imageSize  = new ImagemapSize(1024, (int)(1040 * (double)image.Height / image.Width));
            var   areaWidth  = imageSize.Width / 2;
            var   areaHeight = imageSize.Height / 2;
            Video video      = null;
            var   videoUrl   = BlobStorage.ListBlobUri(blobDirectoryName).FirstOrDefault(x => x.ToString().EndsWith("video.mp4"));

            if (videoUrl != null)
            {
                video = new Video(videoUrl.ToString(), videoUrl.ToString().Replace("video.mp4", "300"),
                                  new ImagemapArea(areaWidth / 2, areaHeight / 2, areaWidth, areaHeight),
                                  new ExternalLink("https://google.com", "google"));
            }
            var imagemapMessage = new ImagemapMessage(uri.ToString().Replace("/1040", ""),
                                                      "Sample Imagemap",
                                                      imageSize,
                                                      new IImagemapAction[] {
                new MessageImagemapAction(new ImagemapArea(0, 0, areaWidth, areaHeight), "Area Top-Left"),
                new MessageImagemapAction(new ImagemapArea(areaWidth, 0, areaWidth, areaHeight), "Area Top-Right"),
                new MessageImagemapAction(new ImagemapArea(0, areaHeight, areaWidth, areaHeight), "Area Bottom-Left"),
                new MessageImagemapAction(new ImagemapArea(areaWidth, areaHeight, areaWidth, areaHeight), "Area Bottom-Right"),
            },
                                                      video: video);

            await MessagingClient.ReplyMessageAsync(replyToken, new[] { imagemapMessage });

            async Task <Uri> UploadImageAsync(int baseSize)
            {
                var img = image.GetThumbnailImage(baseSize, image.Height * baseSize / image.Width, () => false, IntPtr.Zero);

                return(await BlobStorage.UploadImageAsync(img, blobDirectoryName, baseSize.ToString()));
            }
        }
Exemplo n.º 13
0
        private async Task ReplyImagemapAsync(string replyToken, string messageId, string blobDirectoryName)
        {
            var imageStream = await MessagingClient.GetContentStreamAsync(messageId);

            var image = Image.FromStream(imageStream);

            using (var g = Graphics.FromImage(image))
            {
                g.DrawLine(Pens.Red, image.Width / 2, 0, image.Width / 2, image.Height);
                g.DrawLine(Pens.Red, 0, image.Height / 2, image.Width, image.Height / 2);
            }

            var uri = await UploadImageAsync(1040);

            await UploadImageAsync(700);
            await UploadImageAsync(460);
            await UploadImageAsync(300);
            await UploadImageAsync(240);

            var imageSize       = new ImagemapSize(1024, (int)(1040 * (double)image.Height / image.Width));
            var areaWidth       = imageSize.Width / 2;
            var areaHeight      = imageSize.Height / 2;
            var imagemapMessage = new ImagemapMessage(uri.ToString().Replace("/1040", ""),
                                                      "Sample Imagemap",
                                                      imageSize,
                                                      new IImagemapAction[] {
                new MessageImagemapAction(new ImagemapArea(0, 0, areaWidth, areaHeight), "Area Top-Left"),
                new MessageImagemapAction(new ImagemapArea(areaWidth, 0, areaWidth, areaHeight), "Area Top-Right"),
                new MessageImagemapAction(new ImagemapArea(0, areaHeight, areaWidth, areaHeight), "Area Bottom-Left"),
                new MessageImagemapAction(new ImagemapArea(areaWidth, areaHeight, areaWidth, areaHeight), "Area Bottom-Right"),
            });

            await MessagingClient.ReplyMessageAsync(replyToken, new[] { imagemapMessage });

            async Task <Uri> UploadImageAsync(int baseSize)
            {
                var img = image.GetThumbnailImage(baseSize, image.Height * baseSize / image.Width, () => false, IntPtr.Zero);

                return(await BlobStorage.UploadImageAsync(img, blobDirectoryName + "/" + messageId, baseSize.ToString()));
            }
        }