public void As_WhenCalled_ExpectRedditResponseWithSameValues() { int rateLimitUsed = _random.Next(100); int rateLimitRemaining = _random.Next(100); DateTime? rateLimitResetTime = _random.Next(100) > 50 ? DateTime.Now.AddSeconds(_random.Next(300)) : (DateTime?)null; DateTime receivedTime = DateTime.Now.AddSeconds(_random.Next(30, 60) * -1); MyRedditObject data = new MyRedditObject(); IRedditResponse <MyRedditObject> sut = CreateSut(rateLimitUsed: rateLimitUsed, rateLimitRemaining: rateLimitRemaining, rateLimitResetTime: rateLimitResetTime, receivedTime: receivedTime, data: data); IRedditResponse <IRedditObject> result = sut.As <IRedditObject>(); Assert.AreEqual(rateLimitUsed, result.RateLimitUsed); Assert.AreEqual(rateLimitRemaining, result.RateLimitRemaining); if (rateLimitResetTime.HasValue) { Assert.AreEqual(rateLimitResetTime.Value, result.RateLimitResetTime); Assert.AreEqual(rateLimitResetTime.Value.ToUniversalTime(), result.RateLimitResetUtcTime); } else { Assert.IsNull(result.RateLimitResetTime); Assert.IsNull(result.RateLimitResetUtcTime); } Assert.AreEqual(receivedTime, result.ReceivedTime); Assert.AreEqual(receivedTime.ToUniversalTime(), result.ReceivedUtcTime); Assert.AreEqual(data, result.Data); }
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); }
public void As_WhenCalled_ExpectDataInRedditResponseToBeInterface() { IRedditResponse <MyRedditObject> sut = CreateSut(); IRedditResponse <IRedditObject> result = sut.As <IRedditObject>(); Assert.AreEqual(typeof(IRedditObject), result.GetType().GetProperty("Data").PropertyType); }
public void As_WhenCalled_ExpectRedditResponseNotEqualToSut() { IRedditResponse <MyRedditObject> sut = CreateSut(); IRedditResponse <IRedditObject> result = sut.As <IRedditObject>(); Assert.AreNotSame(sut, result); }
public async Task <IRedditResponse <IRedditList <IRedditLink> > > GetLinksAsync(IRedditAccessToken accessToken, IRedditSubreddit subreddit) { if (accessToken == null) { throw new ArgumentNullException(nameof(accessToken)); } if (subreddit == null) { throw new ArgumentNullException(nameof(subreddit)); } try { if (subreddit.Url == null) { return(null); } string localPath = subreddit.Url.LocalPath; if (localPath.StartsWith("/")) { localPath = localPath.Substring(1); } if (localPath.EndsWith("/")) { localPath = localPath.Substring(0, localPath.Length - 1); } IRedditResponse <RedditList <RedditLink> > response = await GetAsync <RedditList <RedditLink> >(new Uri($"{RedditApiUrl}/{localPath}/new"), accessToken.TokenType, accessToken.AccessToken); foreach (RedditLink link in response.Data) { link.Subreddit = subreddit; } return(response.As <IRedditList <IRedditLink> >(response.Data.As <IRedditLink>())); } catch (AggregateException ex) { await _exceptionHandler.HandleAsync(ex); } catch (Exception ex) { await _exceptionHandler.HandleAsync(ex); } return(null); }
public async Task <IRedditResponse <IRedditList <IRedditSubreddit> > > GetSubredditsForAuthenticatedUserAsync(IRedditAccessToken accessToken) { if (accessToken == null) { throw new ArgumentNullException(nameof(accessToken)); } try { IRedditResponse <RedditList <RedditSubreddit> > response = await GetAsync <RedditList <RedditSubreddit> >(new Uri($"{RedditApiUrl}/subreddits/mine/subscriber"), accessToken.TokenType, accessToken.AccessToken); return(response.As <IRedditList <IRedditSubreddit> >(response.Data.As <IRedditSubreddit>())); } catch (AggregateException ex) { await _exceptionHandler.HandleAsync(ex); } catch (Exception ex) { await _exceptionHandler.HandleAsync(ex); } return(null); }