Esempio n. 1
0
        // 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);
        }
Esempio n. 2
0
        // 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());
        }
Esempio n. 3
0
        // 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);
        }
Esempio n. 4
0
        // 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
        }
Esempio n. 5
0
        // 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);
        }
Esempio n. 6
0
        // 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);
        }
Esempio n. 7
0
        // 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);
        }
Esempio n. 8
0
        // 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);
        }
Esempio n. 9
0
        // 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);
        }
Esempio n. 10
0
        // Analysis disable once InconsistentNaming
        public void IsValid_ReturnsFalse_IfMTimeIsDifferent()
        {
            var fileSystem = new FileSystemMock();

            fileSystem.SetFile(fileUri, fileLastWrite);
            var pixbuf           = PixbufMock.CreatePixbuf(fileUri, fileLastWrite.AddMilliseconds(1.0));
            var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem);

            var result = thumbnailService.IsValid(fileUri, pixbuf);

            Assert.IsFalse(result);
        }
Esempio n. 11
0
        // Analysis disable once InconsistentNaming
        public void LoadThumbnail_DeletesThumbnail_IfLoadFails()
        {
            var fileSystem = new FileSystemMock();

            fileSystem.SetFile(largeThumbnailUri, 0, thumbnail);
            fileSystem.FileMock.Setup(m => m.Read(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());
        }