Skip to content

Commit

Permalink
Rename TorrentWebPageServiceTests to TorrentWebPageClientTests, make …
Browse files Browse the repository at this point in the history
…the tests contain their own test data
  • Loading branch information
aannenko committed Sep 16, 2024
1 parent 4bcbdce commit da9849b
Showing 1 changed file with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,9 @@
namespace TransmissionManager.TorrentWebPages.Tests;

[Parallelizable(ParallelScope.Self)]
public sealed class TorrentWebPageServiceTests
public sealed class TorrentWebPageClientTests
{
private const string _webPageUri = "https://torrentTracker.com/forum/viewtopic.php?t=1234567";
private const string _magnetUri = "magnet:?xt=urn:btih:EXAMPLEHASH&dn=Example+Name";
private const string _webPageContentWithMagnet = $"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Magnet Link Example</title>
</head>
<body>
<h1>Magnet Link Example</h1>
<p>Click the link below to open the Magnet URI:</p>
<a href="{_magnetUri}">Download via Magnet</a>
</body>
</html>
""";

private const string _webPageContentWithoutMagnet = $"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Magnet Link Example</title>
</head>
<body>
<h1>Magnet Link Example</h1>
<p>No Magnet URI for you today :(</p>
</body>
</html>
""";

private static readonly FakeOptionsMonitor<TorrentWebPageServiceOptions> _options = new(new()
{
Expand All @@ -52,6 +21,23 @@ public sealed class TorrentWebPageServiceTests
[Test]
public async Task FindMagnetUriAsync_FindsMagnetUri_IfGivenProperWebPage()
{
const string _magnetUri = "magnet:?xt=urn:btih:EXAMPLEHASH&dn=Example+Name";
const string _webPageContentWithMagnet = $"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Magnet Link Example</title>
</head>
<body>
<h1>Magnet Link Example</h1>
<p>Click the link below to open the Magnet URI:</p>
<a href="{_magnetUri}">Download via Magnet</a>
</body>
</html>
""";

var service = CreateClient(
new(HttpMethod.Get, new(_webPageUri)),
new(HttpStatusCode.OK, Content: _webPageContentWithMagnet));
Expand All @@ -64,6 +50,21 @@ public async Task FindMagnetUriAsync_FindsMagnetUri_IfGivenProperWebPage()
[Test]
public async Task FindMagnetUriAsync_FindsMagnetUri_IfGivenWebPageWithoutMagnet()
{
const string _webPageContentWithoutMagnet = $"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Magnet Link Example</title>
</head>
<body>
<h1>Magnet Link Example</h1>
<p>No Magnet URI for you today :(</p>
</body>
</html>
""";

var service = CreateClient(
new(HttpMethod.Get, new(_webPageUri)),
new(HttpStatusCode.OK, Content: _webPageContentWithoutMagnet));
Expand Down

0 comments on commit da9849b

Please sign in to comment.