Skip to content

Commit

Permalink
Revert convertion of Torrent.WebPageUri to Uri type
Browse files Browse the repository at this point in the history
  • Loading branch information
aannenko committed Nov 24, 2024
1 parent 404aa2f commit 4227165
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public async Task AddTorrentAsync_WhenGivenExistingTorrentUri_ReturnsConflictRes
{
var dto = new AddTorrentRequest
{
WebPageUri = _initialTorrents[0].WebPageUri,
WebPageUri = new(_initialTorrents[0].WebPageUri),
DownloadDir = _initialTorrents[0].DownloadDir,
Cron = _initialTorrents[0].Cron,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static Torrent[] CreateInitialTorrents() =>
Id = default,
HashString = FirstTorrentHashString,
Name = FirstTorrentName,
WebPageUri = FirstTorrentWebPageUri,
WebPageUri = FirstTorrentWebPageAddress,
DownloadDir = FirstTorrentDownloadDir,
Cron = FirstTorrentCron,
},
Expand All @@ -48,7 +48,7 @@ public static Torrent[] CreateInitialTorrents() =>
Id = default,
HashString = SecondTorrentHashString,
Name = SecondTorrentName,
WebPageUri = SecondTorrentWebPageUri,
WebPageUri = SecondTorrentWebPageAddress,
DownloadDir = SecondTorrentDownloadDir,
MagnetRegexPattern = SecondTorrentMagnetRegexPattern,
},
Expand All @@ -57,7 +57,7 @@ public static Torrent[] CreateInitialTorrents() =>
Id = default,
HashString = ThirdTorrentHashString,
Name = ThirdTorrentName,
WebPageUri = ThirdTorrentWebPageUri,
WebPageUri = ThirdTorrentWebPageAddress,
DownloadDir = ThirdTorrentDownloadDir,
MagnetRegexPattern = ThirdTorrentMagnetRegexPattern,
Cron = ThirdTorrentCron,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void ToTorrent_WhenGivenValidDto_ReturnsTorrentWithPropertiesCorrectlyMap
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.WebPageUri, Is.EqualTo(dto.WebPageUri.OriginalString));
Assert.That(torrent.DownloadDir, Is.EqualTo(dto.DownloadDir));
Assert.That(torrent.MagnetRegexPattern, Is.EqualTo(dto.MagnetRegexPattern));
Assert.That(torrent.Cron, Is.EqualTo(dto.Cron));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task AddOneAsync_AddsTorrent_WhenItDoesNotConflictWithExistingTorre
Assert.That(actual!.Id, Is.EqualTo(torrentId));
Assert.That(actual.HashString, Is.EqualTo(dto.HashString));
Assert.That(actual.Name, Is.EqualTo(dto.Name));
Assert.That(actual.WebPageUri, Is.EqualTo(dto.WebPageUri));
Assert.That(actual.WebPageUri, Is.EqualTo(dto.WebPageUri.OriginalString));
Assert.That(actual.DownloadDir, Is.EqualTo(dto.DownloadDir));
Assert.That(actual.MagnetRegexPattern, Is.EqualTo(dto.MagnetRegexPattern));
Assert.That(actual.Cron, Is.EqualTo(dto.Cron));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public async Task FindPageAsync_ReturnsFilteredArrayOfTorrents_WhenWebPageUriFil
var service = new TorrentQueryService(context);

var torrents = await service
.FindPageAsync(new(2, 0), new(WebPageUri: _initialTorrents[1].WebPageUri))
.FindPageAsync(new(2, 0), new(WebPageUri: new(_initialTorrents[1].WebPageUri)))
.ConfigureAwait(false);

AssertMultipleTorrents(torrents, _initialTorrents[1..^1], [2]);
Expand All @@ -128,7 +128,7 @@ public async Task FindPageAsync_ReturnsFilteredArrayOfTorrents_WhenDowncasedWebP
using var context = CreateContext();
var service = new TorrentQueryService(context);

var upperCaseUri = new Uri(_initialTorrents[1].WebPageUri.OriginalString.ToUpperInvariant());
var upperCaseUri = new Uri(_initialTorrents[1].WebPageUri.ToUpperInvariant());
var torrents = await service.FindPageAsync(new(2, 0), new(WebPageUri: upperCaseUri)).ConfigureAwait(false);

AssertMultipleTorrents(torrents, _initialTorrents[1..^1], [2]);
Expand Down Expand Up @@ -175,7 +175,7 @@ public async Task FindPageAsync_ReturnsFilteredArrayOfTorrents_WhenMultipleFilte

var expected = _initialTorrents[2];
var torrents = await service
.FindPageAsync(new(5, 0), new(expected.HashString, expected.WebPageUri, expected.Name[..1], true))
.FindPageAsync(new(5, 0), new(expected.HashString, new(expected.WebPageUri), expected.Name[..1], true))
.ConfigureAwait(false);

AssertMultipleTorrents(torrents, [expected], [3]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<RefreshTorrentByIdOutcome> RefreshTorrentByIdAsync(long id, Ca
return new(Result.NotFoundInTransmission, null, GetError(id, transmissionGetError));

var (magnetUri, getMagnetError) = await torrentWebPageService
.GetMagnetUriAsync(torrent.WebPageUri, torrent.MagnetRegexPattern, cancellationToken)
.GetMagnetUriAsync(new(torrent.WebPageUri), torrent.MagnetRegexPattern, cancellationToken)
.ConfigureAwait(false);

if (magnetUri is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static Torrent ToTorrent(this TorrentAddDto dto)
HashString = dto.HashString,
Name = dto.Name,
DownloadDir = dto.DownloadDir,
WebPageUri = dto.WebPageUri,
WebPageUri = dto.WebPageUri.OriginalString,
MagnetRegexPattern = dto.MagnetRegexPattern,
Cron = dto.Cron,
};
Expand Down
4 changes: 3 additions & 1 deletion src/TransmissionManager.Database/Models/Torrent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public sealed class Torrent

public required string Name { get; set; }

public required Uri WebPageUri { get; set; }
#pragma warning disable CA1056 // URI-like properties should not be strings - filtering is easier with strings
public required string WebPageUri { get; set; }
#pragma warning restore CA1056 // URI-like properties should not be strings

public required string DownloadDir { get; set; }

Expand Down
3 changes: 1 addition & 2 deletions src/TransmissionManager.Database/Services/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.UseCollation(_noCaseCollation);

torrentEntity.Property(torrent => torrent.WebPageUri)
.UseCollation(_noCaseCollation)
.HasConversion(uri => uri.OriginalString, str => new Uri(str));
.UseCollation(_noCaseCollation);

torrentEntity.Property(torrent => torrent.HashString)
.UseCollation(_noCaseCollation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task<Torrent[]> FindPageAsync(
query = query.Where(torrent => torrent.HashString == filter.HashString);

if (!string.IsNullOrEmpty(filter.WebPageUri?.OriginalString))
query = query.Where(torrent => torrent.WebPageUri == filter.WebPageUri);
query = query.Where(torrent => torrent.WebPageUri == filter.WebPageUri.OriginalString);

if (!string.IsNullOrEmpty(filter.NameStartsWith))
query = query.Where(torrent => torrent.Name.StartsWith(filter.NameStartsWith));
Expand Down

0 comments on commit 4227165

Please sign in to comment.