public void TooWideImageIsRejected() { // Arrange const string fileName = "Data/Gifs/TooWide.gif"; // Act var result = GifValidator.Validate(fileName); // Assert Assert.AreEqual(GifValidator.ValidationResult.TooWide, result); }
public void ValidImageIsAccepted() { // Arrange const string fileName = "Data/Gifs/Valid.gif"; // Act var result = GifValidator.Validate(fileName); // Assert Assert.AreEqual(GifValidator.ValidationResult.Ok, result); }
public void ImageWithTooManyPixelsIsRejected() { // Arrange const string fileName = "Data/Gifs/TooManyPixels.gif"; // Act var result = GifValidator.Validate(fileName); // Assert Assert.AreEqual(GifValidator.ValidationResult.TooManyPixels, result); }
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)); }); }