Esempio n. 1
0
        public async Task Copy(string file1, string file2)
        {
            MemoryStream savedZip = new MemoryStream();

            Mock <IStreamableKeyValuePersistenceService> streamableKeyValuePersistenceService = new Mock <IStreamableKeyValuePersistenceService>();

            streamableKeyValuePersistenceService
            .Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <Stream>(), It.IsAny <CancellationToken>()))
            .Callback <string, Stream, CancellationToken>((str, stm, can) => File.Open(str, FileMode.Open, FileAccess.Read, FileShare.Read).CopyTo(stm))
            .Returns(Task.CompletedTask);
            streamableKeyValuePersistenceService.Setup(x =>
                                                       x.SaveAsync(It.IsAny <string>(), It.IsAny <Stream>(), It.IsAny <CancellationToken>()))
            .Callback <string, Stream, CancellationToken>((str, stm, can) =>
            {
                stm.Seek(0, SeekOrigin.Begin);
                stm.CopyTo(savedZip);
            })
            .Returns(Task.CompletedTask);
            Mock <ILogger> logger = new Mock <ILogger>();

            MergeZipFilesService mergeZipFilesService = new MergeZipFilesService();
            await mergeZipFilesService.Merge(1, file1, file2, streamableKeyValuePersistenceService.Object, logger.Object, CancellationToken.None);

            using (var archive = new ZipArchive(savedZip, ZipArchiveMode.Read, false))
            {
                Assert.Equal(1, archive.Entries.Count);
            }
        }
Esempio n. 2
0
        public void GetNewFilename(string inFile, string outFile)
        {
            MergeZipFilesService mergeZipFilesService = new MergeZipFilesService();

            string newFile = mergeZipFilesService.GetNewFilename(inFile);

            Assert.Equal(outFile, newFile);
        }