Skip to content

Commit

Permalink
test: improve the test by verifying we got a mp4
Browse files Browse the repository at this point in the history
  • Loading branch information
Belphemur committed Apr 9, 2024
1 parent 4590803 commit 080bd00
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions SoundSwitch.Tests/FileDownloaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ namespace SoundSwitch.Tests;
[TestFixture]
public class FileDownloaderTests
{
private bool IsMP4(MemoryStream stream)
{
// Check if the stream has enough bytes for the magic number
if (stream.Length < 8)
return false;

// Read the first 8 bytes from the stream
var buffer = new byte[8];
stream.Position = 0;
stream.Read(buffer, 0, 8);

Check warning on line 23 in SoundSwitch.Tests/FileDownloaderTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Return value of [MustUseReturnValue] annotated method is not used

Return value of method is not used. Fewer bytes can be read than requested

// Check if the byte sequence matches the MP4 magic number
return buffer[0] == 0x00 && buffer[1] == 0x00 && buffer[2] == 0x00 && buffer[3] == 0x14 && buffer[4] == 0x66 && buffer[5] == 0x74 && buffer[6] == 0x79 && buffer[7] == 0x70;
}
[Test]
public async Task DownloadTest()
{
Expand All @@ -20,15 +34,16 @@ public async Task DownloadTest()
var cancellationToken = default(CancellationToken);
long downloaded = 0;
long fileSize = 0;

// Act
await FileDownloader.DownloadFileAsync(uri, stream, (l, l1) =>
{
downloaded = l;
fileSize = l1;
} , cancellationToken);
}, cancellationToken);

//Assert
downloaded.Should().Be(fileSize);
IsMP4(stream).Should().BeTrue();
}
}

0 comments on commit 080bd00

Please sign in to comment.