From 5ba027bafc4e52afa522810b729faf3133ff056d Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Sat, 16 Nov 2013 15:27:54 +0100 Subject: [PATCH] test SendActions --- PocketSharp.Tests/ModifyTests.cs | 32 +++++++++++++++++++++++++--- PocketSharp/Components/ModifyTags.cs | 2 +- PocketSharp/IPocketClient.cs | 16 +++++++++++--- PocketSharp/PocketSharp.csproj | 2 +- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/PocketSharp.Tests/ModifyTests.cs b/PocketSharp.Tests/ModifyTests.cs index 9f105ae..83791c5 100644 --- a/PocketSharp.Tests/ModifyTests.cs +++ b/PocketSharp.Tests/ModifyTests.cs @@ -1,8 +1,9 @@ -using System; -using System.Threading.Tasks; +using PocketSharp.Models; +using System; using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using Xunit; -using PocketSharp.Models; namespace PocketSharp.Tests { @@ -62,6 +63,31 @@ namespace PocketSharp.Tests } + [Fact] + public async Task AreMultipleActionsSent() + { + PocketItem item = await Setup(); + + bool success = await client.SendActions(new List() + { + new PocketAction() { Action = "favorite", ID = item.ID }, + new PocketAction() { Action = "tags_add", ID = item.ID, Tags = new string[] { "new_tag", "another_tag" } }, + new PocketAction() { Action = "archive", ID = item.ID }, + new PocketAction() { Action = "tag_rename", ID = item.ID, OldTag = "social", NewTag = "not_social" } + }); + + Assert.True(success); + + item = await client.Get(item.ID); + + Assert.True(item.IsFavorite); + Assert.True(item.IsArchive); + Assert.NotNull(item.Tags.Single(tag => tag.Name == "new_tag")); + Assert.NotNull(item.Tags.Single(tag => tag.Name == "another_tag")); + Assert.NotNull(item.Tags.Single(tag => tag.Name == "not_social")); + } + + private async Task Setup() { PocketItem item = await client.Add( diff --git a/PocketSharp/Components/ModifyTags.cs b/PocketSharp/Components/ModifyTags.cs index 2f61e04..5c5679a 100644 --- a/PocketSharp/Components/ModifyTags.cs +++ b/PocketSharp/Components/ModifyTags.cs @@ -158,7 +158,7 @@ namespace PocketSharp /// public async Task RenameTag(int itemID, string oldTag, string newTag, CancellationToken cancellationToken = default(CancellationToken)) { - return await Send(new ActionParameter() + return await Send(new PocketAction() { Action = "tag_rename", ID = itemID, diff --git a/PocketSharp/IPocketClient.cs b/PocketSharp/IPocketClient.cs index e27c032..00c0037 100644 --- a/PocketSharp/IPocketClient.cs +++ b/PocketSharp/IPocketClient.cs @@ -1,8 +1,8 @@ -using System; +using PocketSharp.Models; +using System; using System.Collections.Generic; -using System.Threading.Tasks; -using PocketSharp.Models; using System.Threading; +using System.Threading.Tasks; namespace PocketSharp { @@ -203,6 +203,16 @@ namespace PocketSharp #endregion #region modify methods + /// + /// Sends multiple actions in one request. + /// See: http://getpocket.com/developer/docs/v3/modify + /// + /// The actions. + /// The cancellation token. + /// + /// + Task SendActions(List actions, CancellationToken cancellationToken = default(CancellationToken)); + /// /// Archives the specified item. /// diff --git a/PocketSharp/PocketSharp.csproj b/PocketSharp/PocketSharp.csproj index fd45120..6d404b1 100644 --- a/PocketSharp/PocketSharp.csproj +++ b/PocketSharp/PocketSharp.csproj @@ -54,7 +54,7 @@ - +