using ApplicationTests.Fixtures; using ApplicationTests.Mocks; using FakeItEasy; using IW4MAdmin; using Microsoft.Extensions.DependencyInjection; using SharedLibraryCore.Database; using SharedLibraryCore.Interfaces; using SharedLibraryCore.Services; namespace ApplicationTests { static class DependencyInjectionExtensions { public static IServiceCollection BuildBase(this IServiceCollection serviceCollection, IEventHandler eventHandler = null) { if (eventHandler == null) { eventHandler = new MockEventHandler(); serviceCollection.AddSingleton(eventHandler as MockEventHandler); } else if (eventHandler is MockEventHandler 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(A.Fake()) .AddSingleton(eventHandler); serviceCollection.AddSingleton(_sp => new IW4MServer(_sp.GetRequiredService(), ConfigurationGenerators.CreateServerConfiguration(), _sp.GetRequiredService(), _sp.GetRequiredService(), _sp.GetRequiredService()) { RconParser = _sp.GetRequiredService() }); return serviceCollection; } } }