Ejemplo n.º 1
0
 /// <summary>
 /// Calculate a SHA250 hash for a specified file. Used to compare to two files are the same
 /// </summary>
 /// <param name="fullFileName">The full path of the file for which to get the hash</param>
 /// <returns>The byte array of the file hash</returns>
 public byte[] GetFileHash(FileBase fileBase, string fullFileName)
 {
     using (Stream fileStream = fileBase.OpenRead(fullFileName))
     {
         SHA256Managed sha      = new SHA256Managed();
         byte[]        checksum = sha.ComputeHash(fileStream);
         return(checksum);
     }
 }//end GetFileHash
Ejemplo n.º 2
0
        public async Task GetAvatarAsync_uses_inner_if_file_expired()
        {
            _fileInfo.Exists.Returns(true);
            _fileInfo.LastWriteTime.Returns(new DateTime(2010, 1, 1));
            _fileSystem.File.OpenWrite(Arg.Any <string>()).Returns(_ => new MemoryStream());
            _fileSystem.File.Delete(Arg.Any <string>());

            await MissAsync(_email1, _name1);

            _fileSystem.File.Received(1).Delete(Path.Combine(AppSettings.AvatarImageCachePath, $"{_email1}.{_size}px.png"));

            _file.OpenRead(Arg.Any <string>()).Returns(c => GetPngStream());
            _fileInfo.LastWriteTime.Returns(DateTime.Now);
            _fileSystem.ClearReceivedCalls();
            _fileInfo.ClearReceivedCalls();
            _file.ClearReceivedCalls();

            var image = await _cache.GetAvatarAsync(_email1, _name1, 16);

            image.Should().NotBeNull();
            _ = _fileInfo.Received(1).LastWriteTime;
            _fileSystem.File.Received(1).OpenRead(Path.Combine(AppSettings.AvatarImageCachePath, $"{_email1}.{_size}px.png"));
        }