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); }
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); }
public Duplicates(IConsole console, DiskCacheService diskCacheSvc, GooglePhotosService googlePhotosSvc) : base(console, diskCacheSvc, googlePhotosSvc) { }
public Download(IConsole console, DiskCacheService diskCacheSvc, GooglePhotosService googlePhotosSvc) : base(console, diskCacheSvc, googlePhotosSvc) { }
public Upload(IConsole console, DiskCacheService diskCacheSvc, GooglePhotosService googlePhotosSvc) : base(console, diskCacheSvc, googlePhotosSvc) { _googlePhotosSvc.UploadProgressEvent += _googlePhotosSvc_UploadProgressEvent; }
public Logout(IConsole console, DiskCacheService diskCacheSvc, GooglePhotosService googlePhotosSvc) : base(console, diskCacheSvc, googlePhotosSvc) { }
public MediaItems(IConsole console, DiskCacheService diskCacheSvc, GooglePhotosService googlePhotosSvc) : base(console, diskCacheSvc, googlePhotosSvc) { }