コード例 #1
0
		public async Task Synchronize_WhenLastSynchronizationTimeIsMoreRecentThanFileModificationDate_ShouldNotCallTranscode(
			double daysToAdd,
			[Frozen]Mock<ISynchronizedFilesRepository> synchronizedFileRepository,
			[Frozen]Mock<IFileTranscoder> fileTranscoder,
			MusicMirrorConfiguration config,
			FileSynchronizer sut,
			SourceFilePath sourceFile,
			TargetFilePath targetFile)
		{
			//arrange
			var lastWriteTime = new DateTimeOffset(2015, 04, 01, 0, 0, 0, TimeSpan.Zero);
			var lastSyncTime = lastWriteTime.AddDays(daysToAdd);
			sourceFile.LastWriteTime = lastWriteTime;
			synchronizedFileRepository.Setup(s => s.GetMirroredFilePath(It.IsAny<CancellationToken>(), sourceFile.File)).ReturnsTask(targetFile.File);
			synchronizedFileRepository.Setup(s => s.GetLastSynchronization(It.IsAny<CancellationToken>(), sourceFile.File)).ReturnsTask(lastSyncTime);
			//act
			await sut.Synchronize(CancellationToken.None, sourceFile);
			//assert
			fileTranscoder.Verify(f =>
				f.Transcode(
					It.IsAny<CancellationToken>(),
					sourceFile.File,
					AudioFormat.Flac,
					It.Is((DirectoryInfo d) => d.FullName.Equals(targetFile.File.DirectoryName))),
				Times.Never());
		}
コード例 #2
0
		public async Task Synchronize_ShouldCallInnerSynchronize(
			[Frozen]Mock<IFileTranscoder> innerFileTranscoder,
			CopyId3TagsPostProcessor sut,
			SourceFilePath sourceFile,
			MusicMirrorConfiguration configuration)
		{
			//arrange
			//act
			await sut.Transcode(CancellationToken.None, sourceFile.File, AudioFormat.Flac, configuration.TargetPath);
			//assert
			innerFileTranscoder.Verify(f => f.Transcode(It.IsAny<CancellationToken>(), sourceFile.File, AudioFormat.Flac, configuration.TargetPath));
		}
コード例 #3
0
		public async Task Transcode_ShouldCallTranscoder(
			TranscoderDispatch sut,
			SourceFilePath file,
			DirectoryInfo directory,
			Mock<IFileTranscoder> fileTranscoder)
		{
			//arrange
			sut.AddTranscoder(fileTranscoder.Object, new AudioFormat("test", "test", file.File.Extension, LossKind.Lossless));
			//act
			await sut.Transcode(CancellationToken.None, file.File, AudioFormat.Flac, directory);
			//assert
			fileTranscoder.Verify(f => f.Transcode(CancellationToken.None, file.File, AudioFormat.Flac, directory));
		}
コード例 #4
0
		public async Task DeleteFile_WhenFileDoesNotRequireTranscoding_ShouldCallDefaultFolderOperations(
			[Frozen]Mock<IRequireTranscoding> requireTranscoding,
			ChooseFolderOperation sut,
			SourceFilePath file)
		{
			//arrange
			var defaultFolderOperation = Mock.Get(sut.DefaultFileOperations);
			var verifiable = defaultFolderOperation.Setup(m => m.DeleteFile(It.IsAny<CancellationToken>(), file.File)).ReturnsDefaultTaskVerifiable();
			requireTranscoding.Setup((r) => r.ForFile(It.IsAny<CancellationToken>(), file.File)).ReturnsTask(false);
			//act
			await sut.DeleteFile(CancellationToken.None, file.File);
			//assert
			verifiable.Verify();
		}
コード例 #5
0
		public async Task HasMirroredFileForPath_WhenFileRequireTranscoding_ShouldReturnCorrectValue(
			bool expected,
			[Frozen]Mock<IRequireTranscoding> requireTranscoding,
			ChooseFolderOperation sut,
			SourceFilePath file)
		{
			//arrange			
			var transcodingFolderOperation = Mock.Get(sut.TranscodingFolderOperation);
			transcodingFolderOperation.Setup(m => m.HasMirroredFileForPath(It.IsAny<CancellationToken>(), file.File)).ReturnsTask(expected);			
			requireTranscoding.Setup((r) => r.ForFile(It.IsAny<CancellationToken>(), file.File)).ReturnsTask(true);
			//act
			var actual = await sut.HasMirroredFileForPath(CancellationToken.None, file.File);
			//assert
			actual.Should().Be(expected);
		}
コード例 #6
0
		public async Task Synchronize_ShouldCallAudioTagsSynchronizer(
			[Frozen]Mock<IFileTranscoder> innerFileTranscoder,
			[Frozen]Mock<IAudioTagsSynchronizer> audioTagsSynchronizer,
			CopyId3TagsPostProcessor sut,
			SourceFilePath sourceFile,
			TargetFilePath targetFile)
		{
			//arrange
			innerFileTranscoder.Setup(f => f.GetTranscodedFileName(sourceFile.File.Name)).Returns(targetFile.File.Name);			
			//act
			await sut.Transcode(It.IsAny<CancellationToken>(), sourceFile.File, AudioFormat.Flac, targetFile.File.Directory);
			//assert
			audioTagsSynchronizer.Verify(
				a => a.SynchronizeTags(
					It.IsAny<CancellationToken>(),
					sourceFile.File,
					It.Is((FileInfo f) => new FileInfoEqualityComparer().Equals(f, targetFile.File))));
        }
コード例 #7
0
		public async Task Synchronize_ShouldCallSynchronize(
			[Frozen]Mock<IAsyncFileOperations> fileOperations,
			[Frozen]Mock<IAudioTagReader> audioTagReader,
			[Frozen]Mock<IAudioTagWriter> audioTagWriter,
			AudioTagsSynchronizer sut,
			SourceFilePath sourceFile,
			TargetFilePath targetFile,
			Stream sourceStream,
			Stream targetStream,
            Tag tag)
		{
			//arrange
			fileOperations.Setup(f => f.OpenRead(sourceFile.ToString())).ReturnsTask(sourceStream);
			fileOperations.Setup(f => f.Open(targetFile.ToString(), Hanno.IO.FileMode.Open, Hanno.IO.FileAccess.ReadWrite)).ReturnsTask(targetStream);
			audioTagReader.Setup(a => a.ReadTags(It.IsAny<CancellationToken>(), sourceStream)).ReturnsTask(tag);
			//act
			await sut.SynchronizeTags(CancellationToken.None, sourceFile.File, targetFile.File);
			//assert
			audioTagWriter.Verify(a => a.WriteTags(It.IsAny<CancellationToken>(), targetStream, tag));
        }
コード例 #8
0
		public async Task RenameFile_ShouldCallRenameFile(
			[Frozen]Mock<ISynchronizedFilesRepository> syncFilesRepository,
			[Frozen]Mock<IAsyncFileOperations> fileOperations,
			  SynchronizeFileService sut,
			  SourceFilePath newFilePath,
			  SourceFilePath oldFilePath,
			  TargetFilePath oldMirroredFilePath,
			  TargetFilePath newMirroredFilePath
			  )
		{
			//arrange											
			syncFilesRepository.Setup(s => s.GetMirroredFilePath(It.IsAny<CancellationToken>(), oldFilePath.File))
							   .ReturnsTask(oldMirroredFilePath.File);
			syncFilesRepository.Setup(s => s.GetMirroredFilePath(It.IsAny<CancellationToken>(), newFilePath.File))
							   .ReturnsTask(newMirroredFilePath.File);
			//act
			await sut.RenameFile(CancellationToken.None, newFilePath.File, oldFilePath.File);
			//assert
			fileOperations.Verify(f => f.Move(oldMirroredFilePath.ToString(), newMirroredFilePath.ToString()));
		}
コード例 #9
0
		public async Task RenameFile_ShouldCallAddSynchronization(
			[Frozen]Mock<ISynchronizedFilesRepository> syncFilesRepository,
			[Frozen]Mock<IAsyncFileOperations> fileOperations,
			  SynchronizeFileService sut,
			  SourceFilePath newFilePath,
			  SourceFilePath oldFilePath,
			  TargetFilePath oldMirroredFilePath
			  )
		{
			//arrange			
			var expectedTargetFilePath = Path.Combine(
				sut.Configuration.TargetPath.FullName,
				newFilePath.RelativePath,
				oldMirroredFilePath.File.Name);
			syncFilesRepository.Setup(s => s.GetMirroredFilePath(It.IsAny<CancellationToken>(), oldFilePath.File))
							   .ReturnsTask(oldMirroredFilePath.File);
			//act
			await sut.RenameFile(CancellationToken.None, newFilePath.File, oldFilePath.File);
			//assert
			syncFilesRepository.Verify(f => f.AddSynchronization(
				It.IsAny<CancellationToken>(),
				newFilePath.File));
		}
コード例 #10
0
		public async Task Synchronize_WhenFormatIsUknown_ShouldNotCallTranscode(
		[Frozen]Mock<ISynchronizedFilesRepository> synchronizedFileRepository,
		[Frozen]Mock<IFileTranscoder> fileTranscoder,
		MusicMirrorConfiguration config,
		FileSynchronizer sut,
		TargetFilePath targetFile)
		{
			//arrange
			var expectedExtension = ".uknownExtension";
			var sourceFile = new SourceFilePath(config.SourcePath.FullName, new[] { "test", "test" }, "test" + expectedExtension);
			var lastWriteTime = new DateTimeOffset(2015, 04, 01, 0, 0, 0, TimeSpan.Zero);
			var lastSyncTime = lastWriteTime.AddDays(-1);
			sourceFile.LastWriteTime = lastWriteTime;
			synchronizedFileRepository.Setup(s => s.GetMirroredFilePath(It.IsAny<CancellationToken>(), sourceFile.File)).ReturnsTask(targetFile.File);
			synchronizedFileRepository.Setup(s => s.GetLastSynchronization(It.IsAny<CancellationToken>(), sourceFile.File)).ReturnsTask(lastSyncTime);
			var expectedFormat = new AudioFormat("Uknown format", "Uknown format", expectedExtension, default(LossKind));
			//act
			await sut.Synchronize(CancellationToken.None, sourceFile);
			//assert
			fileTranscoder.Verify(f =>
				f.Transcode(
					It.IsAny<CancellationToken>(),
					sourceFile.File,
					expectedFormat,
					It.Is((DirectoryInfo d) => d.FullName.Equals(targetFile.File.DirectoryName))));
		}
コード例 #11
0
		public async Task DeleteFile_ShouldCallDeleteSynchronization(
			[Frozen]Mock<ISynchronizedFilesRepository> syncFilesRepository,
			[Frozen]Mock<IAsyncFileOperations> fileOperations,
			  SynchronizeFileService sut,
			  SourceFilePath sourceFilePath,
			  TargetFilePath mirroredFilePath
			  )
		{
			//arrange			
			syncFilesRepository.Setup(s => s.GetMirroredFilePath(It.IsAny<CancellationToken>(), sourceFilePath.File))
							   .ReturnsTask(mirroredFilePath.File);
			//act
			await sut.DeleteFile(CancellationToken.None, sourceFilePath.File);
			//assert
			syncFilesRepository.Verify(f => f.DeleteSynchronization(It.IsAny<CancellationToken>(), sourceFilePath.File));
		}
コード例 #12
0
		public async Task Rename_WhenOldFileRequireTranscoding_AndNewFileDoesNotRequireTranscoding_ShouldDeleteOldFile(
		[Frozen]Mock<IRequireTranscoding> requireTranscoding,
		ChooseFolderOperation sut,
		SourceFilePath newFile,
		SourceFilePath oldFile)
		{
			//arrange			
			var transcodingFolderOperation = Mock.Get(sut.TranscodingFolderOperation);
			var verifiable = transcodingFolderOperation.Setup(m => m.DeleteFile(It.IsAny<CancellationToken>(), oldFile.File)).ReturnsDefaultTaskVerifiable();
			requireTranscoding.Setup((r) => r.ForFile(It.IsAny<CancellationToken>(), newFile.File)).ReturnsTask(false);
			requireTranscoding.Setup((r) => r.ForFile(It.IsAny<CancellationToken>(), oldFile.File)).ReturnsTask(true);
			//act
			await sut.RenameFile(CancellationToken.None, newFile.File, oldFile.File);
			//assert
			verifiable.Verify();
		}
コード例 #13
0
		public async Task SynchronizeFile_WhenFileRequireTranscoding_ShouldCallTranscodingFolderOperations(
			[Frozen]Mock<IRequireTranscoding> requireTranscoding,
			ChooseFolderOperation sut,
			SourceFilePath file)
		{
			//arrange			
			var transcodingFolderOperation = Mock.Get(sut.TranscodingFolderOperation);
			var verifiable = transcodingFolderOperation.Setup(m => m.SynchronizeFile(It.IsAny<CancellationToken>(), file.File)).ReturnsDefaultTaskVerifiable();
			requireTranscoding.Setup((r) => r.ForFile(It.IsAny<CancellationToken>(), file.File)).ReturnsTask(true);
			//act
			await sut.SynchronizeFile(CancellationToken.None, file.File);
			//assert
			verifiable.Verify();
		}
コード例 #14
0
		public async Task Transcode_WhenNoThereIsNoTranscoder_ShouldCallDefaultTranscoder(
			[Frozen]Mock<IFileTranscoder> fileTranscoder,
			TranscoderDispatch sut,
			SourceFilePath file,
			DirectoryInfo directory)
		{
			//arrange
			//act
			await sut.Transcode(CancellationToken.None, file.File, AudioFormat.Flac, directory);
			//assert
			fileTranscoder.Verify(f => f.Transcode(CancellationToken.None, file.File, AudioFormat.Flac, directory));
		}
コード例 #15
0
		public async Task SynchronizeFile_ShouldCallAddSynchronization(
		[Frozen]Mock<ISynchronizedFilesRepository> syncFilesRepository,
		[Frozen]Mock<IFileSynchronizer> synchronizer,
		  SynchronizeFileService sut,
		  SourceFilePath sourceFilePath,
		  TargetFilePath mirroredFilePath
		  )
		{
			//arrange			
			syncFilesRepository.Setup(s => s.GetMirroredFilePath(It.IsAny<CancellationToken>(), sourceFilePath.File))
							   .ReturnsTask(mirroredFilePath.File);
			//act			
			await sut.SynchronizeFile(CancellationToken.None, sourceFilePath.File);
			//assert
			var c = new FileInfoEqualityComparer();
			syncFilesRepository.Verify(
				s => s.AddSynchronization(
					It.IsAny<CancellationToken>(),
					It.Is<FileInfo>(f => c.Equals(f, sourceFilePath.File))
					)
				);
		}
コード例 #16
0
		public async Task SynchronizeFile_ShouldCallSynchronizer(		
		[Frozen]Mock<ISynchronizedFilesRepository> syncFilesRepository,
		[Frozen]Mock<IFileSynchronizer> synchronizer,
		  SynchronizeFileService sut,
		  SourceFilePath sourceFilePath,
		  TargetFilePath mirroredFilePath
		  )
		{
			//arrange			
			syncFilesRepository.Setup(s => s.GetMirroredFilePath(It.IsAny<CancellationToken>(), sourceFilePath.File))
							   .ReturnsTask(mirroredFilePath.File);
			//act			
			await sut.SynchronizeFile(CancellationToken.None, sourceFilePath.File);
			//assert
			synchronizer.Verify(s => s.Synchronize(It.IsAny<CancellationToken>(), It.Is((IFileInfo f) => sourceFilePath.File == f.File)));
		}
コード例 #17
0
		public async Task HasMirroredFileForPath_ShouldReturnCorrectValue(
			bool expected,
			[Frozen]Mock<ISynchronizedFilesRepository> syncFilesRepository,
			[Frozen]Mock<IAsyncFileOperations> fileOperations,
			  SynchronizeFileService sut,
			  SourceFilePath sourceFilePath,
			  TargetFilePath mirroredFilePath
			  )
		{
			//arrange			
			syncFilesRepository.Setup(s => s.GetMirroredFilePath(It.IsAny<CancellationToken>(), sourceFilePath.File))
							   .ReturnsTask(mirroredFilePath.File);
			var tf = mirroredFilePath.ToString();
			fileOperations.Setup(f => f.Exists(tf)).ReturnsTask(expected);
			//act
			var actual = await sut.HasMirroredFileForPath(CancellationToken.None, sourceFilePath.File);
			//assert
			actual.Should().Be(expected);
		}