2013-11-12 22:08:02 +01:00
|
|
|
using PocketSharp.Models;
|
|
|
|
|
using System;
|
2013-09-15 21:52:28 +02:00
|
|
|
using System.Collections.Generic;
|
2013-11-12 22:08:02 +01:00
|
|
|
using System.Threading.Tasks;
|
2013-09-15 21:52:28 +02:00
|
|
|
using Xunit;
|
2014-05-01 17:56:18 +02:00
|
|
|
using System.Linq;
|
2013-09-15 21:52:28 +02:00
|
|
|
|
|
|
|
|
namespace PocketSharp.Tests
|
|
|
|
|
{
|
2013-09-16 23:34:13 +02:00
|
|
|
public class AddTests : TestsBase
|
2013-09-15 21:52:28 +02:00
|
|
|
{
|
|
|
|
|
public AddTests() : base() { }
|
2013-09-16 23:34:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task AddSimpleItemWithUriOnly()
|
|
|
|
|
{
|
|
|
|
|
var uri = new Uri("http://frontendplay.com");
|
|
|
|
|
|
|
|
|
|
PocketItem item = await client.Add(uri);
|
|
|
|
|
|
|
|
|
|
Assert.Equal<Uri>(uri, item.Uri);
|
|
|
|
|
|
|
|
|
|
itemsToDelete.Add(item.ID);
|
|
|
|
|
}
|
2013-09-17 22:48:35 +02:00
|
|
|
|
|
|
|
|
|
2013-11-12 22:08:02 +01:00
|
|
|
[Fact]
|
|
|
|
|
public async Task ItemWithInstableImagesIsAdded()
|
|
|
|
|
{
|
|
|
|
|
var uri = new Uri("http://www.valoronline.com.br");
|
|
|
|
|
|
|
|
|
|
PocketItem item = await client.Add(uri);
|
|
|
|
|
|
2014-02-23 21:03:55 +01:00
|
|
|
Assert.NotNull(item);
|
2013-11-12 22:08:02 +01:00
|
|
|
|
|
|
|
|
itemsToDelete.Add(item.ID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-09-17 22:48:35 +02:00
|
|
|
[Fact]
|
|
|
|
|
public async Task AddComplexItem()
|
|
|
|
|
{
|
|
|
|
|
PocketItem item = await client.Add(
|
|
|
|
|
uri: new Uri("http://frontendplay.com"),
|
|
|
|
|
tags: new string[] { "blog", "frontend", "cee" },
|
|
|
|
|
title: "ignored title",
|
|
|
|
|
tweetID: "380051788172632065"
|
|
|
|
|
);
|
|
|
|
|
|
2014-05-01 17:56:18 +02:00
|
|
|
List<PocketItem> items = (await client.Get()).ToList();
|
2013-09-17 22:48:35 +02:00
|
|
|
PocketItem itemDesired = null;
|
|
|
|
|
|
|
|
|
|
items.ForEach(itm =>
|
|
|
|
|
{
|
2013-11-12 22:08:02 +01:00
|
|
|
if (itm.ID == item.ID)
|
2013-09-17 22:48:35 +02:00
|
|
|
{
|
|
|
|
|
itemDesired = itm;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(itemDesired);
|
|
|
|
|
Assert.Equal(itemDesired.ID, item.ID);
|
2014-05-01 17:56:18 +02:00
|
|
|
Assert.Equal(itemDesired.Tags.Count(), 3);
|
2013-09-17 22:48:35 +02:00
|
|
|
|
|
|
|
|
itemsToDelete.Add(item.ID);
|
|
|
|
|
}
|
2014-06-17 10:14:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task ItemViaActionsIsAdded()
|
|
|
|
|
{
|
2014-06-17 10:45:24 +02:00
|
|
|
List<PocketAction> actions = new List<PocketAction>();
|
2014-06-17 10:14:26 +02:00
|
|
|
|
2014-06-17 10:45:24 +02:00
|
|
|
actions.Add(new PocketAction()
|
2014-06-17 10:14:26 +02:00
|
|
|
{
|
2014-06-17 10:45:24 +02:00
|
|
|
Uri = new Uri("http://frontendplay.com/story/4015/string-indexer-for-text-resources-in-nancy"),
|
2014-06-17 10:14:26 +02:00
|
|
|
Action = "add",
|
|
|
|
|
Time = DateTime.Now
|
2014-06-17 10:45:24 +02:00
|
|
|
});
|
2014-06-17 10:14:26 +02:00
|
|
|
|
2014-06-17 10:45:24 +02:00
|
|
|
bool success = await client.SendActions(actions);
|
2014-06-17 10:14:26 +02:00
|
|
|
|
|
|
|
|
Assert.True(success);
|
|
|
|
|
|
2014-06-17 10:45:24 +02:00
|
|
|
IEnumerable<PocketItem> items = await client.Search("in nancy");
|
2014-06-17 10:14:26 +02:00
|
|
|
|
|
|
|
|
Assert.NotNull(items);
|
|
|
|
|
Assert.True(items.Count() > 0);
|
|
|
|
|
|
|
|
|
|
itemsToDelete.Add(items.First().ID);
|
|
|
|
|
}
|
2014-06-17 10:45:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task ItemsViaActionsIsAdded()
|
|
|
|
|
{
|
|
|
|
|
List<PocketAction> actions = new List<PocketAction>();
|
|
|
|
|
|
|
|
|
|
actions.Add(new PocketAction()
|
|
|
|
|
{
|
|
|
|
|
Uri = new Uri("http://frontendplay.com/story/4015/string-indexer-for-text-resources-in-nancy"),
|
|
|
|
|
Action = "add",
|
|
|
|
|
Time = DateTime.Now
|
|
|
|
|
});
|
|
|
|
|
actions.Add(new PocketAction()
|
|
|
|
|
{
|
|
|
|
|
Uri = new Uri("http://frontendplay.com/story/4013/build-a-custom-razor-viewbase-in-nancy"),
|
|
|
|
|
Action = "add",
|
|
|
|
|
Time = DateTime.Now
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
bool success = await client.SendActions(actions);
|
|
|
|
|
|
|
|
|
|
Assert.True(success);
|
|
|
|
|
|
|
|
|
|
IEnumerable<PocketItem> items = await client.Search("in nancy");
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(items);
|
|
|
|
|
Assert.True(items.Count() == 2);
|
|
|
|
|
|
|
|
|
|
itemsToDelete.AddRange(items.Select(item => item.ID));
|
|
|
|
|
}
|
2013-09-15 21:52:28 +02:00
|
|
|
}
|
|
|
|
|
}
|