private void picsPanel_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (picsPanel.SelectedIndex == -1) { imgPreview.Source = new BitmapImage(); return; } string path = (picsPanel.SelectedItem as MediaFile).ImagePath; if (MediaFileFinder.IsImage(path)) { try { imgPreview.Source = new BitmapImage(new Uri(path)); Console.WriteLine(imgPreview.Width + " " + imgPreview.Height); } catch { MessageBox.Show("Can not show " + path); } } else { imgPreview.Source = new BitmapImage(new Uri("pack://application:,,,/MediaPlayer;component/Resources/videoclip-icon.png")); } }
public void IsImage_TestValidImage() { string[] realImages = { "image.jpg", "image.png" }; foreach (string file in realImages) { Assert.IsTrue(MediaFileFinder.IsImage(file)); } string[] notImages = { "image.asf", "image.qwer" }; foreach (string file in notImages) { Assert.IsFalse(MediaFileFinder.IsImage(file)); } }
public void IsImage_TestEmptyString() { string filePath = string.Empty; try { MediaFileFinder.IsImage(filePath); } catch (ArgumentException e) { StringAssert.Contains(e.Message, MediaFileFinder.emptyValueMessage); return; } Assert.Fail("Expected exception not thrown"); }