Jackett/src/Jackett.Test/TestUtil.cs

74 lines
2.3 KiB
C#
Raw Normal View History

using Autofac;
using Jackett;
using Jackett.Services;
using Jackett.Utils.Clients;
using NLog;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
Feature/netcore preparation (#2035) * Move to use package reference for restoring nuget packages. * Return a task result for this async method. * Update to a supported version of the .NET Framework. This also has the side effect of allowing us to automatically generate our binding redirects on build. * Set the solution to target VS2017 * Update test solution csproj file to support being built through MSBuild 15 * Move to use package reference for restoring nuget packages. * Return a task result for this async method. * Update to a supported version of the .NET Framework. This also has the side effect of allowing us to automatically generate our binding redirects on build. * Set the solution to target VS2017 * Update test solution csproj file to support being built through MSBuild 15 * DateTimeRoutines does not have Nuget packages that support .NET Standard (and therefore .NET Core). We will have to include them for now until we can get rid of this dependency. * Move the interfaces into their own files. This will be useful when we share them between the .NET Core and .NET Framework WebAPI * Stage services that need to point to the new interface namespace. * Update CurlSharp to fix memory leak issue and support better runtime compatibility with OSX and Linux * Start spliting some interfaces into their own files - this will help by allowing us to split them out in the future into a seperate project so the actual implementations can stay within their respective architectures when required
2017-10-29 10:19:09 +00:00
using Jackett.Services.Interfaces;
using Jackett.Common.Plumbing;
using Jackett.Common.Models.Config;
namespace Jackett.Test
{
class TestUtil
{
private static IContainer testContainer = null;
public static void SetupContainer()
{
var builder = new ContainerBuilder();
builder.RegisterModule(new JackettModule(new RuntimeSettings()));
builder.RegisterModule<WebApi2Module>();
builder.RegisterType<TestWebClient>().As<WebClient>().SingleInstance();
builder.RegisterInstance(LogManager.GetCurrentClassLogger()).SingleInstance();
builder.RegisterType<TestIndexerManagerServiceHelper>().As<IIndexerManagerService>().SingleInstance();
testContainer = builder.Build();
}
public static TestIndexerManagerServiceHelper IndexManager
{
get
{
return testContainer.Resolve<IIndexerManagerService>() as TestIndexerManagerServiceHelper;
}
}
public static IContainer Container
{
get { return testContainer; }
}
public static void RegisterByteCall(WebRequest r, Func<WebRequest, WebClientByteResult> f)
{
var client = testContainer.Resolve<WebClient>() as TestWebClient;
client.RegisterByteCall(r, f);
}
public static void RegisterStringCall(WebRequest r, Func<WebRequest, WebClientStringResult> f)
{
var client = testContainer.Resolve<WebClient>() as TestWebClient;
client.RegisterStringCall(r, f);
}
public static string GetResource(string item)
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "Jackett.Test." + item.Replace('/','.');
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
using (StreamReader reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
}
}