When passing a CancellationToken to DownloadFileTaskAsync, I'm expecting the method to throw an OperationCanceledException if the cancellation has been requested and the download is cancelled.
This would allow me to manage the cancellation properly later in my code.
This does not seem to be the case today: this test should not fail:
[Test]
public void RequestingCancellation_Throws_OperationCanceledException()
{
// Arrange
const string fileUrl = "https://www.examplefile.com/file-download/202"; // 1 GB txt file
var cts = new CancellationTokenSource();
cts.CancelAfter(500);
Assert.ThrowsAsync<OperationCanceledException>(async () =>
{
// Act
await _sut.DownloadFileTaskAsync(fileUrl, cts.Token);
});
}