add PreRequest action for all requests
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -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<PocketItem> items = await client.Get(count: 1);
|
||||
PocketItem item = items[0];
|
||||
|
||||
await client.Favorite(item);
|
||||
await client.Unfavorite(item);
|
||||
|
||||
Assert.True(Incrementor >= 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,7 @@
|
||||
<Otherwise />
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="MiscTests.cs" />
|
||||
<Compile Include="AddTests.cs" />
|
||||
<Compile Include="AccountTests.cs" />
|
||||
<Compile Include="ModifyTagsTests.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<string> 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()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
/// </value>
|
||||
public string AccessCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Action which is executed before every request
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The pre request callback.
|
||||
/// </value>
|
||||
public Action<string> PreRequest { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PocketClient"/> class.
|
||||
@@ -120,9 +128,9 @@ namespace PocketSharp
|
||||
/// <returns></returns>
|
||||
/// <exception cref="PocketException">No access token available. Use authentification first.</exception>
|
||||
protected async Task<T> Request<T>(
|
||||
string method,
|
||||
string method,
|
||||
CancellationToken cancellationToken,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> 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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user