Пример #1
0
        public async Task TestAddFileNothingExists()
        {
            var fs      = new MockFileSystem();
            var options = new ServerFilesOptions {
                Directory = "D:\\files", TempDirectory = "D:\\temp"
            };

            var filesManager   = new ServerFilesManager(fs, Options.Create(options), GetNullLogger());
            var testFileStream = new MemoryStream(_testFile1);

            // act
            var storedFile = await filesManager.AddFile(testFileStream);

            // assert
            Assert.Equal(_testFile1Hash.ToString(), storedFile.FileHash);
            Assert.Equal(_testFile1.Length, storedFile.Length);
            Assert.True(fs.FileExists($"{options.Directory}\\{_testFile1Hash}"));
            Assert.Empty(fs.Directory.GetFiles(options.TempDirectory));
        }
Пример #2
0
        public async Task TestReadFile()
        {
            var fs      = new MockFileSystem();
            var options = new ServerFilesOptions {
                Directory = "D:\\files", TempDirectory = "D:\\temp"
            };

            var filesManager   = new ServerFilesManager(fs, Options.Create(options), GetNullLogger());
            var testFileStream = new MemoryStream(_testFile1);
            await filesManager.AddFile(testFileStream);

            // act
            var file = filesManager.ReadFile(_testFile1Hash);

            Hash hash;

            using (var gzip = new GZipStream(file, CompressionMode.Decompress, false))
            {
                hash = new Hash(SHA256.Create().ComputeHash(gzip));
            }

            // assert
            Assert.Equal(_testFile1Hash.ToString(), hash.ToString());
        }