using ApplicationTests.Fixtures; using ApplicationTests.Mocks; using FakeItEasy; using IW4MAdmin; using Microsoft.Extensions.DependencyInjection; using SharedLibraryCore.Configuration; using SharedLibraryCore.Database; using SharedLibraryCore.Interfaces; using SharedLibraryCore.Services; using System; namespace ApplicationTests { static class DependencyInjectionExtensions { public static IServiceCollection BuildBase(this IServiceCollection serviceCollection, IEventHandler eventHandler = null) { if (eventHandler == null) { eventHandler = new EventHandlerMock(); serviceCollection.AddSingleton(eventHandler as EventHandlerMock); } else if (eventHandler is EventHandlerMock mockEventHandler) { serviceCollection.AddSingleton(mockEventHandler); } var manager = A.Fake(); var logger = A.Fake(); A.CallTo(() => manager.GetLogger(A.Ignored)) .Returns(logger); serviceCollection.AddSingleton(logger) .AddSingleton(manager) .AddSingleton() .AddSingleton(A.Fake()) .AddSingleton(A.Fake()) .AddSingleton(A.Fake()) .AddSingleton(A.Fake()) .AddSingleton(A.Fake()) .AddSingleton() .AddSingleton(A.Fake()) .AddSingleton(eventHandler) .AddSingleton(ConfigurationGenerators.CreateApplicationConfiguration()) .AddSingleton(ConfigurationGenerators.CreateCommandConfiguration()) .AddSingleton, ApplicationConfigurationHandlerMock>(); serviceCollection.AddSingleton(_sp => new IW4MServer(_sp.GetRequiredService(), ConfigurationGenerators.CreateServerConfiguration(), _sp.GetRequiredService(), _sp.GetRequiredService(), _sp.GetRequiredService()) { RconParser = _sp.GetRequiredService() }); return serviceCollection; } public static IServiceProvider SetupTestHooks(this IServiceProvider serviceProvider) { var mgr = serviceProvider.GetRequiredService(); A.CallTo(() => mgr.GetApplicationSettings()) .Returns(serviceProvider.GetRequiredService>()); return serviceProvider; } } }