using ApplicationTests.Fixtures; using ApplicationTests.Mocks; using FakeItEasy; using IW4MAdmin; using Microsoft.Extensions.DependencyInjection; using SharedLibraryCore.Configuration; using SharedLibraryCore.Interfaces; using System; using ILogger = Microsoft.Extensions.Logging.ILogger; 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 transLookup = A.Fake(); A.CallTo(() => transLookup[A.Ignored]) .Returns("test"); serviceCollection .AddLogging() .AddSingleton(A.Fake()) .AddSingleton(A.Fake()) .AddSingleton(new ServerConfiguration { IPAddress = "127.0.0.1", Port = 28960 }) .AddSingleton(manager) .AddSingleton() .AddSingleton() .AddSingleton(A.Fake()) .AddSingleton(A.Fake()) .AddSingleton(transLookup) .AddSingleton(A.Fake()) .AddSingleton(A.Fake()) .AddSingleton() .AddSingleton(A.Fake()) .AddSingleton(A.Fake()) .AddSingleton(A.Fake()) .AddSingleton(eventHandler) .AddSingleton(ConfigurationGenerators.CreateApplicationConfiguration()) .AddSingleton(ConfigurationGenerators.CreateCommandConfiguration()) .AddSingleton, ApplicationConfigurationHandlerMock>(); return serviceCollection; } public static IServiceProvider SetupTestHooks(this IServiceProvider serviceProvider) { var mgr = serviceProvider.GetRequiredService(); A.CallTo(() => mgr.GetApplicationSettings()) .Returns(serviceProvider.GetRequiredService>()); return serviceProvider; } } }