Example #1
0
        public async Task GetFilePathTest()
        {
            var resourceFileNames = FilesWithMd5.Select(i => (string)i[0]).ToList();

            var tempFilePaths = new List <string>();

            using (var fileService = new LocalTempFileService(TestLogger.Create <LocalTempFileService>(_testOutputHelper)))
            {
                foreach (var resourceFileName in resourceFileNames)
                {
                    var path = GetResourcePath(resourceFileName);
                    File.Exists(path).Should().BeTrue();

                    var tempFilePath = await fileService.CreateFromStreamAsync(resourceFileName, File.OpenRead(path));

                    tempFilePath.Should().NotBeNullOrWhiteSpace();
                    tempFilePaths.Add(tempFilePath);
                }

                fileService.Files.Should().BeEquivalentTo(resourceFileNames);
            }

            foreach (var tempFilePath in tempFilePaths)
            {
                File.Exists(tempFilePath).Should().BeFalse();
            }
        }
Example #2
0
 public void GetUnknownFileTest()
 {
     using (var fileService = new LocalTempFileService(TestLogger.Create <LocalTempFileService>(_testOutputHelper)))
     {
         fileService.Invoking(f => f.GetFilePath("someFile.txt"))
         .Should().Throw <FileNotFoundException>();
     }
 }
Example #3
0
        public async Task CreateFromStreamAsyncTest(string resourceFileName, string md5)
        {
            var path = GetResourcePath(resourceFileName);

            File.Exists(path).Should().BeTrue();

            string tempFilePath;

            using (var fileService = new LocalTempFileService(TestLogger.Create <LocalTempFileService>(_testOutputHelper)))
            {
                tempFilePath = await fileService.CreateFromStreamAsync(resourceFileName, File.OpenRead(path));

                tempFilePath.Should().NotBeNullOrWhiteSpace();

                var tempMd5 = ComputeFileMd5(tempFilePath);

                tempMd5.Should().Be(md5);
            }

            File.Exists(tempFilePath).Should().BeFalse();
        }
Example #4
0
        public async Task ReplaceFileTest()
        {
            var resourceFileName = (string)FilesWithMd5[0][0];
            var path             = GetResourcePath(resourceFileName);
            var replacementPath  = GetResourcePath((string)FilesWithMd5[1][0]);

            File.Exists(path).Should().BeTrue();
            File.Exists(replacementPath).Should().BeTrue();

            string tempFilePath1;
            string tempFilePath2;

            using (var fileService = new LocalTempFileService(TestLogger.Create <LocalTempFileService>(_testOutputHelper)))
            {
                tempFilePath1 = await fileService.CreateFromStreamAsync(resourceFileName, File.OpenRead(path));

                tempFilePath1.Should().NotBeNullOrWhiteSpace();
                var tempMd5 = ComputeFileMd5(tempFilePath1);
                tempMd5.Should().Be((string)FilesWithMd5[0][1]);
                fileService.Files.Should().BeEquivalentTo(new[] { resourceFileName });
                fileService.GetFilePath(resourceFileName).Should().Be(tempFilePath1);

                tempFilePath2 = await fileService.CreateFromStreamAsync(resourceFileName, File.OpenRead(replacementPath));

                File.Exists(tempFilePath1).Should().BeFalse();

                tempFilePath2.Should().NotBeNullOrWhiteSpace();
                tempFilePath2.Should().NotBe(tempFilePath1);
                tempMd5 = ComputeFileMd5(tempFilePath2);
                tempMd5.Should().Be((string)FilesWithMd5[1][1]);
                fileService.Files.Should().BeEquivalentTo(new[] { resourceFileName });
                fileService.GetFilePath(resourceFileName).Should().Be(tempFilePath2);
            }

            File.Exists(tempFilePath1).Should().BeFalse();
            File.Exists(tempFilePath2).Should().BeFalse();
        }