public static void FileVerifierTest_Default_5_Sha256_Hex() { var filePath = Path.Combine(Path.GetTempPath(), $"__test_{Guid.NewGuid().ToString()}__"); var fileInfo = new FileInfo(filePath); File.WriteAllText(filePath, Guid.NewGuid().ToString()); var checksum = Sha256.GetInstance().GenerateInHex(fileInfo); var verified = FileVerifier.VerifyAsync(fileInfo, fileInfo.Length, checksum, FileVerifier.ChecksumType.Sha256, CancellationToken.None).Result; Assert.True(verified); try { fileInfo.Delete(); } catch (Exception) { } }
public void FileDownloader_Default_2_DownloadFileAsync() { var fileDownloader = FileDownloader.GetInstance(); FileDownloader.DownloadOperationResult downloadResult = FileDownloader.DownloadStatus.Unknown; for (var i = 0; i < 3; i++) { _output.WriteLine($"Start to download: {TestFileUrl}"); long progress = 0; downloadResult = fileDownloader.DownloadFileAsync( TestFileUrl, new FileInfo(TestFileDestPath), TestFileSize, incSize => { progress += incSize; _output.WriteLine($"Download progress: {progress}"); }, CancellationToken.None).Result; if (downloadResult.Success) { if (!FileVerifier.VerifyAsync(new FileInfo(TestFileDestPath), TestFileSize, TestFileHash, TestFileChecksumType, CancellationToken.None).Result) { downloadResult = FileDownloader.DownloadStatus.InternalError; continue; } break; } SpinWait.SpinUntil(() => false, TimeSpan.FromSeconds(1)); } try { File.Delete(TestFileDestPath); } catch (Exception) { } _output.WriteLine($"Download status: {downloadResult?.Status}"); Assert.NotNull(downloadResult); Assert.Equal(FileDownloader.DownloadStatus.Success, downloadResult.Status); }