update unit tests
This commit is contained in:
parent
5d9c8f5369
commit
e997b94b3b
@ -17,7 +17,7 @@ namespace IW4MAdmin.Application.IO
|
||||
private readonly bool _ignoreBots;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public GameLogEventDetection(ILogger<GameLogEventDetection> logger, Server server, Uri[] gameLogUris, IGameLogReaderFactory gameLogReaderFactory)
|
||||
public GameLogEventDetection(ILogger<GameLogEventDetection> logger, IW4MServer server, Uri[] gameLogUris, IGameLogReaderFactory gameLogReaderFactory)
|
||||
{
|
||||
_reader = gameLogReaderFactory.CreateGameLogReader(gameLogUris, server.EventParser);
|
||||
_server = server;
|
||||
|
@ -9,8 +9,8 @@ using SharedLibraryCore;
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using static SharedLibraryCore.GameEvent;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace ApplicationTests
|
||||
{
|
||||
|
@ -8,6 +8,7 @@ using SharedLibraryCore.Database.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using SharedLibraryCore.Configuration;
|
||||
|
||||
namespace ApplicationTests
|
||||
{
|
||||
|
@ -16,6 +16,7 @@ using SharedLibraryCore.Services;
|
||||
using static SharedLibraryCore.Database.Models.EFClient;
|
||||
using FluentAssertions;
|
||||
using FluentAssertions.Extensions;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace ApplicationTests
|
||||
{
|
||||
@ -50,6 +51,10 @@ namespace ApplicationTests
|
||||
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);
|
||||
|
@ -6,8 +6,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharedLibraryCore;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace ApplicationTests
|
||||
{
|
||||
@ -28,7 +27,6 @@ namespace ApplicationTests
|
||||
}
|
||||
|
||||
var manager = A.Fake<IManager>();
|
||||
var logger = A.Fake<ILogger>();
|
||||
|
||||
var transLookup = A.Fake<ITranslationLookup>();
|
||||
A.CallTo(() => transLookup[A<string>.Ignored])
|
||||
@ -37,8 +35,11 @@ namespace ApplicationTests
|
||||
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)
|
||||
@ -52,17 +53,6 @@ namespace ApplicationTests
|
||||
.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>(),
|
||||
_sp.GetRequiredService<ILogger<Server>>())
|
||||
{
|
||||
RconParser = _sp.GetRequiredService<IRConParser>()
|
||||
});
|
||||
|
||||
return serviceCollection;
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
using FakeItEasy;
|
||||
using IW4MAdmin;
|
||||
using IW4MAdmin.Application.IO;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NUnit.Framework;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using SharedLibraryCore;
|
||||
|
||||
namespace ApplicationTests
|
||||
{
|
||||
@ -19,19 +18,24 @@ namespace ApplicationTests
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
serviceProvider = new ServiceCollection().BuildBase().BuildServiceProvider();
|
||||
serviceProvider = new ServiceCollection()
|
||||
.BuildBase()
|
||||
.AddSingleton(new Uri[] { new Uri("C:\\test.log")})
|
||||
.AddSingleton(A.Fake<IGameLogReaderFactory>())
|
||||
.AddSingleton<GameLogEventDetection>()
|
||||
.BuildServiceProvider();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GameLogEventDetection_WorksAfterFileSizeReset()
|
||||
{
|
||||
var reader = A.Fake<IGameLogReader>();
|
||||
var factory = A.Fake<IGameLogReaderFactory>();
|
||||
var factory = serviceProvider.GetRequiredService<IGameLogReaderFactory>();
|
||||
|
||||
A.CallTo(() => factory.CreateGameLogReader(A<Uri[]>.Ignored, A<IEventParser>.Ignored))
|
||||
.Returns(reader);
|
||||
|
||||
var detect = new GameLogEventDetection(serviceProvider.GetService<IW4MServer>(), new Uri[] { new Uri("C:\\test.log") }, factory);
|
||||
var detect = serviceProvider.GetRequiredService<GameLogEventDetection>();
|
||||
|
||||
A.CallTo(() => reader.Length)
|
||||
.Returns(100)
|
||||
|
@ -41,6 +41,8 @@ namespace ApplicationTests
|
||||
fakeRConParser = serviceProvider.GetRequiredService<IRConParser>();
|
||||
mockEventHandler = serviceProvider.GetRequiredService<EventHandlerMock>();
|
||||
appConfig = serviceProvider.GetRequiredService<ApplicationConfiguration>();
|
||||
serviceProvider.GetService<IW4MServer>().RconParser =
|
||||
serviceProvider.GetService<IRConParser>();
|
||||
|
||||
var rconConnectionFactory = serviceProvider.GetRequiredService<IRConConnectionFactory>();
|
||||
|
||||
@ -215,7 +217,7 @@ namespace ApplicationTests
|
||||
|
||||
await server.Ban("test reason", target, origin);
|
||||
|
||||
A.CallTo(() => fakeRConParser.ExecuteCommandAsync(fakeRConConnection, "kick"))
|
||||
A.CallTo(() => server.RconParser.ExecuteCommandAsync(A<IRConConnection>.Ignored, "kick"))
|
||||
.MustHaveHappenedOnceExactly();
|
||||
}
|
||||
|
||||
@ -290,7 +292,7 @@ namespace ApplicationTests
|
||||
|
||||
await server.TempBan("test reason", TimeSpan.Zero, target, origin);
|
||||
|
||||
A.CallTo(() => fakeRConParser.ExecuteCommandAsync(fakeRConConnection, "kick"))
|
||||
A.CallTo(() => server.RconParser.ExecuteCommandAsync(A<IRConConnection>.Ignored, "kick"))
|
||||
.MustHaveHappenedOnceExactly();
|
||||
}
|
||||
|
||||
@ -312,7 +314,7 @@ namespace ApplicationTests
|
||||
|
||||
await server.TempBan("test reason", TimeSpan.Zero, target, origin);
|
||||
|
||||
A.CallTo(() => fakeRConParser.ExecuteCommandAsync(fakeRConConnection, "kick"))
|
||||
A.CallTo(() => server.RconParser.ExecuteCommandAsync(A<IRConConnection>.Ignored, "kick"))
|
||||
.MustHaveHappenedOnceExactly();
|
||||
}
|
||||
#endregion
|
||||
@ -348,7 +350,7 @@ namespace ApplicationTests
|
||||
|
||||
await server.Kick("test reason", target, origin);
|
||||
|
||||
A.CallTo(() => fakeRConParser.ExecuteCommandAsync(fakeRConConnection, "kick"))
|
||||
A.CallTo(() => server.RconParser.ExecuteCommandAsync(A<IRConConnection>.Ignored, "kick"))
|
||||
.MustHaveHappenedOnceExactly();
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ using SharedLibraryCore.Services;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace ApplicationTests
|
||||
{
|
||||
|
@ -1,36 +1,32 @@
|
||||
using FakeItEasy;
|
||||
using IW4MAdmin;
|
||||
using IW4MAdmin.Application;
|
||||
using IW4MAdmin.Application.EventParsers;
|
||||
using NUnit.Framework;
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharedLibraryCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace ApplicationTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ServerTests
|
||||
{
|
||||
private IServiceProvider _serviceProvider;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
|
||||
_serviceProvider = new ServiceCollection()
|
||||
.BuildBase()
|
||||
.BuildServiceProvider();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GameTimeFalseQuitTest()
|
||||
{
|
||||
var mgr = A.Fake<IManager>();
|
||||
var server = new IW4MServer(mgr,
|
||||
new SharedLibraryCore.Configuration.ServerConfiguration() { IPAddress = "127.0.0.1", Port = 28960 },
|
||||
A.Fake<ITranslationLookup>(), A.Fake<IRConConnectionFactory>(),
|
||||
A.Fake<IGameLogReaderFactory>(), A.Fake<IMetaService>(), A.Fake<ILogger<Server>>());
|
||||
|
||||
var server = _serviceProvider.GetRequiredService<IW4MServer>();
|
||||
var parser = new BaseEventParser(A.Fake<IParserRegexFactory>(), A.Fake<ILogger>(), A.Fake<ApplicationConfiguration>());
|
||||
parser.Configuration.GuidNumberStyle = System.Globalization.NumberStyles.Integer;
|
||||
|
||||
@ -50,13 +46,7 @@ namespace ApplicationTests
|
||||
[Test]
|
||||
public void LogFileReplay()
|
||||
{
|
||||
var mgr = A.Fake<IManager>();
|
||||
|
||||
var server = new IW4MServer(mgr,
|
||||
new SharedLibraryCore.Configuration.ServerConfiguration() { IPAddress = "127.0.0.1", Port = 28960 },
|
||||
A.Fake<ITranslationLookup>(), A.Fake<IRConConnectionFactory>(), A.Fake<IGameLogReaderFactory>(), A.Fake<IMetaService>(),
|
||||
A.Fake<ILogger<Server>>());
|
||||
|
||||
var server = _serviceProvider.GetRequiredService<IW4MServer>();
|
||||
var parser = new BaseEventParser(A.Fake<IParserRegexFactory>(), A.Fake<ILogger>(), A.Fake<ApplicationConfiguration>());
|
||||
parser.Configuration.GuidNumberStyle = System.Globalization.NumberStyles.Integer;
|
||||
|
||||
|
@ -13,8 +13,6 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using IW4MAdmin.Plugins.Stats.Helpers;
|
||||
using ApplicationTests.Fixtures;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharedLibraryCore;
|
||||
using Stats.Helpers;
|
||||
using Stats.Dtos;
|
||||
using SharedLibraryCore.Configuration;
|
||||
@ -37,8 +35,11 @@ namespace ApplicationTests
|
||||
handlerFactory = A.Fake<IConfigurationHandlerFactory>();
|
||||
|
||||
serviceProvider = new ServiceCollection()
|
||||
.AddSingleton<StatsResourceQueryHelper>()
|
||||
.BuildBase()
|
||||
.AddSingleton(A.Fake<IConfigurationHandler<StatsConfiguration>>())
|
||||
.AddSingleton<StatsResourceQueryHelper>()
|
||||
.AddSingleton(new ServerConfiguration() { IPAddress = "127.0.0.1", Port = 28960 })
|
||||
.AddSingleton<StatManager>()
|
||||
.AddSingleton<IW4MAdmin.Plugins.Stats.Plugin>()
|
||||
.BuildServiceProvider();
|
||||
|
||||
@ -61,11 +62,7 @@ namespace ApplicationTests
|
||||
A.CallTo(() => handlerFactory.GetConfigurationHandler<StatsConfiguration>(A<string>.Ignored))
|
||||
.Returns(config);
|
||||
|
||||
var server = new IW4MServer(mgr,
|
||||
new SharedLibraryCore.Configuration.ServerConfiguration() { IPAddress = "127.0.0.1", Port = 28960 },
|
||||
A.Fake<ITranslationLookup>(),
|
||||
A.Fake<IRConConnectionFactory>(),
|
||||
A.Fake<IGameLogReaderFactory>(), A.Fake<IMetaService>(), A.Fake<ILogger<Server>>());
|
||||
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
||||
|
||||
var parser = new BaseEventParser(A.Fake<IParserRegexFactory>(), A.Fake<ILogger>(), A.Fake<ApplicationConfiguration>());
|
||||
parser.Configuration.GuidNumberStyle = System.Globalization.NumberStyles.Integer;
|
||||
@ -128,8 +125,8 @@ namespace ApplicationTests
|
||||
public async Task Test_ConcurrentCallsToUpdateStatHistoryDoesNotCauseException()
|
||||
{
|
||||
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
||||
var configHandler = A.Fake<IConfigurationHandler<StatsConfiguration>>();
|
||||
var mgr = new StatManager(serviceProvider.GetRequiredService<IManager>(), serviceProvider.GetRequiredService<IDatabaseContextFactory>(), configHandler);
|
||||
var configHandler = serviceProvider.GetRequiredService<IConfigurationHandler<StatsConfiguration>>();
|
||||
var mgr = serviceProvider.GetRequiredService<StatManager>();
|
||||
var target = ClientGenerators.CreateDatabaseClient();
|
||||
target.CurrentServer = server;
|
||||
|
||||
@ -141,10 +138,11 @@ namespace ApplicationTests
|
||||
|
||||
var dbFactory = serviceProvider.GetRequiredService<IDatabaseContextFactory>();
|
||||
var db = dbFactory.CreateContext(true);
|
||||
db.Set<EFServer>().Add(new EFServer()
|
||||
var efServer = new EFServer()
|
||||
{
|
||||
EndPoint = server.EndPoint.ToString()
|
||||
});
|
||||
};
|
||||
db.Set<EFServer>().Add(efServer);
|
||||
|
||||
db.Clients.Add(target);
|
||||
db.SaveChanges();
|
||||
@ -154,6 +152,10 @@ namespace ApplicationTests
|
||||
var stats = target.GetAdditionalProperty<EFClientStatistics>("ClientStats");
|
||||
|
||||
await mgr.UpdateStatHistory(target, stats);
|
||||
|
||||
db.Clients.Remove(target);
|
||||
db.Set<EFServer>().Remove(efServer);
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
#region QUERY_HELPER
|
||||
@ -161,7 +163,7 @@ namespace ApplicationTests
|
||||
public async Task Test_StatsQueryHelper_Get()
|
||||
{
|
||||
var queryHelper = serviceProvider.GetRequiredService<StatsResourceQueryHelper>();
|
||||
using var context = contextFactory.CreateContext();
|
||||
await using var context = contextFactory.CreateContext();
|
||||
|
||||
var server = new EFServer() { ServerId = 1 };
|
||||
var stats = new EFClientStatistics()
|
||||
|
Loading…
Reference in New Issue
Block a user