Skip to content

Commit 72598bf

Browse files
committed
fix: Update tests.
1 parent a140557 commit 72598bf

File tree

7 files changed

+32
-35
lines changed

7 files changed

+32
-35
lines changed

.vscode/launch.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"version": "0.2.0",
33
"configurations": [
4+
45
{
56
"name": ".NET Core Launch (console) - Console Example (authorization code)",
67
"type": "coreclr",

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## Unreleased - 2025-04-18
8+
9+
- Upgrade to .NET 10
10+
- Deprecate ability to award user content, due to Reddit API removal
11+
712
## [2.3.0] - 2022-11-04
813

914
- Add ability to load unresolved comment threads

src/Reddit.NET.Client/Command/Subreddits/CreateSubredditSubmissionCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public class Parameters
110110
/// <summary>
111111
/// Gets or sets a value indicating whether the submission should be resubmitted if it already exists.
112112
/// </summary>
113+
[Obsolete("No longer supported by the Reddit API.")]
113114
public bool ForceResubmit { get; set; }
114115

115116
/// <summary>

src/Reddit.NET.Client/Interactions/Abstract/UserContentInteractor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Threading;
23
using System.Threading.Tasks;
34
using Microsoft;
@@ -94,6 +95,7 @@ public async Task UnsaveAsync(CancellationToken cancellationToken = default) =>
9495
/// </remarks>
9596
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that may be used to cancel the asynchronous operation.</param>
9697
/// <returns>A task representing the asynchronous operation.</returns>
98+
[Obsolete("Reddit has removed the ability to award content from their API.")]
9799
public async Task AwardAsync(CancellationToken cancellationToken = default)
98100
{
99101
var awardContentCommand = new AwardContentCommand(new AwardContentCommand.Parameters()

tests/Reddit.NET.Client.IntegrationTests/CommentInteractorTests.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using System.Net;
34
using System.Security.Cryptography;
45
using System.Threading.Tasks;
56
using NUnit.Framework;
@@ -169,19 +170,17 @@ public async Task UnsaveAsync_ValidSubmission_ShouldUnsave()
169170
Assert.IsFalse(commentDetails.Saved);
170171
}
171172

172-
// Note we are only testing the failure scenario as otherwise it would
173-
// require a testing account with a balance which means $$$.
173+
// Note the ability to award via the API has been removed, so we're just testing it errors as expected.
174174
[Test]
175-
public void AwardAsync_InsufficientCoins_ThrowsRedditClientApiException()
175+
public void AwardAsync_AnyComment_ThrowsRedditClientResponseException()
176176
{
177177
// https://old.reddit.com/r/AskReddit/comments/9whgf4/stan_lee_has_passed_away_at_95_years_old/e9kveve/
178178
var comment = _client.Comment(submissionId: "9whgf4", commentId: "e9kveve");
179179

180-
var exception = Assert.ThrowsAsync<RedditClientApiException>(async () => await comment.AwardAsync());
180+
var exception = Assert.ThrowsAsync<RedditClientResponseException>(async () => await comment.AwardAsync());
181181

182182
Assert.IsNotNull(exception);
183-
Assert.IsNotNull(exception.Details);
184-
Assert.AreEqual("INSUFFICIENT_COINS", exception.Details.Type);
183+
Assert.AreEqual(HttpStatusCode.NotFound, exception.StatusCode);
185184
}
186185

187186
[Test]
@@ -213,6 +212,9 @@ public async Task EditAsync_ExistingComment_ShouldUpdateCommentText()
213212

214213
await comment.EditAsync(updatedText);
215214

215+
// Small delay as sometimes the reload doesn't work immediately.
216+
await Task.Delay(TimeSpan.FromSeconds(3));
217+
216218
await commentDetails.ReloadAsync(_client);
217219

218220
Assert.IsNotNull(commentDetails);

tests/Reddit.NET.Client.IntegrationTests/SubmissionInteractorTests.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using System.Net;
34
using System.Threading.Tasks;
45
using NUnit.Framework;
56
using Reddit.NET.Client.Exceptions;
@@ -57,8 +58,8 @@ public async Task GetDetailsAsync_ReloadModel_ShouldGetDetails()
5758
[Test]
5859
public async Task GetDuplicatesAsync_ValidSubmission_ShouldGetDuplicates()
5960
{
60-
// https://old.reddit.com/r/programming/comments/ybmnzb/tomorrow_is_unix_timestamp_1666666666_peak/
61-
var submission = _client.Submission("ybmnzb");
61+
// https://old.reddit.com/r/programming/comments/1jwmwdy/linus_torvalds_built_git_in_10_days_and_never/
62+
var submission = _client.Submission("1jwmwdy");
6263

6364
var submissionDetails = await submission.GetDetailsAsync();
6465

@@ -221,10 +222,9 @@ public async Task UnsaveAsync_ValidSubmission_ShouldUnsave()
221222
Assert.IsFalse(submissionDetails.Saved);
222223
}
223224

224-
// Note we are only testing the failure scenario as otherwise it would
225-
// require a testing account with a balance which means $$$.
225+
// Note the ability to award via the API has been removed, so we're just testing it errors as expected.
226226
[Test]
227-
public async Task AwardAsync_InsufficientCoins_ThrowsRedditClientApiException()
227+
public async Task AwardAsync_AnySubmission_ThrowsRedditClientResponseException()
228228
{
229229
var subreddit = _client.Subreddit(Environment.GetEnvironmentVariable("TEST_SUBREDDIT_NAME"));
230230

@@ -240,11 +240,10 @@ public async Task AwardAsync_InsufficientCoins_ThrowsRedditClientApiException()
240240

241241
var submission = submissionDetails.Interact(_client);
242242

243-
var exception = Assert.ThrowsAsync<RedditClientApiException>(async () => await submission.AwardAsync());
243+
var exception = Assert.ThrowsAsync<RedditClientResponseException>(async () => await submission.AwardAsync());
244244

245245
Assert.IsNotNull(exception);
246-
Assert.IsNotNull(exception.Details);
247-
Assert.AreEqual("INSUFFICIENT_COINS", exception.Details.Type);
246+
Assert.AreEqual(HttpStatusCode.NotFound, exception.StatusCode);
248247
}
249248

250249
[Test]

tests/Reddit.NET.Client.IntegrationTests/SubredditInteractorTests.cs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ public class SubredditInteractorTests
1717
[SetUp]
1818
public void Setup()
1919
{
20+
Environment.SetEnvironmentVariable("TEST_REDDIT_USERNAME", "reddit-client-tests1");
21+
Environment.SetEnvironmentVariable("TEST_REDDIT_PASSWORD", "nR6!WxETLVL:U$nW");
22+
Environment.SetEnvironmentVariable("TEST_REDDIT_CLIENT_ID", "its0xF_8bLi8Hgp7qfhkQg");
23+
Environment.SetEnvironmentVariable("TEST_REDDIT_CLIENT_SECRET", "kwoBYfI-HvxwNkwztyxzZ3iVW3EQcg");
24+
Environment.SetEnvironmentVariable("TEST_SUBREDDIT_NAME", "redditclienttests1");
25+
2026
_client = TestRedditClientProvider.GetScriptClient();
2127
}
2228

@@ -196,14 +202,13 @@ public async Task UnsubscribeAsync_ValidSubreddit_ShouldUnsubscribe()
196202
}
197203

198204
[Test]
199-
public async Task CreateSubmissionAsync_LinkSubmissionWithResubmit_ShouldCreateLinkSubmission()
205+
public async Task CreateSubmissionAsync_LinkSubmission_ShouldCreateLinkSubmission()
200206
{
201207
var subreddit = _client.Subreddit(Environment.GetEnvironmentVariable("TEST_SUBREDDIT_NAME"));
202208

203209
var newSubmissionDetails = new LinkSubmissionCreationDetails(
204210
title: $"Test submission {Guid.NewGuid()}",
205-
uri: new Uri("https://github.com/JedS6391/Reddit.NET"),
206-
resubmit: true);
211+
uri: new Uri("https://github.com/JedS6391/Reddit.NET"));
207212

208213
var createdSubmission = await subreddit.CreateSubmissionAsync(newSubmissionDetails);
209214

@@ -212,24 +217,6 @@ public async Task CreateSubmissionAsync_LinkSubmissionWithResubmit_ShouldCreateL
212217
Assert.IsTrue(createdSubmission.Url == newSubmissionDetails.Uri.AbsoluteUri);
213218
}
214219

215-
[Test]
216-
public void CreateSubmissionAsync_LinkSubmissionWithoutResubmit_ThrowsRedditClientApiException()
217-
{
218-
var subreddit = _client.Subreddit(Environment.GetEnvironmentVariable("TEST_SUBREDDIT_NAME"));
219-
220-
var newSubmissionDetails = new LinkSubmissionCreationDetails(
221-
title: $"Test submission {Guid.NewGuid()}",
222-
uri: new Uri("https://github.com/JedS6391/Reddit.NET"),
223-
resubmit: false);
224-
225-
var exception = Assert.ThrowsAsync<RedditClientApiException>(async () =>
226-
await subreddit.CreateSubmissionAsync(newSubmissionDetails));
227-
228-
Assert.IsNotNull(exception);
229-
Assert.IsNotNull(exception.Details);
230-
Assert.AreEqual("ALREADY_SUB", exception.Details.Type);
231-
}
232-
233220
[Test]
234221
public async Task CreateSubmissionAsync_TextSubmission_ShouldCreateTextSubmission()
235222
{

0 commit comments

Comments
 (0)