// 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_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_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 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 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 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 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 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 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_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_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); }
// 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 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); }