[tweaks and fixes]

reenable tekno support
address vagrant thread issue
refactor game log reader creation to follow better practices
fix bot issues/address how guids are generated for bots/none provided
This commit is contained in:
RaidMax
2020-05-04 16:50:02 -05:00
parent b49592d666
commit 267e0b8cbe
50 changed files with 775 additions and 233 deletions

View File

@ -23,6 +23,9 @@
<None Update="Files\GameEvents.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Files\replay.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Files\T6Game.log">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

View File

@ -37,12 +37,10 @@ namespace ApplicationTests
cmdConfig = new CommandConfiguration();
serviceProvider = new ServiceCollection()
.BuildBase()
.BuildBase(new MockEventHandler(true))
.BuildServiceProvider();
mockEventHandler = new MockEventHandler(true);
A.CallTo(() => serviceProvider.GetRequiredService<IManager>().GetEventHandler())
.Returns(mockEventHandler);
mockEventHandler = serviceProvider.GetRequiredService<MockEventHandler>();
var mgr = serviceProvider.GetRequiredService<IManager>();
transLookup = serviceProvider.GetRequiredService<ITranslationLookup>();
@ -54,7 +52,9 @@ namespace ApplicationTests
new NonImpersonatableCommand(cmdConfig, transLookup)
});
//Utilities.DefaultCommandTimeout = new TimeSpan(0, 0, 2);
A.CallTo(() => mgr.AddEvent(A<GameEvent>.Ignored))
.Invokes((fakeCall) => mockEventHandler.HandleEvent(mgr, fakeCall.Arguments[0] as GameEvent));
}
#region RUNAS

View File

@ -9,10 +9,22 @@ using SharedLibraryCore.Services;
namespace ApplicationTests
{
static class DepedencyInjectionExtensions
static class DependencyInjectionExtensions
{
public static IServiceCollection BuildBase(this IServiceCollection serviceCollection)
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<IManager>();
var logger = A.Fake<ILogger>();
@ -27,10 +39,13 @@ namespace ApplicationTests
.AddSingleton(A.Fake<ITranslationLookup>())
.AddSingleton(A.Fake<IRConParser>())
.AddSingleton(A.Fake<IParserRegexFactory>())
.AddSingleton(A.Fake<ClientService>());
.AddSingleton<DataFileLoader>()
.AddSingleton(A.Fake<ClientService>())
.AddSingleton(A.Fake<IGameLogReaderFactory>())
.AddSingleton(eventHandler);
serviceCollection.AddSingleton(_sp => new IW4MServer(_sp.GetRequiredService<IManager>(), ConfigurationGenerators.CreateServerConfiguration(),
_sp.GetRequiredService<ITranslationLookup>(), _sp.GetRequiredService<IRConConnectionFactory>())
_sp.GetRequiredService<ITranslationLookup>(), _sp.GetRequiredService<IRConConnectionFactory>(), _sp.GetRequiredService<IGameLogReaderFactory>())
{
RconParser = _sp.GetRequiredService<IRConParser>()
});

View File

@ -0,0 +1,16 @@
using IW4MAdmin.Application.Misc;
using Newtonsoft.Json;
using System.IO;
using System.Threading.Tasks;
namespace ApplicationTests.Fixtures
{
class DataFileLoader
{
public async Task<T> Load<T>(string fileName)
{
string data = await File.ReadAllTextAsync($"{fileName}.json");
return JsonConvert.DeserializeObject<T>(data, EventLog.BuildVcrSerializationSettings());
}
}
}

View File

@ -0,0 +1,17 @@
using IW4MAdmin;
using IW4MAdmin.Application;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using SharedLibraryCore;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace ApplicationTests
{
[TestFixture]
public class GameEventHandlerTests
{
}
}

View File

@ -1,5 +1,7 @@
using FakeItEasy;
using IW4MAdmin;
using IW4MAdmin.Application.IO;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using SharedLibraryCore;
using SharedLibraryCore.Interfaces;
@ -12,11 +14,24 @@ namespace ApplicationTests
public class IOTests
{
private IServiceProvider serviceProvider;
[SetUp]
public void Setup()
{
serviceProvider = new ServiceCollection().BuildBase().BuildServiceProvider();
}
[Test]
public async Task GameLogEventDetection_WorksAfterFileSizeReset()
{
var reader = A.Fake<IGameLogReader>();
var detect = new GameLogEventDetection(null, "", A.Fake<Uri>(), reader);
var factory = A.Fake<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);
A.CallTo(() => reader.Length)
.Returns(100)
@ -35,7 +50,7 @@ namespace ApplicationTests
await detect.UpdateLogEvents();
}
A.CallTo(() => reader.ReadEventsFromLog(A<Server>.Ignored, A<long>.Ignored, A<long>.Ignored))
A.CallTo(() => reader.ReadEventsFromLog(A<long>.Ignored, A<long>.Ignored))
.MustHaveHappenedTwiceExactly();
}
}

View File

@ -36,6 +36,7 @@ namespace ApplicationTests
fakeManager = serviceProvider.GetRequiredService<IManager>();
fakeRConConnection = serviceProvider.GetRequiredService<IRConConnection>();
fakeRConParser = serviceProvider.GetRequiredService<IRConParser>();
mockEventHandler = serviceProvider.GetRequiredService<MockEventHandler>();
var rconConnectionFactory = serviceProvider.GetRequiredService<IRConConnectionFactory>();
@ -45,10 +46,9 @@ namespace ApplicationTests
A.CallTo(() => fakeRConParser.Configuration)
.Returns(ConfigurationGenerators.CreateRConParserConfiguration(serviceProvider.GetRequiredService<IParserRegexFactory>()));
mockEventHandler = new MockEventHandler();
A.CallTo(() => fakeManager.GetEventHandler())
.Returns(mockEventHandler);
A.CallTo(() => fakeManager.AddEvent(A<GameEvent>.Ignored))
.Invokes((fakeCall) => mockEventHandler.HandleEvent(fakeManager, fakeCall.Arguments[0] as GameEvent));
}
#region LOG

View File

@ -14,7 +14,7 @@ namespace ApplicationTests.Mocks
_autoExecute = autoExecute;
}
public void AddEvent(GameEvent gameEvent)
public void HandleEvent(IManager manager, GameEvent gameEvent)
{
Events.Add(gameEvent);

View File

@ -0,0 +1,21 @@
using SharedLibraryCore;
using SharedLibraryCore.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace ApplicationTests.Mocks
{
class VcrEventReader : IGameLogReader
{
public long Length => throw new NotImplementedException();
public int UpdateInterval => throw new NotImplementedException();
public Task<IEnumerable<GameEvent>> ReadEventsFromLog(long fileSizeDiff, long startPosition)
{
throw new NotImplementedException();
}
}
}

View File

@ -31,9 +31,7 @@ namespace ApplicationTests
{
serviceProvider = new ServiceCollection().BuildBase().BuildServiceProvider();
fakeManager = serviceProvider.GetRequiredService<IManager>();
mockEventHandler = new MockEventHandler();
A.CallTo(() => fakeManager.GetEventHandler())
.Returns(mockEventHandler);
mockEventHandler = serviceProvider.GetRequiredService<MockEventHandler>();
var rconConnectionFactory = serviceProvider.GetRequiredService<IRConConnectionFactory>();
@ -42,6 +40,9 @@ namespace ApplicationTests
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));
}
[Test]

View File

@ -33,7 +33,7 @@ namespace ApplicationTests
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<ITranslationLookup>(), A.Fake<IRConConnectionFactory>(), A.Fake<IGameLogReaderFactory>());
var parser = new BaseEventParser(A.Fake<IParserRegexFactory>(), A.Fake<ILogger>());
parser.Configuration.GuidNumberStyle = System.Globalization.NumberStyles.Integer;
@ -59,7 +59,7 @@ namespace ApplicationTests
var server = new IW4MServer(mgr,
new SharedLibraryCore.Configuration.ServerConfiguration() { IPAddress = "127.0.0.1", Port = 28960 },
A.Fake<ITranslationLookup>(), A.Fake<IRConConnectionFactory>());
A.Fake<ITranslationLookup>(), A.Fake<IRConConnectionFactory>(), A.Fake<IGameLogReaderFactory>());
var parser = new BaseEventParser(A.Fake<IParserRegexFactory>(), A.Fake<ILogger>());
parser.Configuration.GuidNumberStyle = System.Globalization.NumberStyles.Integer;

View File

@ -63,7 +63,7 @@ namespace ApplicationTests
var server = new IW4MServer(mgr,
new SharedLibraryCore.Configuration.ServerConfiguration() { IPAddress = "127.0.0.1", Port = 28960 },
A.Fake<ITranslationLookup>(),
A.Fake<IRConConnectionFactory>());
A.Fake<IRConConnectionFactory>(), A.Fake<IGameLogReaderFactory>());
var parser = new BaseEventParser(A.Fake<IParserRegexFactory>(), A.Fake<ILogger>());
parser.Configuration.GuidNumberStyle = System.Globalization.NumberStyles.Integer;

View File

@ -0,0 +1,43 @@
using ApplicationTests.Fixtures;
using IW4MAdmin;
using IW4MAdmin.Application;
using IW4MAdmin.Application.Misc;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ApplicationTests
{
[TestFixture]
public class VcrTests
{
private IServiceProvider serviceProvider;
[SetUp]
public void Setup()
{
serviceProvider = new ServiceCollection().BuildBase()
.BuildServiceProvider();
}
[Test]
[TestCase("replay")]
public async Task ReplayEvents(string source)
{
var sourceData = await serviceProvider
.GetRequiredService<DataFileLoader>()
.Load<EventLog>(source);
var server = serviceProvider.GetRequiredService<IW4MServer>();
foreach (var gameEvent in sourceData.Values.First())
{
await server.ExecuteEvent(gameEvent);
}
}
}
}