Skip to content

Commit

Permalink
Add tests for TorrentAddDtoExtensions
Browse files Browse the repository at this point in the history
  • Loading branch information
aannenko committed Nov 21, 2024
1 parent 40a554d commit 404aa2f
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using TransmissionManager.Database.Dto;
using TransmissionManager.Database.Extensions;

namespace TransmissionManager.Database.Tests;

[Parallelizable(ParallelScope.All)]
internal sealed class TorrentAddDtoExtensionsTests
{
[Test]
public void ToTorrent_WhenGivenValidDto_ReturnsTorrentWithPropertiesCorrectlyMapped()
{
var dto = new TorrentAddDto(
hashString: "ABCDEF0123456789ABCDEF0123456789ABCDEF01",
name: "Test name",
webPageUri: new("https://torrenttracker.com/forum/viewtopic.php?t=1234570"),
downloadDir: "/tvshows",
magnetRegexPattern: @"magnet:\?xt=[^""]*",
cron: "0 9,17 * * *");

var torrent = dto.ToTorrent();

Assert.That(torrent, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(torrent.Id, Is.Zero);
Assert.That(torrent.HashString, Is.EqualTo(dto.HashString));
Assert.That(torrent.Name, Is.EqualTo(dto.Name));
Assert.That(torrent.WebPageUri, Is.EqualTo(dto.WebPageUri));
Assert.That(torrent.DownloadDir, Is.EqualTo(dto.DownloadDir));
Assert.That(torrent.MagnetRegexPattern, Is.EqualTo(dto.MagnetRegexPattern));
Assert.That(torrent.Cron, Is.EqualTo(dto.Cron));
});
}

[Test]
public void ToTorrent_WhenGivenNull_ThrowsArgumentNullException()
{
TorrentAddDto dto = null!;
Assert.That(dto.ToTorrent, Throws.ArgumentNullException);
}
}

0 comments on commit 404aa2f

Please sign in to comment.