Esempio n. 1
0
        public void Setup()
        {
            serviceProvider = new ServiceCollection()
                              .BuildBase(new EventHandlerMock(true))
                              .AddSingleton(A.Fake <ClientService>())
                              .AddSingleton <LoadMapCommand>()
                              .AddSingleton <SetLevelCommand>()
                              .AddSingleton <RunAsCommand>()
                              .AddSingleton <PrivateMessageAdminsCommand>()
                              .AddSingleton <KickCommand>()
                              .AddSingleton <WarnCommand>()
                              .AddSingleton <TempBanCommand>()
                              .AddSingleton <BanCommand>()
                              .BuildServiceProvider()
                              .SetupTestHooks();

            mockEventHandler = serviceProvider.GetRequiredService <EventHandlerMock>();
            manager          = serviceProvider.GetRequiredService <IManager>();
            transLookup      = serviceProvider.GetRequiredService <ITranslationLookup>();
            clientService    = serviceProvider.GetRequiredService <ClientService>();
            appConfig        = serviceProvider.GetRequiredService <ApplicationConfiguration>();
            appConfig.MapChangeDelaySeconds = 1;
            cmdConfig = serviceProvider.GetRequiredService <CommandConfiguration>();
            serviceProvider.GetService <IW4MServer>().RconParser =
                serviceProvider.GetService <IRConParser>();

            Utilities.DefaultLogger = serviceProvider.GetRequiredService <ILogger>();

            A.CallTo(() => manager.GetClientService())
            .Returns(clientService);

            A.CallTo(() => clientService.UpdateLevel(A <Permission> .Ignored, A <EFClient> .Ignored, A <EFClient> .Ignored))
            .Returns(Task.CompletedTask);

            A.CallTo(() => manager.GetCommands())
            .Returns(new Command[]
            {
                new ImpersonatableCommand(cmdConfig, transLookup),
                new NonImpersonatableCommand(cmdConfig, transLookup),
                new MockCommand(cmdConfig, transLookup)
            });

            A.CallTo(() => manager.AddEvent(A <GameEvent> .Ignored))
            .Invokes((fakeCall) => mockEventHandler.HandleEvent(manager, fakeCall.Arguments[0] as GameEvent));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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));
        }