Skip to content

Commit

Permalink
removed .net 8 sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
bezzad committed Dec 10, 2023
1 parent fa6f839 commit 4546556
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 74 deletions.
3 changes: 1 addition & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ codecov:
wait_for_ci: yes

ignore:
- "src/Downloader.Sample/**/*"
- "src/Downloader.Sample.NetFramework/**/*"
- "src/Samples/**/*"
- "src/Downloader.DummyHttpServer/**/*"
- "src/Downloader.Test/Properties/Resources.Designer.cs"
2 changes: 1 addition & 1 deletion src/Downloader.Test/Downloader.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net6.0;</TargetFrameworks>
<IsPackable>false</IsPackable>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>Sign.snk</AssemblyOriginatorKeyFile>
Expand Down
113 changes: 57 additions & 56 deletions src/Downloader.Test/IntegrationTests/DownloadIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ namespace Downloader.Test.IntegrationTests;

public abstract class DownloadIntegrationTest : IDisposable
{
private readonly ITestOutputHelper _output;
protected static byte[] FileData { get; set; }
protected readonly ITestOutputHelper Output;
protected string URL { get; set; }
protected int FileSize { get; set; }
protected string Filename { get; set; }
protected string FilePath { get; set; }
protected DownloadConfiguration Config { get; set; }
protected DownloadService Downloader { get; set; }

public DownloadIntegrationTest(ITestOutputHelper output)
{
_output = output;
Output = output;
Filename = Path.GetRandomFileName();
FilePath = Path.Combine(Path.GetTempPath(), Filename);
URL = DummyFileHelper.GetFileWithNameUrl(Filename, DummyFileHelper.FileSize16Kb);
FileSize = DummyFileHelper.FileSize16Kb;
FileData ??= DummyFileHelper.File16Kb;
URL = DummyFileHelper.GetFileWithNameUrl(Filename, FileSize);
}

public void Dispose()
Expand All @@ -39,7 +43,7 @@ protected void DownloadFileCompleted(object sender, System.ComponentModel.AsyncC
{
if (e.Error is not null)
{
_output.WriteLine("Error when completed: " + e.Error.Message.ToString());
Output.WriteLine("Error when completed: " + e.Error.Message.ToString());
}
}

Expand Down Expand Up @@ -68,10 +72,10 @@ public async Task DownloadUrlWithFilenameOnMemoryTest()
Assert.NotNull(memoryStream);
Assert.True(Downloader.Package.IsSaveComplete);
Assert.Null(Downloader.Package.FileName);
Assert.Equal(DummyFileHelper.FileSize16Kb, memoryStream.Length);
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.Equal(FileSize, memoryStream.Length);
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.Equal(100.0, Downloader.Package.SaveProgress);
Assert.True(DummyFileHelper.File16Kb.AreEqual(memoryStream));
Assert.True(FileData.AreEqual(memoryStream));
}

[Fact]
Expand Down Expand Up @@ -101,9 +105,9 @@ public async Task DownloadAndReadFileOnDownloadFileCompletedEventTest()
Assert.True(downloadCompletedSuccessfully);
Assert.NotNull(downloadedBytes);
Assert.Equal(destFilename, Downloader.Package.FileName);
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.Equal(DummyFileHelper.FileSize16Kb, downloadedBytes.Length);
Assert.True(DummyFileHelper.File16Kb.SequenceEqual(downloadedBytes));
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.Equal(FileSize, downloadedBytes.Length);
Assert.True(FileData.SequenceEqual(downloadedBytes));

File.Delete(destFilename);
}
Expand All @@ -123,8 +127,8 @@ public async Task Download16KbWithoutFilenameOnDirectoryTest()
Assert.NotNull(Downloader.Package.FileName);
Assert.StartsWith(DummyFileHelper.TempDirectory, Downloader.Package.FileName);
Assert.Equal(FilePath, Downloader.Package.FileName);
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.True(DummyFileHelper.File16Kb.AreEqual(File.OpenRead(Downloader.Package.FileName)));
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.True(FileData.AreEqual(File.OpenRead(Downloader.Package.FileName)));

File.Delete(FilePath);
}
Expand All @@ -139,8 +143,8 @@ public async Task Download16KbWithFilenameTest()
Assert.True(File.Exists(Downloader.Package.FileName));
Assert.NotNull(Downloader.Package.FileName);
Assert.StartsWith(DummyFileHelper.TempDirectory, Downloader.Package.FileName);
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.True(DummyFileHelper.File16Kb.AreEqual(File.OpenRead(Downloader.Package.FileName)));
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.True(FileData.AreEqual(File.OpenRead(Downloader.Package.FileName)));

File.Delete(Downloader.Package.FileName);
}
Expand Down Expand Up @@ -178,16 +182,16 @@ public async Task Download16KbOnMemoryTest()
var fileBytes = await Downloader.DownloadFileTaskAsync(URL);

// assert
Assert.Equal(expected: DummyFileHelper.FileSize16Kb, actual: Downloader.Package.TotalFileSize);
Assert.Equal(DummyFileHelper.FileSize16Kb, fileBytes.Length);
Assert.True(DummyFileHelper.File16Kb.AreEqual(fileBytes));
Assert.Equal(expected: FileSize, actual: Downloader.Package.TotalFileSize);
Assert.Equal(FileSize, fileBytes.Length);
Assert.True(FileData.AreEqual(fileBytes));
}

[Fact]
public async Task DownloadProgressChangedTest()
{
// arrange
var progressChangedCount = (int)Math.Ceiling((double)DummyFileHelper.FileSize16Kb / Config.BufferBlockSize);
var progressChangedCount = (int)Math.Ceiling((double)FileSize / Config.BufferBlockSize);
var progressCounter = 0;
Downloader.DownloadProgressChanged += (s, e) => Interlocked.Increment(ref progressCounter);

Expand Down Expand Up @@ -241,11 +245,11 @@ public async Task StopResumeDownloadTest()

// assert
Assert.True(File.Exists(Downloader.Package.FileName));
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.Equal(expectedStopCount, stopCount);
Assert.Equal(expectedStopCount, cancellationsOccurrenceCount);
Assert.True(downloadCompletedSuccessfully);
Assert.True(DummyFileHelper.File16Kb.SequenceEqual(stream.ToArray()));
Assert.True(FileData.SequenceEqual(stream.ToArray()));

File.Delete(Downloader.Package.FileName);
}
Expand Down Expand Up @@ -278,10 +282,10 @@ public async Task PauseResumeDownloadTest()
// assert
Assert.False(Downloader.IsPaused);
Assert.True(File.Exists(Downloader.Package.FileName));
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.Equal(expectedPauseCount, pauseCount);
Assert.True(downloadCompletedSuccessfully);
Assert.True(DummyFileHelper.File16Kb.SequenceEqual(stream.ToArray()));
Assert.True(FileData.SequenceEqual(stream.ToArray()));

File.Delete(Downloader.Package.FileName);
}
Expand Down Expand Up @@ -316,9 +320,9 @@ public async Task StopResumeDownloadFromLastPositionTest()
}

// assert
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.Equal(DummyFileHelper.FileSize16Kb, totalProgressedByteSize);
Assert.Equal(DummyFileHelper.FileSize16Kb, totalReceivedBytes);
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.Equal(FileSize, totalProgressedByteSize);
Assert.Equal(FileSize, totalReceivedBytes);
}

[Fact]
Expand Down Expand Up @@ -357,8 +361,8 @@ public async Task StopResumeDownloadOverFirstPackagePositionTest()
Assert.False(Downloader.Package.IsSaving);
Assert.False(isSavingStateOnCancel);
Assert.True(isSavingStateBeforCancel);
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.Equal(DummyFileHelper.FileSize16Kb, result.Length);
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.Equal(FileSize, result.Length);
}

[Fact]
Expand All @@ -373,7 +377,7 @@ public async Task TestTotalReceivedBytesWhenResumeDownload()
Downloader.DownloadProgressChanged += async (s, e) => {
totalDownloadSize += e.ReceivedBytes.Length;
lastProgressPercentage = e.ProgressPercentage;
if (canStopDownload && totalDownloadSize > DummyFileHelper.FileSize16Kb / 2)
if (canStopDownload && totalDownloadSize > FileSize / 2)
{
// Stopping after start of downloading
await Downloader.CancelTaskAsync();
Expand All @@ -388,8 +392,8 @@ public async Task TestTotalReceivedBytesWhenResumeDownload()
// assert
Assert.True(Downloader.Package.IsSaveComplete);
Assert.False(Downloader.IsCancelled);
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.Equal(DummyFileHelper.FileSize16Kb, totalDownloadSize);
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.Equal(FileSize, totalDownloadSize);
Assert.Equal(100.0, lastProgressPercentage);
}

Expand All @@ -405,7 +409,7 @@ public async Task TestTotalReceivedBytesOnResumeDownloadWhenLostDownloadedData()
Downloader.DownloadProgressChanged += (s, e) => {
totalDownloadSize = e.ReceivedBytesSize;
lastProgressPercentage = e.ProgressPercentage;
if (canStopDownload && totalDownloadSize > DummyFileHelper.FileSize16Kb / 2)
if (canStopDownload && totalDownloadSize > FileSize / 2)
{
// Stopping after start of downloading
Downloader.CancelAsync();
Expand All @@ -419,8 +423,8 @@ public async Task TestTotalReceivedBytesOnResumeDownloadWhenLostDownloadedData()
await Downloader.DownloadFileTaskAsync(Downloader.Package); // resume download from stopped point.

// assert
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.Equal(DummyFileHelper.FileSize16Kb, totalDownloadSize);
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.Equal(FileSize, totalDownloadSize);
Assert.Equal(100.0, lastProgressPercentage);
Assert.Equal(100.0, Downloader.Package.SaveProgress);
}
Expand All @@ -444,7 +448,7 @@ public async Task SpeedLimitTest()
await Downloader.DownloadFileTaskAsync(URL);

// assert
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.True(averageSpeed <= Config.MaximumBytesPerSecond * 1.5, $"Average Speed: {averageSpeed} , Speed Limit: {Config.MaximumBytesPerSecond}");
}

Expand All @@ -453,10 +457,10 @@ public async Task DynamicSpeedLimitTest()
{
// arrange
double upperTolerance = 1.5; // 50% upper than expected avg speed
double expectedAverageSpeed = DummyFileHelper.FileSize16Kb / 32; // == (256*16 + 512*8 + 1024*4 + 2048*2) / 32
double expectedAverageSpeed = FileSize / 32; // == (256*16 + 512*8 + 1024*4 + 2048*2) / 32
double averageSpeed = 0;
var progressCounter = 0;
const int oneSpeedStepSize = 4096; // DummyFileHelper.FileSize16Kb / 4
const int oneSpeedStepSize = 4096; // FileSize / 4

Config.MaximumBytesPerSecond = 256; // Byte/s

Expand All @@ -474,7 +478,7 @@ public async Task DynamicSpeedLimitTest()
averageSpeed /= progressCounter;

// assert
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.True(averageSpeed <= expectedAverageSpeed * upperTolerance,
$"Avg Speed: {averageSpeed} , Expected Avg Speed Limit: {expectedAverageSpeed * upperTolerance}, " +
$"Progress Count: {progressCounter}");
Expand All @@ -490,8 +494,8 @@ public async Task TestSizeWhenDownloadOnMemoryStream()
using var stream = await Downloader.DownloadFileTaskAsync(URL);

// assert
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.Equal(DummyFileHelper.FileSize16Kb, stream.Length);
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.Equal(FileSize, stream.Length);
}

[Fact]
Expand All @@ -510,15 +514,12 @@ public async Task TestTypeWhenDownloadOnMemoryStream()
[Fact]
public async Task TestContentWhenDownloadOnMemoryStream()
{
// arrange


// act
using var stream = await Downloader.DownloadFileTaskAsync(URL);
var memStream = stream as MemoryStream;
var data = (stream as MemoryStream).ToArray();

// assert
Assert.True(DummyFileHelper.File16Kb.SequenceEqual(memStream.ToArray()));
Assert.True(FileData.SequenceEqual(data));
}

[Fact(Timeout = 60_000)]
Expand Down Expand Up @@ -588,10 +589,10 @@ public async Task TestDownloadParallelVsHalfOfChunks()
// assert
Assert.True(maxParallelCountTasks >= actualMaxParallelCountTasks);
Assert.NotNull(stream);
Assert.Equal(DummyFileHelper.FileSize16Kb, stream.Length);
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.Equal(FileSize, stream.Length);
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.Equal(100.0, Downloader.Package.SaveProgress);
for (int i = 0; i < DummyFileHelper.FileSize16Kb; i++)
for (int i = 0; i < FileSize; i++)
Assert.Equal((byte)i, bytes[i]);
}

Expand Down Expand Up @@ -637,7 +638,7 @@ public async Task KeepOrRemoveFileWhenDownloadFailedTest(bool clearFileAfterFail
Config.ClearPackageOnCompletionWithFailure = clearFileAfterFailure;
var downloadService = new DownloadService(Config);
var filename = Path.GetTempFileName();
var url = DummyFileHelper.GetFileWithFailureAfterOffset(DummyFileHelper.FileSize16Kb, DummyFileHelper.FileSize16Kb / 2);
var url = DummyFileHelper.GetFileWithFailureAfterOffset(FileSize, FileSize / 2);

// act
await downloadService.DownloadFileTaskAsync(url, filename);
Expand All @@ -656,7 +657,7 @@ public async Task testRetryDownloadAfterFailure(bool timeout)
{
// arrange
Exception error = null;
var fileSize = DummyFileHelper.FileSize16Kb;
var fileSize = FileSize;
var failureOffset = fileSize / 2;
Config.MaxTryAgainOnFailover = 5;
Config.BufferBlockSize = 1024;
Expand Down Expand Up @@ -740,15 +741,15 @@ public async Task TestStopDownloadWithCancellationToken()
public async Task TestResumeDownloadWithAnotherUrl()
{
// arrange
var url1 = DummyFileHelper.GetFileWithNameUrl("file1.dat", DummyFileHelper.FileSize16Kb);
var url2 = DummyFileHelper.GetFileWithNameUrl("file2.dat", DummyFileHelper.FileSize16Kb);
var url1 = DummyFileHelper.GetFileWithNameUrl("file1.dat", FileSize);
var url2 = DummyFileHelper.GetFileWithNameUrl("file2.dat", FileSize);
var canStopDownload = true;
var totalDownloadSize = 0L;
Config.BufferBlockSize = 1024;
Config.ChunkCount = 4;
Downloader.DownloadProgressChanged += (s, e) => {
totalDownloadSize = e.ReceivedBytesSize;
if (canStopDownload && totalDownloadSize > DummyFileHelper.FileSize16Kb / 2)
if (canStopDownload && totalDownloadSize > FileSize / 2)
{
// Stopping after start of downloading
Downloader.CancelAsync();
Expand All @@ -761,9 +762,9 @@ public async Task TestResumeDownloadWithAnotherUrl()
await Downloader.DownloadFileTaskAsync(Downloader.Package, url2); // resume download with new url2.

// assert
Assert.Equal(DummyFileHelper.FileSize16Kb, Downloader.Package.TotalFileSize);
Assert.Equal(DummyFileHelper.FileSize16Kb, totalDownloadSize);
Assert.Equal(Downloader.Package.Storage.Length, DummyFileHelper.FileSize16Kb);
Assert.Equal(FileSize, Downloader.Package.TotalFileSize);
Assert.Equal(FileSize, totalDownloadSize);
Assert.Equal(Downloader.Package.Storage.Length, FileSize);
Assert.Equal(100.0, Downloader.Package.SaveProgress);
}

Expand All @@ -776,7 +777,7 @@ public async Task DownloadAFileFromMultipleUrlsWithMultipleChunksTest(int urlsCo
// arrange
Config.ChunkCount = chunksCount;
Config.ParallelCount = chunksCount;
var totalSize = DummyFileHelper.FileSize16Kb;
var totalSize = FileSize;
var chunkSize = totalSize / Config.ChunkCount;

var urls = Enumerable.Range(1, urlsCount)
Expand Down
2 changes: 1 addition & 1 deletion src/Downloader/Downloader.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net452;net6.0;net8.0;</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net452;net6.0;</TargetFrameworks>
<LangVersion>latestMajor</LangVersion>
<Version>3.0.6</Version>
<Title>Downloader</Title>
Expand Down
16 changes: 2 additions & 14 deletions src/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
version: '3.8'
version: '3.9'

# NOTE: do not execute both win and linux services, because both of them are using port 3333
services:

#windows-net6:
# image: mcr.microsoft.com/windows/servercore:ltsc2022
# build:
# context: .
# dockerfile: ./dockerfile
# environment:
# - ASPNETCORE_ENVIRONMENT=Development
# volumes:
# - .:/app
# working_dir: /app
# container_name: downloader-win

linux-net6:
linux-net:
image: mcr.microsoft.com/dotnet/sdk:6.0
build:
context: .
Expand Down

0 comments on commit 4546556

Please sign in to comment.