public void Setup() { eventLogData = JsonConvert.DeserializeObject <EventLogTest>(System.IO.File.ReadAllText("Files/GameEvents.json")); appConfig = ConfigurationGenerators.CreateApplicationConfiguration(); serviceProvider = new ServiceCollection() .AddSingleton(A.Fake <ILogger>()) .AddSingleton <BaseEventParser>() .AddTransient <IParserPatternMatcher, ParserPatternMatcher>() .AddSingleton <IParserRegexFactory, ParserRegexFactory>() .AddSingleton(appConfig) .BuildServiceProvider(); }
public async Task Test_CommandProcessing_IsBroadcastCommand() { string broadcastPrefix = "@@"; var config = ConfigurationGenerators.CreateApplicationConfiguration(); config.BroadcastCommandPrefix = broadcastPrefix; var server = serviceProvider.GetRequiredService <IW4MServer>(); var cmd = EventGenerators.GenerateEvent(GameEvent.EventType.Command, $"{broadcastPrefix}{nameof(MockCommand)}", server); var result = await CommandProcessing.ValidateCommand(cmd, config); Assert.AreEqual(nameof(MockCommand), result.Name); Assert.IsTrue(result.IsBroadcast); }
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 <IManager>(); var logger = A.Fake <ILogger>(); var transLookup = A.Fake <ITranslationLookup>(); A.CallTo(() => transLookup[A <string> .Ignored]) .Returns("test"); A.CallTo(() => manager.GetLogger(A <long> .Ignored)) .Returns(logger); serviceCollection.AddSingleton(logger) .AddSingleton(manager) .AddSingleton <IDatabaseContextFactory, DatabaseContextFactoryMock>() .AddSingleton(A.Fake <IRConConnectionFactory>()) .AddSingleton(A.Fake <IRConConnection>()) .AddSingleton(transLookup) .AddSingleton(A.Fake <IRConParser>()) .AddSingleton(A.Fake <IParserRegexFactory>()) .AddSingleton <DataFileLoader>() .AddSingleton(A.Fake <IGameLogReaderFactory>()) .AddSingleton(A.Fake <IMetaService>()) .AddSingleton(eventHandler) .AddSingleton(ConfigurationGenerators.CreateApplicationConfiguration()) .AddSingleton(ConfigurationGenerators.CreateCommandConfiguration()) .AddSingleton <IConfigurationHandler <ApplicationConfiguration>, ApplicationConfigurationHandlerMock>(); serviceCollection.AddSingleton(_sp => new IW4MServer(_sp.GetRequiredService <IManager>(), ConfigurationGenerators.CreateServerConfiguration(), _sp.GetRequiredService <ITranslationLookup>(), _sp.GetRequiredService <IRConConnectionFactory>(), _sp.GetRequiredService <IGameLogReaderFactory>(), _sp.GetRequiredService <IMetaService>()) { RconParser = _sp.GetRequiredService <IRConParser>() }); return(serviceCollection); }
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 <IManager>(); var transLookup = A.Fake <ITranslationLookup>(); A.CallTo(() => transLookup[A <string> .Ignored]) .Returns("test"); serviceCollection .AddLogging() .AddSingleton(A.Fake <ILogger>()) .AddSingleton(A.Fake <SharedLibraryCore.Interfaces.ILogger>()) .AddSingleton(new ServerConfiguration { IPAddress = "127.0.0.1", Port = 28960 }) .AddSingleton(manager) .AddSingleton <IDatabaseContextFactory, DatabaseContextFactoryMock>() .AddSingleton <IW4MServer>() .AddSingleton(A.Fake <IRConConnectionFactory>()) .AddSingleton(A.Fake <IRConConnection>()) .AddSingleton(transLookup) .AddSingleton(A.Fake <IRConParser>()) .AddSingleton(A.Fake <IParserRegexFactory>()) .AddSingleton <DataFileLoader>() .AddSingleton(A.Fake <IGameLogReaderFactory>()) .AddSingleton(A.Fake <IMetaService>()) .AddSingleton(A.Fake <IClientNoticeMessageFormatter>()) .AddSingleton(eventHandler) .AddSingleton(ConfigurationGenerators.CreateApplicationConfiguration()) .AddSingleton(ConfigurationGenerators.CreateCommandConfiguration()) .AddSingleton <IConfigurationHandler <ApplicationConfiguration>, ApplicationConfigurationHandlerMock>(); return(serviceCollection); }
public void Setup() { serviceProvider = new ServiceCollection().BuildBase() .AddSingleton(A.Fake <ClientService>()) .AddSingleton <IScriptCommandFactory, ScriptCommandFactory>() .AddSingleton(A.Fake <IScriptPluginServiceResolver>()) .BuildServiceProvider(); fakeManager = serviceProvider.GetRequiredService <IManager>(); mockEventHandler = serviceProvider.GetRequiredService <EventHandlerMock>(); var rconConnectionFactory = serviceProvider.GetRequiredService <IRConConnectionFactory>(); A.CallTo(() => rconConnectionFactory.CreateConnection(A <string> .Ignored, A <int> .Ignored, A <string> .Ignored)) .Returns(serviceProvider.GetRequiredService <IRConConnection>()); A.CallTo(() => serviceProvider.GetRequiredService <IRConParser>().Configuration) .Returns(ConfigurationGenerators.CreateRConParserConfiguration(serviceProvider.GetRequiredService <IParserRegexFactory>())); A.CallTo(() => fakeManager.AddEvent(A <GameEvent> .Ignored)) .Invokes((fakeCall) => mockEventHandler.HandleEvent(fakeManager, fakeCall.Arguments[0] as GameEvent)); }
public void Setup() { serviceProvider = new ServiceCollection().BuildBase().BuildServiceProvider(); fakeLogger = serviceProvider.GetRequiredService <ILogger>(); fakeManager = serviceProvider.GetRequiredService <IManager>(); fakeRConConnection = serviceProvider.GetRequiredService <IRConConnection>(); fakeRConParser = serviceProvider.GetRequiredService <IRConParser>(); mockEventHandler = serviceProvider.GetRequiredService <EventHandlerMock>(); appConfig = serviceProvider.GetRequiredService <ApplicationConfiguration>(); var rconConnectionFactory = serviceProvider.GetRequiredService <IRConConnectionFactory>(); A.CallTo(() => rconConnectionFactory.CreateConnection(A <string> .Ignored, A <int> .Ignored, A <string> .Ignored)) .Returns(fakeRConConnection); A.CallTo(() => fakeRConParser.Configuration) .Returns(ConfigurationGenerators.CreateRConParserConfiguration(serviceProvider.GetRequiredService <IParserRegexFactory>())); A.CallTo(() => fakeManager.AddEvent(A <GameEvent> .Ignored)) .Invokes((fakeCall) => mockEventHandler.HandleEvent(fakeManager, fakeCall.Arguments[0] as GameEvent)); }