Files

318 lines
7.6 KiB
C#
Raw Permalink Normal View History

2018-04-09 12:18:45 +02:00
using Newtonsoft.Json.Linq;
2014-03-04 22:35:50 -06:00
using Newtonsoft.Json.Schema;
using PocketSharp.Models;
2013-11-21 21:45:49 +01:00
using System;
2013-09-15 21:44:09 +02:00
using System.Collections.Generic;
2013-11-21 21:45:49 +01:00
using System.Threading.Tasks;
2013-09-15 21:44:09 +02:00
using Xunit;
using System.Linq;
2013-09-15 21:44:09 +02:00
namespace PocketSharp.Tests
{
public class GetTests : TestsBase
2013-09-15 21:44:09 +02:00
{
public GetTests() : base() { }
2013-09-15 21:44:09 +02:00
[Fact]
public async Task AreItemsRetrieved()
{
List<PocketItem> items = (await client.Get()).ToList();
2013-09-15 21:44:09 +02:00
Assert.True(items.Count > 0);
}
2013-09-19 12:13:07 +02:00
[Fact]
public async Task IsItemRetrievedById()
{
List<PocketItem> items = (await client.Get()).ToList();
2013-09-19 12:13:07 +02:00
PocketItem item = items[0];
2013-09-21 20:48:50 +02:00
PocketItem itemDuplicate = await client.Get(item.ID);
2013-09-19 12:13:07 +02:00
Assert.True(item.ID == itemDuplicate.ID);
Assert.True(item.Uri == itemDuplicate.Uri);
}
2014-03-04 22:35:50 -06:00
2018-07-03 12:20:16 +02:00
[Fact]
public async Task AreSuggestionsRetrieved()
{
var articles = await client.GetTrendingArticles();
string itemId = articles.First().ID;
List<PocketItem> suggestions = (await client.GetSuggestions(itemId)).ToList();
Assert.True(suggestions.Count > 0);
}
// [Fact]
// public async Task IsItemJsonPopulated()
// {
// List<PocketItem> items = (await client.Get()).ToList();
// string schemaJson = @"{
// 'description': 'PocketItem',
// 'type': 'object'
// }";
// JsonSchema schema = JsonSchema.Parse(schemaJson);
// foreach (var pocketItem in items)
// {
// Assert.True(!string.IsNullOrWhiteSpace(pocketItem.Json));
// var jObject = JObject.Parse(pocketItem.Json);
// Assert.True(jObject.IsValid(schema));
// }
// }
2013-09-19 12:13:07 +02:00
2013-09-18 21:01:51 +02:00
[Fact]
public async Task AreFilteredItemsRetrieved()
{
IEnumerable<PocketItem> items = await client.Get(RetrieveFilter.Favorite);
2013-09-18 21:01:51 +02:00
Assert.True(items.Count() > 0);
2013-09-18 21:01:51 +02:00
}
[Fact]
public async Task RetrieveWithMultipleFilters()
{
IEnumerable<PocketItem> items = await client.Get(
2013-09-18 21:01:51 +02:00
state: State.unread,
tag: "pocket",
sort: Sort.title,
2013-09-18 21:01:51 +02:00
since: new DateTime(2010, 12, 10),
count: 2
);
Assert.InRange<int>(items.Count(), 0, 2);
2013-09-18 21:01:51 +02:00
}
[Fact]
public async Task ItemContainsUri()
{
IEnumerable<PocketItem> items = await client.Get(count: 1);
2013-09-15 21:44:09 +02:00
2018-04-09 12:18:45 +02:00
Assert.True(1 == items.Count());
Assert.StartsWith("http", items.First().Uri.OriginalString);
}
2013-09-15 21:44:09 +02:00
2013-09-20 23:20:44 +02:00
[Fact]
public async Task InvalidRetrievalReturnsNoResults()
{
IEnumerable<PocketItem> items = await client.Get(
2013-09-20 23:20:44 +02:00
favorite: true,
search: "xoiu987a#;"
);
Assert.False(items.Count() > 0);
2013-09-20 23:20:44 +02:00
PocketItem item = await client.Get("99999999");
2013-09-20 23:20:44 +02:00
Assert.Null(item);
2013-09-21 20:48:50 +02:00
items = await client.Get(RetrieveFilter.Video);
2013-09-20 23:20:44 +02:00
Assert.False(items.Count() > 0);
2013-09-20 23:20:44 +02:00
}
2013-09-15 21:44:09 +02:00
[Fact]
public async Task SearchReturnsResult()
{
IEnumerable<PocketItem> items = await client.Search("pocket");
2013-09-15 21:44:09 +02:00
Assert.True(items.Count() > 0);
2018-04-09 12:18:45 +02:00
Assert.Contains("pocket", items.First().FullTitle.ToLower());
2013-09-15 21:44:09 +02:00
}
2013-09-20 23:20:44 +02:00
[Fact]
public async Task InvalidSearchReturnsNoResult()
{
IEnumerable<PocketItem> items = await client.Search("adsüasd-opiu2;.398dfyx");
2013-09-20 23:20:44 +02:00
Assert.False(items.Count() > 0);
2013-09-20 23:20:44 +02:00
}
2013-09-21 20:48:50 +02:00
[Fact]
public async Task RetrieveTagsReturnsResult()
{
IEnumerable<PocketTag> items = await client.GetTags();
2013-09-21 20:48:50 +02:00
Assert.True(items.Count() > 0);
2013-09-21 20:48:50 +02:00
}
2013-09-15 21:44:09 +02:00
[Fact]
public async Task SearchByTagsReturnsResult()
{
IEnumerable<PocketItem> items = await client.SearchByTag("pocket");
2013-09-15 21:44:09 +02:00
Assert.True(items.Count() == 1);
2013-09-15 21:44:09 +02:00
bool found = false;
items.First().Tags.ToList().ForEach(tag =>
2013-09-15 21:44:09 +02:00
{
if (tag.Name.Contains("pocket"))
{
found = true;
}
});
Assert.True(found);
}
2013-09-20 23:20:44 +02:00
[Fact]
public async Task InvalidSearchByTagsReturnsNoResult()
{
IEnumerable<PocketItem> items = await client.SearchByTag("adsüasd-opiu2;.398dfyx");
2013-09-20 23:20:44 +02:00
Assert.False(items.Count() > 0);
2013-09-20 23:20:44 +02:00
}
2013-09-27 00:12:02 +02:00
[Fact]
public async Task AreStatisticsRetrieved()
{
PocketStatistics statistics = await client.GetUserStatistics();
2013-09-27 00:12:02 +02:00
Assert.True(statistics.CountAll > 0);
}
[Fact]
public async Task AreLimitsRetrieved()
{
PocketLimits limits = await client.GetUsageLimits();
Assert.True(limits.RateLimitForConsumerKey > 9999);
}
[Fact]
public async Task IsNewPocketItemListGeneratorWorking()
{
IEnumerable<PocketItem> items = await client.Get(count: 1, tag: "pocket");
PocketItem item = items.First();
Assert.True(item.Tags.ToList().Find(i => i.Name == "pocket") != null);
}
2013-11-21 21:45:49 +01:00
[Fact]
public async Task IsSinceParameterWorkingOnAddTags()
{
2014-08-28 14:14:40 +02:00
DateTime since = DateTime.Now;
2013-11-21 21:45:49 +01:00
IEnumerable<PocketItem> items = await client.Get(state: State.all);
PocketItem itemToModify = items.First();
2013-11-21 21:45:49 +01:00
Assert.True(items.Count() >= 3);
2013-11-21 21:45:49 +01:00
items = await client.Get(state: State.all, since: since);
Assert.True(items == null || items.Count() == 0);
2013-11-21 21:45:49 +01:00
await client.AddTags(itemToModify, new string[] { "pocketsharp" });
items = await client.Get(state: State.all, since: since);
Assert.True(items.Count() > 0);
2013-11-21 21:45:49 +01:00
await client.RemoveTags(itemToModify, new string[] { "pocketsharp" });
}
[Fact]
public async Task IsSinceParameterWorkingOnFavoriteAndArchiveModification()
{
2014-08-28 14:14:40 +02:00
DateTime since = DateTime.Now;//1409221736
2013-11-21 21:45:49 +01:00
IEnumerable<PocketItem> items = await client.Get(state: State.all);
PocketItem itemToModify = items.First();
2013-11-21 21:45:49 +01:00
Assert.True(items.Count() >= 3);
2013-11-21 21:45:49 +01:00
items = await client.Get(state: State.all, since: since);
Assert.True(items == null || items.Count() == 0);
2013-11-21 21:45:49 +01:00
await client.Favorite(itemToModify);
items = await client.Get(state: State.all, since: since);
Assert.True(items.Count() > 0);
2013-11-21 21:45:49 +01:00
await client.Unfavorite(itemToModify);
2014-08-28 14:14:40 +02:00
since = DateTime.Now;
2013-11-21 21:45:49 +01:00
await client.Archive(itemToModify);
items = await client.Get(state: State.all, since: since);
Assert.True(items.Count() > 0);
2013-11-21 21:45:49 +01:00
await client.Unarchive(itemToModify);
}
2014-08-28 14:14:40 +02:00
[Fact]
public async Task IsUTCSinceParameterWorking()
{
DateTime since = DateTime.UtcNow;
IEnumerable<PocketItem> items = await client.Get(state: State.all);
PocketItem itemToModify = items.First();
items = await client.Get(state: State.all, since: since);
Assert.True(items == null || items.Count() == 0);
await client.Favorite(itemToModify);
items = await client.Get(state: State.all, since: since);
Assert.True(items.Count() > 0);
await client.Unfavorite(itemToModify);
}
2013-11-21 21:45:49 +01:00
[Fact]
public async Task IsSinceParameterWorkingOnAddAndDelete()
{
2014-08-28 14:14:40 +02:00
DateTime since = DateTime.UtcNow;
2013-11-21 21:45:49 +01:00
PocketItem item = await client.Add(new Uri("http://frontendplay.com"));
IEnumerable<PocketItem> items = await client.Get(state: State.all, since: since);
2013-11-21 21:45:49 +01:00
since = DateTime.UtcNow;
await client.Delete(item);
items = await client.Get(state: State.all, since: since);
Assert.True(items.Count() == 1 && items.First().IsDeleted);
2013-11-21 21:45:49 +01:00
}
[Fact]
public async Task AreUncachedItemsProperlyResolved()
{
PocketItem item = await client.Add(new Uri("http://de.ign.com/m/feature/21608/die-20-besten-kurzfilme-des-jahres-2013?bust=1"));
IEnumerable<PocketItem> items = await client.Get(state: State.all);
Assert.NotNull(item.Uri);
Assert.NotNull(items.First().Uri);
Assert.Equal(item.Uri, items.First().Uri);
itemsToDelete.Add(item.ID);
}
2013-09-15 21:44:09 +02:00
}
}