using Jackett.Common.Models.Config; using Jackett.Common.Services.Interfaces; using Jackett.Common.Utils.Clients; using NLog; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Jackett.Test { public class TestWebClient : WebClient { private Dictionary> byteCallbacks = new Dictionary>(); private Dictionary> stringCallbacks = new Dictionary>(); public TestWebClient(IProcessService p, Logger l, IConfigurationService c, ServerConfig sc) : base(p: p, l: l, c: c, sc: sc) { } public void RegisterByteCall(WebRequest req, Func f) { byteCallbacks.Add(req, f); } public void RegisterStringCall(WebRequest req, Func f) { stringCallbacks.Add(req, f); } override public Task GetBytes(WebRequest request) { return Task.FromResult< WebClientByteResult>(byteCallbacks.Where(r => r.Key.Equals(request)).First().Value.Invoke(request)); } override public Task GetString(WebRequest request) { return Task.FromResult(stringCallbacks.Where(r => r.Key.Equals(request)).First().Value.Invoke(request)); } override public void Init() { } } }