2020-04-01 15:11:56 -04:00
|
|
|
|
using FakeItEasy;
|
|
|
|
|
using IW4MAdmin.Application.IO;
|
2020-05-04 17:50:02 -04:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-04-01 15:11:56 -04:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-11-12 20:46:17 -05:00
|
|
|
|
using SharedLibraryCore;
|
2020-04-01 15:11:56 -04:00
|
|
|
|
|
|
|
|
|
namespace ApplicationTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class IOTests
|
|
|
|
|
{
|
|
|
|
|
|
2020-05-04 17:50:02 -04:00
|
|
|
|
private IServiceProvider serviceProvider;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2020-11-12 20:46:17 -05:00
|
|
|
|
serviceProvider = new ServiceCollection()
|
|
|
|
|
.BuildBase()
|
|
|
|
|
.AddSingleton(new Uri[] { new Uri("C:\\test.log")})
|
|
|
|
|
.AddSingleton(A.Fake<IGameLogReaderFactory>())
|
|
|
|
|
.AddSingleton<GameLogEventDetection>()
|
|
|
|
|
.BuildServiceProvider();
|
2020-05-04 17:50:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-01 15:11:56 -04:00
|
|
|
|
[Test]
|
|
|
|
|
public async Task GameLogEventDetection_WorksAfterFileSizeReset()
|
|
|
|
|
{
|
|
|
|
|
var reader = A.Fake<IGameLogReader>();
|
2020-11-12 20:46:17 -05:00
|
|
|
|
var factory = serviceProvider.GetRequiredService<IGameLogReaderFactory>();
|
2020-05-04 17:50:02 -04:00
|
|
|
|
|
|
|
|
|
A.CallTo(() => factory.CreateGameLogReader(A<Uri[]>.Ignored, A<IEventParser>.Ignored))
|
|
|
|
|
.Returns(reader);
|
|
|
|
|
|
2020-11-12 20:46:17 -05:00
|
|
|
|
var detect = serviceProvider.GetRequiredService<GameLogEventDetection>();
|
2020-04-01 15:11:56 -04:00
|
|
|
|
|
|
|
|
|
A.CallTo(() => reader.Length)
|
|
|
|
|
.Returns(100)
|
|
|
|
|
.Once()
|
|
|
|
|
.Then
|
|
|
|
|
.Returns(200)
|
|
|
|
|
.Once()
|
|
|
|
|
.Then
|
|
|
|
|
.Returns(10)
|
|
|
|
|
.Once()
|
|
|
|
|
.Then
|
|
|
|
|
.Returns(100);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
await detect.UpdateLogEvents();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 17:50:02 -04:00
|
|
|
|
A.CallTo(() => reader.ReadEventsFromLog(A<long>.Ignored, A<long>.Ignored))
|
2020-04-01 15:11:56 -04:00
|
|
|
|
.MustHaveHappenedTwiceExactly();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|