2020-04-01 15:11:56 -04:00
|
|
|
|
using FakeItEasy;
|
|
|
|
|
using IW4MAdmin.Application.RconParsers;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2020-04-01 15:11:56 -04:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
|
|
|
|
|
namespace ApplicationTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class BaseRConParserTests
|
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
private readonly ILogger<BaseRConParser> _fakeLogger = A.Fake<ILogger<BaseRConParser>>();
|
|
|
|
|
|
2020-04-01 15:11:56 -04:00
|
|
|
|
[Test]
|
|
|
|
|
public void SetDvarAsync_FormatStringType()
|
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
var parser = new BaseRConParser(_fakeLogger, A.Fake<IParserRegexFactory>());
|
2020-04-01 15:11:56 -04:00
|
|
|
|
var connection = A.Fake<IRConConnection>();
|
|
|
|
|
|
|
|
|
|
parser.SetDvarAsync(connection, "test", "test").Wait();
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => connection.SendQueryAsync(SharedLibraryCore.RCon.StaticHelpers.QueryType.SET_DVAR, "test \"test\""))
|
|
|
|
|
.MustHaveHappened();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SetDvarAsync_FormatEmptyStringTypeIncludesQuotes()
|
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
var parser = new BaseRConParser(_fakeLogger, A.Fake<IParserRegexFactory>());
|
2020-04-01 15:11:56 -04:00
|
|
|
|
var connection = A.Fake<IRConConnection>();
|
|
|
|
|
|
|
|
|
|
parser.SetDvarAsync(connection, "test", "").Wait();
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => connection.SendQueryAsync(SharedLibraryCore.RCon.StaticHelpers.QueryType.SET_DVAR, "test \"\""))
|
|
|
|
|
.MustHaveHappened();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SetDvarAsync_FormatsNonString()
|
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
var parser = new BaseRConParser(_fakeLogger, A.Fake<IParserRegexFactory>());
|
2020-04-01 15:11:56 -04:00
|
|
|
|
var connection = A.Fake<IRConConnection>();
|
|
|
|
|
|
|
|
|
|
parser.SetDvarAsync(connection, "test", 123).Wait();
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => connection.SendQueryAsync(SharedLibraryCore.RCon.StaticHelpers.QueryType.SET_DVAR, "test 123"))
|
|
|
|
|
.MustHaveHappened();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|