Esempio n. 1
0
        public void CreateOrGetCacheFile_ThrowsInvalidOperationExceptionIfCacheDirectoryIsInvalid()
        {
            // Arrange
            const string             dummySource          = "dummySource";
            const string             dummyCacheDirectory  = "dummyCacheDirectory";
            var                      dummyException       = new IOException();
            Mock <IDirectoryService> mockDirectoryService = _mockRepository.Create <IDirectoryService>();

            mockDirectoryService.Setup(d => d.CreateDirectory(dummyCacheDirectory)).Throws(dummyException);
            DiskCacheService testSubject = CreateDiskCacheService(directoryService: mockDirectoryService.Object);

            // Act and assert
            InvalidOperationException result = Assert.Throws <InvalidOperationException>(() => testSubject.CreateOrGetCacheFile(dummySource, dummyCacheDirectory));

            // Assert
            _mockRepository.VerifyAll();
            Assert.Equal(string.Format(Strings.InvalidOperationException_DiskCacheService_InvalidDiskCacheDirectory, dummyCacheDirectory), result.Message);
            Assert.Same(dummyException, result.InnerException);
        }
Esempio n. 2
0
        public void GetStream_LogsWarningsThenThrowsIOExceptionIfCacheFileExistsButIsInUseAndRemainsInUseOnTheThirdTryToOpenIt()
        {
            // Arrange
            const string     dummyFilePath   = "dummyFilePath";
            const FileMode   dummyFileMode   = FileMode.Open;
            const FileAccess dummyFileAccess = FileAccess.Read;
            const FileShare  dummyFileShare  = FileShare.Read;
            var            dummyIOException  = new IOException();
            Mock <ILogger> mockLogger        = _mockRepository.Create <ILogger>();

            mockLogger.Setup(l => l.IsEnabled(LogLevel.Warning)).Returns(true);
            Mock <ILoggerFactory> mockLoggerFactory = _mockRepository.Create <ILoggerFactory>();

            mockLoggerFactory.Setup(l => l.CreateLogger(typeof(DiskCacheService).FullName)).Returns(mockLogger.Object);
            Mock <IFileService> mockFileService = _mockRepository.Create <IFileService>();

            mockFileService.Setup(f => f.Open(dummyFilePath, dummyFileMode, dummyFileAccess, dummyFileShare)).Throws(dummyIOException);
            DiskCacheService testSubject = CreateDiskCacheService(fileService: mockFileService.Object, loggerFactory: mockLoggerFactory.Object);

            // Act and assert
            IOException result = Assert.Throws <IOException>(() => testSubject.GetStream(dummyFilePath, dummyFileMode, dummyFileAccess, dummyFileShare));

            _mockRepository.VerifyAll();
            mockFileService.Verify(f => f.Open(dummyFilePath, dummyFileMode, dummyFileAccess, dummyFileShare), Times.Exactly(3));
            Assert.Same(dummyIOException, result);
            mockLogger.Verify(l => l.Log(LogLevel.Warning, 0,
                                         // object is of type FormattedLogValues
                                         It.Is <It.IsAnyType>((f, _) => f.ToString() == string.Format(Strings.LogWarning_DiskCacheService_FileInUse, dummyFilePath, 2)),
                                         null,
                                         (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()),
                              Times.Once);
            mockLogger.Verify(l => l.Log(LogLevel.Warning, 0,
                                         It.Is <It.IsAnyType>((f, _) => f.ToString() == string.Format(Strings.LogWarning_DiskCacheService_FileInUse, dummyFilePath, 1)),
                                         null,
                                         (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()),
                              Times.Once);
            mockLogger.Verify(l => l.Log(LogLevel.Warning, 0,
                                         It.Is <It.IsAnyType>((f, _) => f.ToString() == string.Format(Strings.LogWarning_DiskCacheService_FileInUse, dummyFilePath, 0)),
                                         null,
                                         (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()),
                              Times.Once);
        }
Esempio n. 3
0
 public Duplicates(IConsole console, DiskCacheService diskCacheSvc, GooglePhotosService googlePhotosSvc) : base(console, diskCacheSvc, googlePhotosSvc)
 {
 }
Esempio n. 4
0
 public Download(IConsole console, DiskCacheService diskCacheSvc, GooglePhotosService googlePhotosSvc) : base(console, diskCacheSvc, googlePhotosSvc)
 {
 }
Esempio n. 5
0
 public Upload(IConsole console, DiskCacheService diskCacheSvc, GooglePhotosService googlePhotosSvc) : base(console, diskCacheSvc, googlePhotosSvc)
 {
     _googlePhotosSvc.UploadProgressEvent += _googlePhotosSvc_UploadProgressEvent;
 }
Esempio n. 6
0
 public Logout(IConsole console, DiskCacheService diskCacheSvc, GooglePhotosService googlePhotosSvc) : base(console, diskCacheSvc, googlePhotosSvc)
 {
 }
 public MediaItems(IConsole console, DiskCacheService diskCacheSvc, GooglePhotosService googlePhotosSvc) : base(console, diskCacheSvc, googlePhotosSvc)
 {
 }