diff --git a/PocketSharp.Tests/DefaultAccount.playlist b/PocketSharp.Tests/DefaultAccount.playlist index ce94283..8cf559d 100644 --- a/PocketSharp.Tests/DefaultAccount.playlist +++ b/PocketSharp.Tests/DefaultAccount.playlist @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/PocketSharp.Tests/MiscTests.cs b/PocketSharp.Tests/MiscTests.cs new file mode 100644 index 0000000..f5024fa --- /dev/null +++ b/PocketSharp.Tests/MiscTests.cs @@ -0,0 +1,31 @@ +using PocketSharp.Models; +using System.Collections.Generic; +using System.Threading.Tasks; +using Xunit; + +namespace PocketSharp.Tests +{ + public class MiscTests : TestsBase + { + private int Incrementor = 0; + + public MiscTests() + : base() + { + client.PreRequest = method => Incrementor++; + } + + + [Fact] + public async Task CheckPreRequestAction() + { + List items = await client.Get(count: 1); + PocketItem item = items[0]; + + await client.Favorite(item); + await client.Unfavorite(item); + + Assert.True(Incrementor >= 3); + } + } +} diff --git a/PocketSharp.Tests/PocketSharp.Tests.csproj b/PocketSharp.Tests/PocketSharp.Tests.csproj index a50ee3c..932fc0b 100644 --- a/PocketSharp.Tests/PocketSharp.Tests.csproj +++ b/PocketSharp.Tests/PocketSharp.Tests.csproj @@ -68,6 +68,7 @@ + diff --git a/PocketSharp.Tests/StressTests.cs b/PocketSharp.Tests/StressTests.cs index 2ff59e7..3a2936b 100644 --- a/PocketSharp.Tests/StressTests.cs +++ b/PocketSharp.Tests/StressTests.cs @@ -1,22 +1,21 @@ using System; -using System.Threading.Tasks; using System.Collections.Generic; -using Xunit; -using PocketSharp.Models; using System.IO; using System.Linq; -using System.Diagnostics; +using System.Threading.Tasks; +using Xunit; namespace PocketSharp.Tests { public class StressTests : TestsBase { private static IEnumerable urls; - private static string[] tags = new string[]{ "css", "js", "csharp", "windows", "microsoft" }; + private static string[] tags = new string[] { "css", "js", "csharp", "windows", "microsoft" }; - public StressTests() : base() - { + public StressTests() + : base() + { // !! please don't misuse this account !! client = new PocketClient( consumerKey: "20000-786d0bc8c39294e9829111d6", @@ -31,7 +30,7 @@ namespace PocketSharp.Tests [Fact] public async Task Are100IdingtemsRetrievedProperly() { - await FillAccount(4457, 10000); + await FillAccount(8360, 10000); } [Fact] @@ -49,13 +48,13 @@ namespace PocketSharp.Tests [Fact] public async Task Are0ItemsRetrievedProperly() { - + } [Fact] public async Task IsSearchedSuccessfullyOn10000Items() { - + } diff --git a/PocketSharp/PocketClient.cs b/PocketSharp/PocketClient.cs index 3c05b1e..5434e67 100644 --- a/PocketSharp/PocketClient.cs +++ b/PocketSharp/PocketClient.cs @@ -1,13 +1,13 @@ -using PocketSharp.Models; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using PocketSharp.Models; using System; using System.Collections.Generic; using System.Net; using System.Net.Http; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; using System.Net.Http.Headers; using System.Threading; +using System.Threading.Tasks; namespace PocketSharp { @@ -69,6 +69,14 @@ namespace PocketSharp /// public string AccessCode { get; set; } + /// + /// Action which is executed before every request + /// + /// + /// The pre request callback. + /// + public Action PreRequest { get; set; } + /// /// Initializes a new instance of the class. @@ -120,9 +128,9 @@ namespace PocketSharp /// /// No access token available. Use authentification first. protected async Task Request( - string method, + string method, CancellationToken cancellationToken, - Dictionary parameters = null, + Dictionary parameters = null, bool requireAuth = true) where T : class, new() { if (requireAuth && AccessCode == null) @@ -151,6 +159,12 @@ namespace PocketSharp // content of the request request.Content = new FormUrlEncodedContent(parameters); + // call pre request action + if (PreRequest != null) + { + PreRequest(method); + } + // make async request try {