diff --git a/src/Downloader.Test/IntegrationTests/DownloadIntegrationTest.cs b/src/Downloader.Test/IntegrationTests/DownloadIntegrationTest.cs index d17ef31..254ca72 100644 --- a/src/Downloader.Test/IntegrationTests/DownloadIntegrationTest.cs +++ b/src/Downloader.Test/IntegrationTests/DownloadIntegrationTest.cs @@ -12,7 +12,7 @@ namespace Downloader.Test.IntegrationTests; -public abstract class DownloadIntegrationTest +public abstract class DownloadIntegrationTest : IDisposable { private readonly ITestOutputHelper _output; protected string URL { get; set; } @@ -29,6 +29,12 @@ public DownloadIntegrationTest(ITestOutputHelper output) URL = DummyFileHelper.GetFileWithNameUrl(Filename, DummyFileHelper.FileSize16Kb); } + public void Dispose() + { + if (File.Exists(FilePath)) + File.Delete(FilePath); + } + protected void DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { if (e.Error is not null) @@ -839,4 +845,31 @@ public async Task DownloadBigFileOnMemory() Assert.Equal(100.0, Downloader.Package.SaveProgress); Assert.True(actualFile.AreEqual(stream)); } + + [Fact] + public async Task DownloadBigFileWithMemoryLimitationOnDisk() + { + // arrange + var totalSize = 1024 * 1024 * 1024; // 1GB + //Downloader.AddLogger(new FileLogger($"D:\\TestDownload\\DownloadBigFileOnDisk_{DateTime.Now.ToString("yyyyMMdd.HHmmss")}.log")); + byte fillByte = 123; + Config.ChunkCount = 16; + Config.ParallelCount = 16; + Config.MaximumBytesPerSecond = 0; + Config.MaximumMemoryBufferBytes = 1024 * 1024 * 100; // 100MB + URL = DummyFileHelper.GetFileWithNameUrl(Filename, totalSize, fillByte); + + // act + await Downloader.DownloadFileTaskAsync(URL, FilePath); + using var fileStream = File.Open(FilePath, FileMode.Open, FileAccess.Read); + + // assert + Assert.Equal(totalSize, Downloader.Package.TotalFileSize); + Assert.Equal(totalSize, fileStream.Length); + Assert.Equal(100.0, Downloader.Package.SaveProgress); + for (int i = 0; i < totalSize; i++) + { + Assert.Equal(fillByte, fileStream.ReadByte()); + } + } } \ No newline at end of file diff --git a/src/Downloader.Test/IntegrationTests/ParallelDownloadIntegrationTest.cs b/src/Downloader.Test/IntegrationTests/ParallelDownloadIntegrationTest.cs index 0de18b3..46fac99 100644 --- a/src/Downloader.Test/IntegrationTests/ParallelDownloadIntegrationTest.cs +++ b/src/Downloader.Test/IntegrationTests/ParallelDownloadIntegrationTest.cs @@ -1,5 +1,4 @@ -using Downloader.Test.Helper; -using Xunit.Abstractions; +using Xunit.Abstractions; namespace Downloader.Test.IntegrationTests; diff --git a/src/Downloader.Test/IntegrationTests/SerialDownloadIntegrationTest.cs b/src/Downloader.Test/IntegrationTests/SerialDownloadIntegrationTest.cs index cee395d..1639cfb 100644 --- a/src/Downloader.Test/IntegrationTests/SerialDownloadIntegrationTest.cs +++ b/src/Downloader.Test/IntegrationTests/SerialDownloadIntegrationTest.cs @@ -1,5 +1,4 @@ -using Downloader.Test.Helper; -using Xunit.Abstractions; +using Xunit.Abstractions; namespace Downloader.Test.IntegrationTests; @@ -17,5 +16,5 @@ public SerialDownloadIntegrationTest(ITestOutputHelper output) : base(output) Downloader = new DownloadService(Config); Downloader.DownloadFileCompleted += DownloadFileCompleted; - } + } }