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-04-25 20:01:26 -04:00
|
|
|
|
using SharedLibraryCore.Database;
|
2020-04-22 19:46:41 -04:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using SharedLibraryCore.Services;
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
eventHandler = new MockEventHandler();
|
|
|
|
|
serviceCollection.AddSingleton(eventHandler as MockEventHandler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (eventHandler is MockEventHandler mockEventHandler)
|
|
|
|
|
{
|
|
|
|
|
serviceCollection.AddSingleton(mockEventHandler);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-22 19:46:41 -04:00
|
|
|
|
var manager = A.Fake<IManager>();
|
|
|
|
|
var logger = A.Fake<ILogger>();
|
2020-04-25 20:01:26 -04:00
|
|
|
|
|
2020-04-22 19:46:41 -04:00
|
|
|
|
A.CallTo(() => manager.GetLogger(A<long>.Ignored))
|
|
|
|
|
.Returns(logger);
|
|
|
|
|
|
|
|
|
|
serviceCollection.AddSingleton(logger)
|
|
|
|
|
.AddSingleton(manager)
|
2020-04-25 20:01:26 -04:00
|
|
|
|
.AddSingleton<IDatabaseContextFactory, DatabaseContextFactoryMock>()
|
2020-04-22 19:46:41 -04:00
|
|
|
|
.AddSingleton(A.Fake<IRConConnectionFactory>())
|
|
|
|
|
.AddSingleton(A.Fake<IRConConnection>())
|
|
|
|
|
.AddSingleton(A.Fake<ITranslationLookup>())
|
|
|
|
|
.AddSingleton(A.Fake<IRConParser>())
|
|
|
|
|
.AddSingleton(A.Fake<IParserRegexFactory>())
|
2020-05-04 17:50:02 -04:00
|
|
|
|
.AddSingleton<DataFileLoader>()
|
|
|
|
|
.AddSingleton(A.Fake<ClientService>())
|
|
|
|
|
.AddSingleton(A.Fake<IGameLogReaderFactory>())
|
|
|
|
|
.AddSingleton(eventHandler);
|
2020-04-22 19:46:41 -04:00
|
|
|
|
|
|
|
|
|
serviceCollection.AddSingleton(_sp => new IW4MServer(_sp.GetRequiredService<IManager>(), ConfigurationGenerators.CreateServerConfiguration(),
|
2020-05-04 17:50:02 -04:00
|
|
|
|
_sp.GetRequiredService<ITranslationLookup>(), _sp.GetRequiredService<IRConConnectionFactory>(), _sp.GetRequiredService<IGameLogReaderFactory>())
|
2020-04-22 19:46:41 -04:00
|
|
|
|
{
|
|
|
|
|
RconParser = _sp.GetRequiredService<IRConParser>()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return serviceCollection;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|