2020-03-03 16:28:26 +00:00
|
|
|
using System;
|
2015-07-25 23:51:55 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
2020-02-09 18:08:34 +00:00
|
|
|
using Jackett.Common.Models.Config;
|
|
|
|
using Jackett.Common.Services.Interfaces;
|
|
|
|
using Jackett.Common.Utils.Clients;
|
|
|
|
using NLog;
|
2015-07-25 23:51:55 +00:00
|
|
|
|
2017-10-29 08:42:25 +00:00
|
|
|
namespace Jackett.Test
|
2015-07-25 23:51:55 +00:00
|
|
|
{
|
2017-11-05 09:42:03 +00:00
|
|
|
public class TestWebClient : WebClient
|
2015-07-25 23:51:55 +00:00
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
private readonly Dictionary<WebRequest, Func<WebRequest, WebClientByteResult>> byteCallbacks = new Dictionary<WebRequest, Func<WebRequest, WebClientByteResult>>();
|
|
|
|
private readonly Dictionary<WebRequest, Func<WebRequest, WebClientStringResult>> stringCallbacks = new Dictionary<WebRequest, Func<WebRequest, WebClientStringResult>>();
|
2015-07-25 23:51:55 +00:00
|
|
|
|
2017-11-05 09:42:03 +00:00
|
|
|
public TestWebClient(IProcessService p, Logger l, IConfigurationService c, ServerConfig sc)
|
2016-12-06 13:56:47 +00:00
|
|
|
: base(p: p,
|
|
|
|
l: l,
|
2017-11-05 09:42:03 +00:00
|
|
|
c: c,
|
|
|
|
sc: sc)
|
2016-12-06 13:56:47 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
public void RegisterByteCall(WebRequest req, Func<WebRequest, WebClientByteResult> f) => byteCallbacks.Add(req, f);
|
2015-07-25 23:51:55 +00:00
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
public void RegisterStringCall(WebRequest req, Func<WebRequest, WebClientStringResult> f) => stringCallbacks.Add(req, f);
|
2015-07-25 23:51:55 +00:00
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
public override Task<WebClientByteResult> GetBytes(WebRequest request) => Task.FromResult<WebClientByteResult>(byteCallbacks.Where(r => r.Key.Equals(request)).First().Value.Invoke(request));
|
2015-07-25 23:51:55 +00:00
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
public override Task<WebClientStringResult> GetString(WebRequest request) => Task.FromResult<WebClientStringResult>(stringCallbacks.Where(r => r.Key.Equals(request)).First().Value.Invoke(request));
|
2015-07-30 17:50:46 +00:00
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
public override void Init()
|
2015-07-30 17:50:46 +00:00
|
|
|
{
|
2020-02-09 02:35:16 +00:00
|
|
|
|
2015-07-30 17:50:46 +00:00
|
|
|
}
|
2015-07-25 23:51:55 +00:00
|
|
|
}
|
|
|
|
}
|