2014-03-04 22:35:50 -06:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
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;
|
2014-05-01 17:56:18 +02:00
|
|
|
using System.Linq;
|
2013-09-15 21:44:09 +02:00
|
|
|
|
|
|
|
|
namespace PocketSharp.Tests
|
|
|
|
|
{
|
2013-09-30 23:24:18 +02:00
|
|
|
public class GetTests : TestsBase
|
2013-09-15 21:44:09 +02:00
|
|
|
{
|
2013-09-30 23:24:18 +02:00
|
|
|
public GetTests() : base() { }
|
2013-09-15 21:44:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task AreItemsRetrieved()
|
|
|
|
|
{
|
2014-05-01 17:56:18 +02:00
|
|
|
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()
|
|
|
|
|
{
|
2014-05-01 17:56:18 +02:00
|
|
|
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-07-02 15:31:38 +02:00
|
|
|
// [Fact]
|
|
|
|
|
// public async Task IsItemJsonPopulated()
|
|
|
|
|
// {
|
|
|
|
|
// List<PocketItem> items = (await client.Get()).ToList();
|
|
|
|
|
// string schemaJson = @"{
|
|
|
|
|
// 'description': 'PocketItem',
|
|
|
|
|
// 'type': 'object'
|
|
|
|
|
// }";
|
2014-03-04 22:35:50 -06:00
|
|
|
|
2014-07-02 15:31:38 +02:00
|
|
|
// 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()
|
|
|
|
|
{
|
2014-05-01 17:56:18 +02:00
|
|
|
IEnumerable<PocketItem> items = await client.Get(RetrieveFilter.Favorite);
|
2013-09-18 21:01:51 +02:00
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
Assert.True(items.Count() > 0);
|
2013-09-18 21:01:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task RetrieveWithMultipleFilters()
|
|
|
|
|
{
|
2014-05-01 17:56:18 +02:00
|
|
|
IEnumerable<PocketItem> items = await client.Get(
|
2013-09-18 21:01:51 +02:00
|
|
|
state: State.unread,
|
|
|
|
|
tag: "pocket",
|
2013-09-18 21:14:07 +02:00
|
|
|
sort: Sort.title,
|
2013-09-18 21:01:51 +02:00
|
|
|
since: new DateTime(2010, 12, 10),
|
|
|
|
|
count: 2
|
|
|
|
|
);
|
|
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
Assert.InRange<int>(items.Count(), 0, 2);
|
2013-09-18 21:01:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-09-17 23:08:15 +02:00
|
|
|
[Fact]
|
|
|
|
|
public async Task ItemContainsUri()
|
|
|
|
|
{
|
2014-05-01 17:56:18 +02:00
|
|
|
IEnumerable<PocketItem> items = await client.Get(count: 1);
|
2013-09-15 21:44:09 +02:00
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
Assert.True(items.Count() == 1);
|
|
|
|
|
Assert.True(items.First().Uri.ToString().StartsWith("http"));
|
2013-09-17 23:08:15 +02:00
|
|
|
}
|
2013-09-15 21:44:09 +02:00
|
|
|
|
|
|
|
|
|
2013-09-20 23:20:44 +02:00
|
|
|
[Fact]
|
|
|
|
|
public async Task InvalidRetrievalReturnsNoResults()
|
|
|
|
|
{
|
2014-05-01 17:56:18 +02:00
|
|
|
IEnumerable<PocketItem> items = await client.Get(
|
2013-09-20 23:20:44 +02:00
|
|
|
favorite: true,
|
|
|
|
|
search: "xoiu987a#;"
|
|
|
|
|
);
|
|
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
Assert.False(items.Count() > 0);
|
2013-09-20 23:20:44 +02:00
|
|
|
|
2013-12-15 11:00:00 +01: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
|
|
|
|
2014-05-01 17:56:18 +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()
|
|
|
|
|
{
|
2014-05-01 17:56:18 +02:00
|
|
|
IEnumerable<PocketItem> items = await client.Search("pocket");
|
2013-09-15 21:44:09 +02:00
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
Assert.True(items.Count() > 0);
|
|
|
|
|
Assert.True(items.First().FullTitle.ToLower().Contains("pocket"));
|
2013-09-15 21:44:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-09-20 23:20:44 +02:00
|
|
|
[Fact]
|
|
|
|
|
public async Task InvalidSearchReturnsNoResult()
|
|
|
|
|
{
|
2014-05-01 17:56:18 +02:00
|
|
|
IEnumerable<PocketItem> items = await client.Search("adsüasd-opiu2;.398dfyx");
|
2013-09-20 23:20:44 +02:00
|
|
|
|
2014-05-01 17:56:18 +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()
|
|
|
|
|
{
|
2014-05-01 17:56:18 +02:00
|
|
|
IEnumerable<PocketTag> items = await client.GetTags();
|
2013-09-21 20:48:50 +02:00
|
|
|
|
2014-05-01 17:56:18 +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()
|
|
|
|
|
{
|
2014-05-01 17:56:18 +02:00
|
|
|
IEnumerable<PocketItem> items = await client.SearchByTag("pocket");
|
2013-09-15 21:44:09 +02:00
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
Assert.True(items.Count() == 1);
|
2013-09-15 21:44:09 +02:00
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
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()
|
|
|
|
|
{
|
2014-05-01 17:56:18 +02:00
|
|
|
IEnumerable<PocketItem> items = await client.SearchByTag("adsüasd-opiu2;.398dfyx");
|
2013-09-20 23:20:44 +02:00
|
|
|
|
2014-05-01 17:56:18 +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()
|
|
|
|
|
{
|
2013-11-04 22:46:30 +01:00
|
|
|
PocketStatistics statistics = await client.GetUserStatistics();
|
2013-09-27 00:12:02 +02:00
|
|
|
|
|
|
|
|
Assert.True(statistics.CountAll > 0);
|
|
|
|
|
}
|
2013-10-25 00:52:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task AreLimitsRetrieved()
|
|
|
|
|
{
|
|
|
|
|
PocketLimits limits = await client.GetUsageLimits();
|
|
|
|
|
|
|
|
|
|
Assert.True(limits.RateLimitForConsumerKey > 9999);
|
|
|
|
|
}
|
2013-11-04 22:46:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task IsNewPocketItemListGeneratorWorking()
|
|
|
|
|
{
|
2014-05-01 17:56:18 +02:00
|
|
|
IEnumerable<PocketItem> items = await client.Get(count: 1, tag: "pocket");
|
|
|
|
|
PocketItem item = items.First();
|
2013-11-04 22:46:30 +01:00
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
Assert.True(item.Tags.ToList().Find(i => i.Name == "pocket") != null);
|
2013-11-04 22:46:30 +01:00
|
|
|
}
|
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
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
IEnumerable<PocketItem> items = await client.Get(state: State.all);
|
|
|
|
|
PocketItem itemToModify = items.First();
|
2013-11-21 21:45:49 +01:00
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
Assert.True(items.Count() >= 3);
|
2013-11-21 21:45:49 +01:00
|
|
|
|
|
|
|
|
items = await client.Get(state: State.all, since: since);
|
|
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
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);
|
|
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
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
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
IEnumerable<PocketItem> items = await client.Get(state: State.all);
|
|
|
|
|
PocketItem itemToModify = items.First();
|
2013-11-21 21:45:49 +01:00
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
Assert.True(items.Count() >= 3);
|
2013-11-21 21:45:49 +01:00
|
|
|
|
|
|
|
|
items = await client.Get(state: State.all, since: since);
|
|
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
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);
|
|
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
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);
|
|
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
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"));
|
|
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
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);
|
|
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
Assert.True(items.Count() == 1 && items.First().IsDeleted);
|
2013-11-21 21:45:49 +01:00
|
|
|
}
|
2013-12-27 21:34:22 +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"));
|
|
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
IEnumerable<PocketItem> items = await client.Get(state: State.all);
|
2013-12-27 21:34:22 +01:00
|
|
|
|
|
|
|
|
Assert.NotNull(item.Uri);
|
2014-05-01 17:56:18 +02:00
|
|
|
Assert.NotNull(items.First().Uri);
|
|
|
|
|
Assert.Equal(item.Uri, items.First().Uri);
|
2013-12-27 21:34:22 +01:00
|
|
|
|
|
|
|
|
itemsToDelete.Add(item.ID);
|
|
|
|
|
}
|
2013-09-15 21:44:09 +02:00
|
|
|
}
|
|
|
|
|
}
|