public async Task GetSpecificSubredditAsync_WhenRedditKnownSubredditIsNull_ThrowsArgumentNullException() { IRedditAccessToken accessToken = CreateRedditAccessToken(); const IRedditKnownSubreddit knownSubreddit = null; IRedditLogic sut = CreateSut(); await sut.GetSpecificSubredditAsync(accessToken, knownSubreddit); }
public async Task GetSpecificSubredditAsync_WhenAccessTokenIsNull_ThrowsArgumentNullException() { const IRedditAccessToken accessToken = null; IRedditKnownSubreddit knownSubreddit = CreateRedditKnownSubreddit(); IRedditRepository sut = CreateSut(); await sut.GetSpecificSubredditAsync(accessToken, knownSubreddit); }
public async Task GetSpecificSubredditAsync_WhenCalled_AssertWillExceedRateLimitWasCalledOnRedditRateLimitLogic() { IRedditAccessToken accessToken = CreateRedditAccessToken(); IRedditKnownSubreddit knownSubreddit = CreateRedditKnownSubreddit(); IRedditLogic sut = CreateSut(); await sut.GetSpecificSubredditAsync(accessToken, knownSubreddit); _redditRateLimitLogicMock.Verify(m => m.WillExceedRateLimit(It.Is <int>(value => value == 1)), Times.Once); }
public async Task GetSpecificSubredditAsync_WhenCalledAndRedditRateLimitHasExceeded_ReturnsNull() { IRedditAccessToken accessToken = CreateRedditAccessToken(); IRedditKnownSubreddit knownSubreddit = CreateRedditKnownSubreddit(); const bool willExceedRateLimit = true; IRedditLogic sut = CreateSut(willExceedRateLimit: willExceedRateLimit); IRedditSubreddit result = await sut.GetSpecificSubredditAsync(accessToken, knownSubreddit); Assert.IsNull(result); }
public async Task GetSpecificSubredditAsync_WhenCalledAndRedditRateLimitHasNotExceededAndExceptionOccurs_ReturnsNull() { IRedditAccessToken accessToken = CreateRedditAccessToken(); IRedditKnownSubreddit knownSubreddit = CreateRedditKnownSubreddit(); const bool willExceedRateLimit = false; Exception exception = new Exception(); IRedditLogic sut = CreateSut(willExceedRateLimit: willExceedRateLimit, exception: exception); IRedditSubreddit result = await sut.GetSpecificSubredditAsync(accessToken, knownSubreddit); Assert.IsNull(result); }
public async Task GetSpecificSubredditAsync_WhenCalledAndRedditRateLimitHasNotExceededAndExceptionOccurs_AssertHandleAsyncWasCalledOnExceptionHandler() { IRedditAccessToken accessToken = CreateRedditAccessToken(); IRedditKnownSubreddit knownSubreddit = CreateRedditKnownSubreddit(); const bool willExceedRateLimit = false; Exception exception = new Exception(); IRedditLogic sut = CreateSut(willExceedRateLimit: willExceedRateLimit, exception: exception); await sut.GetSpecificSubredditAsync(accessToken, knownSubreddit); _exceptionHandlerMock.Verify(m => m.HandleAsync(It.Is <Exception>(value => value == exception)), Times.Once); }
public async Task GetSpecificSubredditAsync_WhenCalledAndRedditRateLimitHasNotExceeded_AssertHandleAsyncWasNotCalledOnExceptionHandler() { IRedditAccessToken accessToken = CreateRedditAccessToken(); IRedditKnownSubreddit knownSubreddit = CreateRedditKnownSubreddit(); const bool willExceedRateLimit = false; IRedditLogic sut = CreateSut(willExceedRateLimit: willExceedRateLimit); await sut.GetSpecificSubredditAsync(accessToken, knownSubreddit); _exceptionHandlerMock.Verify(m => m.HandleAsync(It.IsAny <AggregateException>()), Times.Never); _exceptionHandlerMock.Verify(m => m.HandleAsync(It.IsAny <Exception>()), Times.Never); }
public async Task GetSpecificSubredditAsync_WhenCalledAndRedditRateLimitHasExceeded_AssertGetSpecificSubredditAsyncWasNotCalledOnRedditRepository() { IRedditAccessToken accessToken = CreateRedditAccessToken(); IRedditKnownSubreddit knownSubreddit = CreateRedditKnownSubreddit(); const bool willExceedRateLimit = true; IRedditLogic sut = CreateSut(willExceedRateLimit: willExceedRateLimit); await sut.GetSpecificSubredditAsync(accessToken, knownSubreddit); _redditRepositoryMock.Verify(m => m.GetSpecificSubredditAsync( It.IsAny <IRedditAccessToken>(), It.IsAny <IRedditKnownSubreddit>()), Times.Never); }
public async Task GetSpecificSubredditAsync_WhenCalledAndRedditRateLimitHasNotExceeded_ReturnsSubreddit() { IRedditAccessToken accessToken = CreateRedditAccessToken(); IRedditKnownSubreddit knownSubreddit = CreateRedditKnownSubreddit(); const bool willExceedRateLimit = false; IRedditSubreddit subreddit = CreateSubreddit(); IRedditResponse <IRedditSubreddit> redditResponse = CreateRedditResponse(subreddit: subreddit); IRedditLogic sut = CreateSut(willExceedRateLimit: willExceedRateLimit, redditResponse: redditResponse); IRedditSubreddit result = await sut.GetSpecificSubredditAsync(accessToken, knownSubreddit); Assert.IsNotNull(result); Assert.AreEqual(subreddit, result); }
public async Task GetSpecificSubredditAsync_WhenCalled_AssertHandleAsyncWasCalledOnExceptionHandler() { IRedditAccessToken redditAccessToken = CreateRedditAccessToken(); IRedditKnownSubreddit knownSubreddit = CreateRedditKnownSubreddit(); IRedditRepository sut = CreateSut(); await sut.GetSpecificSubredditAsync(redditAccessToken, knownSubreddit); _exceptionHandlerMock.Verify(m => m.HandleAsync(It.Is <Exception>(exception => exception != null && exception.InnerException == null && exception.GetType() == typeof(UnauthorizedAccessException))), Times.Once()); }
private async Task GetKnownNsfwSubredditsAsync_WhenCalled_ExpectKnownNsfwSubredditsContainsName(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } IDataProviderFactory sut = CreateSut(); IEnumerable <IRedditKnownSubreddit> knownNsfwSubreddits = await sut.GetKnownNsfwSubredditsAsync(); Assert.IsNotNull(knownNsfwSubreddits); Assert.AreEqual(NumberOfKnownNsfwSubreddits, knownNsfwSubreddits.Count()); IRedditKnownSubreddit knownNsfwSubreddit = knownNsfwSubreddits.SingleOrDefault(m => string.Compare(m.Name, name, false) == 0); Assert.IsNotNull(knownNsfwSubreddit); Assert.IsTrue(knownNsfwSubreddit.Rank >= _minRank && knownNsfwSubreddit.Rank <= _maxRank); }
public async Task GetSpecificSubredditAsync_WhenCalledAndRedditRateLimitHasNotExceeded_AssertEnforceRateLimitAsyncWasCalledOnRedditRateLimitLogic() { IRedditAccessToken accessToken = CreateRedditAccessToken(); IRedditKnownSubreddit knownSubreddit = CreateRedditKnownSubreddit(); const bool willExceedRateLimit = false; int rateLimitUsed = _random.Next(1, 60); int rateLimitRemaining = _random.Next(1, 60); DateTime rateLimitResetTime = DateTime.Now.AddSeconds(_random.Next(90, 300)); DateTime receivedTime = DateTime.Now.AddSeconds(_random.Next(1, 10) * -1); IRedditResponse <IRedditSubreddit> redditResponse = CreateRedditResponse(rateLimitUsed, rateLimitRemaining, rateLimitResetTime, receivedTime); IRedditLogic sut = CreateSut(willExceedRateLimit: willExceedRateLimit, redditResponse: redditResponse); await sut.GetSpecificSubredditAsync(accessToken, knownSubreddit); _redditRateLimitLogicMock.Verify(m => m.EnforceRateLimitAsync( It.Is <int>(value => value == rateLimitUsed), It.Is <int>(value => value == rateLimitRemaining), It.Is <DateTime?>(value => value.HasValue && value.Value == rateLimitResetTime), It.Is <DateTime>(value => value == receivedTime)), Times.Once); }
public async Task <IRedditResponse <IRedditSubreddit> > GetSpecificSubredditAsync(IRedditAccessToken accessToken, IRedditKnownSubreddit knownSubreddit) { if (accessToken == null) { throw new ArgumentNullException(nameof(accessToken)); } if (knownSubreddit == null) { throw new ArgumentNullException(nameof(knownSubreddit)); } try { IRedditResponse <RedditListChild <RedditSubreddit> > response = await GetAsync <RedditListChild <RedditSubreddit> >(new Uri($"{RedditApiUrl}/r/{knownSubreddit.Name}/about"), accessToken.TokenType, accessToken.AccessToken); return(response.As <IRedditSubreddit>(response.Data.Data)); } catch (AggregateException ex) { await _exceptionHandler.HandleAsync(ex); } catch (Exception ex) { await _exceptionHandler.HandleAsync(ex); } return(null); }