Skip to content

Commit

Permalink
refactore unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bezzad committed Nov 17, 2023
1 parent e8e995e commit 68e6171
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,24 @@ public async Task DownloadUrlWithFilenameOnMemoryTest()
{
// arrange
var downloadCompletedSuccessfully = false;
var resultMessage = "";
var downloader = new DownloadService(Config);
downloader.DownloadFileCompleted += (s, e) => {
if (e.Cancelled == false && e.Error == null)
{
downloadCompletedSuccessfully = true;
}
else
{
resultMessage = e.Error?.Message;
}
};

// act
using var memoryStream = await downloader.DownloadFileTaskAsync(URL);

// assert
Assert.True(downloadCompletedSuccessfully);
Assert.True(downloadCompletedSuccessfully, resultMessage);
Assert.NotNull(memoryStream);
Assert.True(downloader.Package.IsSaveComplete);
Assert.Null(downloader.Package.FileName);
Expand Down Expand Up @@ -162,7 +167,7 @@ public async Task Download16KbOnMemoryTest()
var fileBytes = await downloader.DownloadFileTaskAsync(URL);

// assert
Assert.Equal(DummyFileHelper.FileSize16Kb, downloader.Package.TotalFileSize);
Assert.Equal(expected: DummyFileHelper.FileSize16Kb, actual: downloader.Package.TotalFileSize);
Assert.Equal(DummyFileHelper.FileSize16Kb, fileBytes.Length);
Assert.True(DummyFileHelper.File16Kb.AreEqual(fileBytes));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Downloader.Test/UnitTests/ChunkDownloaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ public async Task ReadStreamTest()
{
// arrange
var randomlyBytes = DummyData.GenerateRandomBytes(Size);
var chunk = new Chunk(0, Size - 1) { Timeout = 100 };
var chunk = new Chunk(0, Size - 1) { Timeout = 1000 };
var chunkDownloader = new ChunkDownloader(chunk, Configuration, Storage);
using var memoryStream = new MemoryStream(randomlyBytes);

// act
await chunkDownloader.ReadStream(memoryStream, new PauseTokenSource().Token, new CancellationToken());
Storage.Flush();
var chunkStream = Storage.OpenRead();

// assert
var chunkStream = Storage.OpenRead();
Assert.Equal(memoryStream.Length, Storage.Length);
for (int i = 0; i < Size; i++)
{
Assert.Equal(randomlyBytes[i], chunkStream.ReadByte());
Assert.Equal(expected: randomlyBytes[i], actual: chunkStream.ReadByte());
}

chunkDownloader.Chunk.Clear();
Expand Down

0 comments on commit 68e6171

Please sign in to comment.