2020-04-22 19:46:41 -04:00
|
|
|
|
using ApplicationTests.Fixtures;
|
2020-04-25 20:01:26 -04:00
|
|
|
|
using ApplicationTests.Mocks;
|
2020-04-22 19:46:41 -04:00
|
|
|
|
using FakeItEasy;
|
|
|
|
|
using IW4MAdmin;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-05-16 12:54:01 -04:00
|
|
|
|
using SharedLibraryCore.Configuration;
|
2020-04-22 19:46:41 -04:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2020-05-16 12:54:01 -04:00
|
|
|
|
using System;
|
2020-11-12 20:46:17 -05:00
|
|
|
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
2020-04-22 19:46:41 -04:00
|
|
|
|
|
|
|
|
|
namespace ApplicationTests
|
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
static class DependencyInjectionExtensions
|
2020-04-22 19:46:41 -04:00
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
public static IServiceCollection BuildBase(this IServiceCollection serviceCollection, IEventHandler eventHandler = null)
|
2020-04-22 19:46:41 -04:00
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
|
|
|
|
|
if (eventHandler == null)
|
|
|
|
|
{
|
2020-05-16 12:54:01 -04:00
|
|
|
|
eventHandler = new EventHandlerMock();
|
|
|
|
|
serviceCollection.AddSingleton(eventHandler as EventHandlerMock);
|
2020-05-04 17:50:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-16 12:54:01 -04:00
|
|
|
|
else if (eventHandler is EventHandlerMock mockEventHandler)
|
2020-05-04 17:50:02 -04:00
|
|
|
|
{
|
|
|
|
|
serviceCollection.AddSingleton(mockEventHandler);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-22 19:46:41 -04:00
|
|
|
|
var manager = A.Fake<IManager>();
|
2020-04-25 20:01:26 -04:00
|
|
|
|
|
2020-10-17 11:47:56 -04:00
|
|
|
|
var transLookup = A.Fake<ITranslationLookup>();
|
|
|
|
|
A.CallTo(() => transLookup[A<string>.Ignored])
|
|
|
|
|
.Returns("test");
|
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
serviceCollection
|
|
|
|
|
.AddLogging()
|
|
|
|
|
.AddSingleton(A.Fake<ILogger>())
|
2020-11-12 20:46:17 -05:00
|
|
|
|
.AddSingleton(A.Fake<SharedLibraryCore.Interfaces.ILogger>())
|
|
|
|
|
.AddSingleton(new ServerConfiguration { IPAddress = "127.0.0.1", Port = 28960 })
|
2020-04-22 19:46:41 -04:00
|
|
|
|
.AddSingleton(manager)
|
2020-04-25 20:01:26 -04:00
|
|
|
|
.AddSingleton<IDatabaseContextFactory, DatabaseContextFactoryMock>()
|
2020-11-12 20:46:17 -05:00
|
|
|
|
.AddSingleton<IW4MServer>()
|
2020-04-22 19:46:41 -04:00
|
|
|
|
.AddSingleton(A.Fake<IRConConnectionFactory>())
|
|
|
|
|
.AddSingleton(A.Fake<IRConConnection>())
|
2020-10-17 11:47:56 -04:00
|
|
|
|
.AddSingleton(transLookup)
|
2020-04-22 19:46:41 -04:00
|
|
|
|
.AddSingleton(A.Fake<IRConParser>())
|
|
|
|
|
.AddSingleton(A.Fake<IParserRegexFactory>())
|
2020-05-04 17:50:02 -04:00
|
|
|
|
.AddSingleton<DataFileLoader>()
|
|
|
|
|
.AddSingleton(A.Fake<IGameLogReaderFactory>())
|
2020-08-17 22:21:11 -04:00
|
|
|
|
.AddSingleton(A.Fake<IMetaService>())
|
2020-05-16 12:54:01 -04:00
|
|
|
|
.AddSingleton(eventHandler)
|
|
|
|
|
.AddSingleton(ConfigurationGenerators.CreateApplicationConfiguration())
|
|
|
|
|
.AddSingleton(ConfigurationGenerators.CreateCommandConfiguration())
|
|
|
|
|
.AddSingleton<IConfigurationHandler<ApplicationConfiguration>, ApplicationConfigurationHandlerMock>();
|
2020-04-22 19:46:41 -04:00
|
|
|
|
|
|
|
|
|
return serviceCollection;
|
|
|
|
|
}
|
2020-05-16 12:54:01 -04:00
|
|
|
|
|
|
|
|
|
public static IServiceProvider SetupTestHooks(this IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
var mgr = serviceProvider.GetRequiredService<IManager>();
|
|
|
|
|
A.CallTo(() => mgr.GetApplicationSettings())
|
|
|
|
|
.Returns(serviceProvider.GetRequiredService<IConfigurationHandler<ApplicationConfiguration>>());
|
|
|
|
|
|
|
|
|
|
return serviceProvider;
|
|
|
|
|
}
|
2020-04-22 19:46:41 -04:00
|
|
|
|
}
|
|
|
|
|
}
|