Ejemplo n.º 1
0
        public void TooWideImageIsRejected()
        {
            // Arrange
            const string fileName = "Data/Gifs/TooWide.gif";

            // Act
            var result = GifValidator.Validate(fileName);

            // Assert
            Assert.AreEqual(GifValidator.ValidationResult.TooWide, result);
        }
Ejemplo n.º 2
0
        public void ValidImageIsAccepted()
        {
            // Arrange
            const string fileName = "Data/Gifs/Valid.gif";

            // Act
            var result = GifValidator.Validate(fileName);

            // Assert
            Assert.AreEqual(GifValidator.ValidationResult.Ok, result);
        }
Ejemplo n.º 3
0
        public void ImageWithTooManyPixelsIsRejected()
        {
            // Arrange
            const string fileName = "Data/Gifs/TooManyPixels.gif";

            // Act
            var result = GifValidator.Validate(fileName);

            // Assert
            Assert.AreEqual(GifValidator.ValidationResult.TooManyPixels, result);
        }
Ejemplo n.º 4
0
        private async Task AttachImage(string fileName)
        {
            IsSending = true;

            if (Path.GetExtension(fileName) == ".gif")
            {
                if (GifValidator.Validate(fileName) != GifValidator.ValidationResult.Ok)
                {
                    Notifier.DisplayMessage(Strings.ImageSizeTooBig, NotificationType.Error);
                    IsSending = false;
                    return;
                }
            }

            byte[] mediaData = File.ReadAllBytes(fileName);
            if (mediaData.Length > TwitterConfig.MaxImageSize)
            {
                Notifier.DisplayMessage(Strings.ImageSizeTooBig, NotificationType.Error);
                IsSending = false;
                return;
            }

            var usedAccounts     = Accounts.Where(a => a.Use).ToArray();
            var acc              = usedAccounts.First();
            var additionalOwners = usedAccounts.Skip(1).Select(a => a.Context.UserId);

            string mediaType = TwitterHelper.GetMimeType(fileName);
            var    media     = await acc.Context.Twitter.UploadMediaAsync(mediaData, mediaType, additionalOwners).ContinueWith(t =>
            {
                IsSending = false;
                return(t.Result);
            });

            await Dispatcher.RunAsync(() =>
            {
                Medias.Add(media);
                AttachedMedias.Add(new MediaItem(media.MediaID, mediaData, fileName));
            });
        }