2016-12-06 13:56:47 +00:00
|
|
|
|
using Jackett.Services;
|
|
|
|
|
using Jackett.Utils.Clients;
|
|
|
|
|
using NLog;
|
2015-07-25 23:51:55 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace JackettTest
|
|
|
|
|
{
|
|
|
|
|
public class TestWebClient : IWebClient
|
|
|
|
|
{
|
|
|
|
|
private Dictionary<WebRequest, Func<WebRequest, WebClientByteResult>> byteCallbacks = new Dictionary<WebRequest, Func<WebRequest, WebClientByteResult>>();
|
|
|
|
|
private Dictionary<WebRequest, Func<WebRequest, WebClientStringResult>> stringCallbacks = new Dictionary<WebRequest, Func<WebRequest, WebClientStringResult>>();
|
|
|
|
|
|
2016-12-06 13:56:47 +00:00
|
|
|
|
public TestWebClient(IProcessService p, Logger l, IConfigurationService c)
|
|
|
|
|
: base(p: p,
|
|
|
|
|
l: l,
|
|
|
|
|
c: c)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 23:51:55 +00:00
|
|
|
|
public void RegisterByteCall(WebRequest req, Func<WebRequest, WebClientByteResult> f)
|
|
|
|
|
{
|
|
|
|
|
byteCallbacks.Add(req, f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RegisterStringCall(WebRequest req, Func<WebRequest, WebClientStringResult> f)
|
|
|
|
|
{
|
|
|
|
|
stringCallbacks.Add(req, f);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-06 13:56:47 +00:00
|
|
|
|
override public Task<WebClientByteResult> GetBytes(WebRequest request)
|
2015-07-25 23:51:55 +00:00
|
|
|
|
{
|
|
|
|
|
return Task.FromResult< WebClientByteResult>(byteCallbacks.Where(r => r.Key.Equals(request)).First().Value.Invoke(request));
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-06 13:56:47 +00:00
|
|
|
|
override public Task<WebClientStringResult> GetString(WebRequest request)
|
2015-07-25 23:51:55 +00:00
|
|
|
|
{
|
|
|
|
|
return Task.FromResult<WebClientStringResult>(stringCallbacks.Where(r => r.Key.Equals(request)).First().Value.Invoke(request));
|
|
|
|
|
}
|
2015-07-30 17:50:46 +00:00
|
|
|
|
|
2016-12-06 13:56:47 +00:00
|
|
|
|
override public void Init()
|
2015-07-30 17:50:46 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2015-07-25 23:51:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|