// Analysis disable once InconsistentNaming public void Constructor_CreatesThumbnailFolders_IfTheyDontExist () { var fileSystem = new FileSystemMock (); // Analysis disable once ObjectCreationAsStatement new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); fileSystem.DirectoryMock.Verify (m => m.CreateDirectory (new SafeUri (largeThumbnailPath)), Times.Once ()); fileSystem.DirectoryMock.Verify (m => m.CreateDirectory (new SafeUri (normalThumbnailPath)), Times.Once ()); }
public void DontCopyIfSourceIsTargetFile () { var photo = PhotoMock.Create (targetUri); var fileSystem = new FileSystemMock (); var tracker = new PhotoFileTracker (fileSystem); tracker.CopyIfNeeded (photo, targetBase); Assert.AreEqual (0, tracker.OriginalFiles.Count ()); Assert.AreEqual (0, tracker.CopiedFiles.Count ()); Assert.AreEqual (targetUri, photo.DefaultVersion.Uri); fileSystem.FileMock.Verify (f => f.Copy (It. IsAny<SafeUri> (), It.IsAny<SafeUri> (), It.IsAny<bool> ()), Times.Never); }
public void CopyNewFile () { var photo = PhotoMock.Create (sourceUri); var fileSystem = new FileSystemMock (); var tracker = new PhotoFileTracker (fileSystem); tracker.CopyIfNeeded (photo, targetBase); CollectionAssert.AreEquivalent (new[]{ sourceUri }, tracker.OriginalFiles); CollectionAssert.AreEquivalent (new[]{ targetUri }, tracker.CopiedFiles); Assert.AreEqual (targetUri, photo.DefaultVersion.Uri); fileSystem.FileMock.Verify (f => f.Copy (sourceUri, targetUri, false), Times.Once); }
// Analysis disable once InconsistentNaming public void IsValid_ReturnsTrue_IfPixbufIsValid () { var fileSystem = new FileSystemMock (); fileSystem.SetFile (fileUri, fileMTime); var pixbuf = PixbufMock.CreatePixbuf (fileUri, fileMTime); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.IsValid (fileUri, pixbuf); Assert.IsTrue (result); }
// Analysis disable once InconsistentNaming public void IsValid_ReturnsFalse_IfFileDoesNotExist () { var fileSystem = new FileSystemMock (); var pixbuf = PixbufMock.CreatePixbuf (fileUri, fileMTime + 1); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.IsValid (fileUri, pixbuf); Assert.IsFalse (result); }
// Analysis disable once InconsistentNaming public void IsValid_ReturnsFalse_IfFileUriIsDifferent () { var fileSystem = new FileSystemMock (); fileSystem.SetFile (fileUri, fileMTime); var pixbuf = PixbufMock.CreatePixbuf (new SafeUri ("file:///some-uri"), fileMTime); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.IsValid (fileUri, pixbuf); Assert.IsFalse (result); }
// Analysis disable once InconsistentNaming public void IsValid_ReturnsFalse_IfPixbufIsNull () { var fileSystem = new FileSystemMock (); fileSystem.SetFile (fileUri, fileMTime); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.IsValid (fileUri, null); Assert.IsFalse (result); }
// Analysis disable once InconsistentNaming public void GetThumbnailPath_ReturnsPathForNormalThumbnail () { var fileSystem = new FileSystemMock (); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.GetThumbnailPath (fileUri, ThumbnailSize.Normal); Assert.AreEqual (normalThumbnailUri, result); }
// Analysis disable once InconsistentNaming public void GetThumbnail_CreatesPngAndReturnsPixbuf_IfPngIsMissing () { var fileSystem = new FileSystemMock (); fileSystem.SetFile (fileUri, fileMTime); thumbnailerMock.Setup (thumb => thumb.TryCreateThumbnail (largeThumbnailUri, ThumbnailSize.Large)) .Returns (true) .Callback (() => fileSystem.SetFile (largeThumbnailUri, 0, thumbnail)); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.GetThumbnail (fileUri, ThumbnailSize.Large); Assert.IsNotNull (result); }
// Analysis disable once InconsistentNaming public void LoadThumbnail_ReturnsNull_IfThumbnailDoesNotExist () { var fileSystem = new FileSystemMock (); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.LoadThumbnail (largeThumbnailUri); Assert.IsNull (result); }
// Analysis disable once InconsistentNaming public void DeleteThumbnail_IgnoresExceptionsOnDeletingThumbnails () { var fileSystem = new FileSystemMock (); fileSystem.SetFile (largeThumbnailUri); fileSystem.SetFile (normalThumbnailUri); fileSystem.FileMock.Setup (m => m.Delete (largeThumbnailUri)).Throws<Exception> (); fileSystem.FileMock.Setup (m => m.Delete (normalThumbnailUri)).Throws<Exception> (); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); thumbnailService.DeleteThumbnails (fileUri); fileSystem.FileMock.Verify (m => m.Delete (largeThumbnailUri), Times.Once ()); fileSystem.FileMock.Verify (m => m.Delete (normalThumbnailUri), Times.Once ()); // test ends without the exceptions thrown by File.Delete beeing unhandled }
// Analysis disable once InconsistentNaming public void DeleteThumbnail_DoesNotDeleteThumbnails_IfNotExist () { var fileSystem = new FileSystemMock (); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); thumbnailService.DeleteThumbnails (fileUri); fileSystem.FileMock.Verify (m => m.Delete (largeThumbnailUri), Times.Never ()); fileSystem.FileMock.Verify (m => m.Delete (normalThumbnailUri), Times.Never ()); }
// Analysis disable once InconsistentNaming public void DeleteThumbnail_DeletesLargeAndNormalThumbnails_IfTheyExist () { var fileSystem = new FileSystemMock (); fileSystem.SetFile (largeThumbnailUri); fileSystem.SetFile (normalThumbnailUri); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); thumbnailService.DeleteThumbnails (fileUri); fileSystem.FileMock.Verify (m => m.Delete (largeThumbnailUri), Times.Once ()); fileSystem.FileMock.Verify (m => m.Delete (normalThumbnailUri), Times.Once ()); }
// Analysis disable once InconsistentNaming public void GetThumbnail_ReturnsNull_IfThumbnailCreationFails () { var fileSystem = new FileSystemMock (); fileSystem.SetFile (fileUri, fileMTime); thumbnailerMock.Setup (thumb => thumb.TryCreateThumbnail (largeThumbnailUri, ThumbnailSize.Large)).Returns (false); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.GetThumbnail (fileUri, ThumbnailSize.Large); Assert.IsNull (result); }
// Analysis disable once InconsistentNaming public void GetThumbnail_ReturnsNull_IfNoThumbnailerFound () { var fileSystem = new FileSystemMock (); var thumbnailerFactoryMock = new Mock<IThumbnailerFactory> (); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactoryMock.Object, fileSystem); var result = thumbnailService.GetThumbnail (fileUri, ThumbnailSize.Large); Assert.IsNull (result); }
public void FilesAreRenamedToNextFreeIndex () { var photo = PhotoMock.Create (sourceUri, rawUri); var fileSystem = new FileSystemMock ( xmpSourceUri, targetUri, targetUri1, targetRawUri, targetRawUri1, targetRawUri2, targetRawUri4); var tracker = new PhotoFileTracker (fileSystem); tracker.CopyIfNeeded (photo, targetBase); CollectionAssert.AreEquivalent (new[]{ sourceUri, rawUri, xmpSourceUri }, tracker.OriginalFiles); CollectionAssert.AreEquivalent (new[]{ targetUri2, targetRawUri3, xmpTargetUri2 }, tracker.CopiedFiles); Assert.AreEqual (targetUri2, photo.DefaultVersion.Uri); Assert.AreEqual (targetRawUri3, photo.Versions.ElementAt(1).Uri); fileSystem.FileMock.Verify (f => f.Copy (sourceUri, targetUri2, false), Times.Once); fileSystem.FileMock.Verify (f => f.Copy (rawUri, targetRawUri3, false), Times.Once); fileSystem.FileMock.Verify (f => f.Copy (xmpSourceUri, xmpTargetUri2, true), Times.Once); }
// Analysis disable once InconsistentNaming public void LoadThumbnail_ReturnsPixbuf_IfThumbnailExists () { var fileSystem = new FileSystemMock (); fileSystem.SetFile (largeThumbnailUri, 0, thumbnail); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.LoadThumbnail (largeThumbnailUri); Assert.IsNotNull (result); }
// Analysis disable once InconsistentNaming public void LoadThumbnail_IgnoresExceptionsOnDeletingThumbnails () { var fileSystem = new FileSystemMock (); fileSystem.SetFile (largeThumbnailUri, 0, thumbnail); fileSystem.FileMock.Setup (m => m.Read (largeThumbnailUri)).Throws<Exception> (); fileSystem.FileMock.Setup (m => m.Delete (largeThumbnailUri)).Throws<Exception> (); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.LoadThumbnail (largeThumbnailUri); Assert.IsNull (result); fileSystem.FileMock.Verify (file => file.Delete (largeThumbnailUri), Times.Once ()); }
// Analysis disable once InconsistentNaming public void GetThumbnail_ReturnsPixbuf_IfValidPngExists () { var fileSystem = new FileSystemMock (); fileSystem.SetFile (fileUri, fileMTime); fileSystem.SetFile (largeThumbnailUri, 0, thumbnail); var thumbnailService = new ThumbnailService (xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.GetThumbnail (fileUri, ThumbnailSize.Large); Assert.IsNotNull (result); }