From e87d729536ec2948d34226e532358a782718113f Mon Sep 17 00:00:00 2001 From: felk Date: Mon, 20 Sep 2021 20:47:33 +0200 Subject: [PATCH] fix formatting in CommandProcessorTest --- .../Commands/CommandProcessorTest.cs | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/tests/TPP.Core.Tests/Commands/CommandProcessorTest.cs b/tests/TPP.Core.Tests/Commands/CommandProcessorTest.cs index acdde0d4..924f6a0d 100644 --- a/tests/TPP.Core.Tests/Commands/CommandProcessorTest.cs +++ b/tests/TPP.Core.Tests/Commands/CommandProcessorTest.cs @@ -73,7 +73,7 @@ public async Task TestCommandThrowsError() Assert.That(result?.Response, Is.EqualTo("An error occurred.")); string errorTextRegex = @"^An exception occured while executing command 'broken'\. " + - $@"User: {Regex.Escape(_mockUser.ToString())}, Original text: bla$"; + $@"User: {Regex.Escape(_mockUser.ToString())}, Original text: bla$"; loggerMock.VerifyLog(logger => logger.LogError( new InvalidOperationException("this command is busted!"), It.IsRegex(errorTextRegex))); } @@ -98,7 +98,9 @@ public async Task TestAliases() var commandProcessor = new CommandProcessor( _nullLogger, _commandLoggerMock.Object, new ArgsParser(), Mock.Of()); commandProcessor.InstallCommand(new Command("main", CommandUtils.StaticResponse("Hi!")) - { Aliases = new[] { "alias1", "alias2" } }); + { + Aliases = new[] { "alias1", "alias2" } + }); foreach (string command in ImmutableList.Create("main", "alias1", "ALIAS2")) { @@ -126,7 +128,9 @@ public void InstallConflictAlias() _nullLogger, _commandLoggerMock.Object, new ArgsParser(), Mock.Of()); commandProcessor.InstallCommand(new Command("a", CommandUtils.StaticResponse("Hi!")) - { Aliases = new[] { "x" } }); + { + Aliases = new[] { "x" } + }); ArgumentException ex = Assert.Throws(() => commandProcessor .InstallCommand(new Command("b", CommandUtils.StaticResponse("Hi!")) { Aliases = new[] { "X" } }))!; Assert.That(ex.Message, Is.EqualTo("The alias 'x' conflicts with: a(x): ")); @@ -139,7 +143,9 @@ public void InstallConflictNameVsAlias() _nullLogger, _commandLoggerMock.Object, new ArgsParser(), Mock.Of()); commandProcessor.InstallCommand(new Command("a", CommandUtils.StaticResponse("Hi!")) - { Aliases = new[] { "b" } }); + { + Aliases = new[] { "b" } + }); ArgumentException ex = Assert.Throws(() => commandProcessor .InstallCommand(new Command("b", CommandUtils.StaticResponse("Hi!")) { Aliases = new[] { "x" } }))!; Assert.That(ex.Message, Is.EqualTo("The command name 'b' conflicts with: a(b): ")); @@ -150,21 +156,24 @@ public async Task TestPermissions() { var commandProcessor = new CommandProcessor( _nullLogger, _commandLoggerMock.Object, new ArgsParser(), Mock.Of()); - commandProcessor.InstallCommand(new Command("opsonly", CommandUtils.StaticResponse("you are an operator")).WithCondition( - canExecute: ctx => IsOperator(ctx.Message.User), - ersatzResult: new CommandResult { Response = "Only operators can use that command" })); + commandProcessor.InstallCommand( + new Command("opsonly", CommandUtils.StaticResponse("you are an operator")).WithCondition( + canExecute: ctx => IsOperator(ctx.Message.User), + ersatzResult: new CommandResult { Response = "Only operators can use that command" })); bool IsOperator(User user) => user.Roles.Contains(Role.Operator); - User op = new User( - id: Guid.NewGuid().ToString(), - name: "operator", twitchDisplayName: "operator", simpleName: "mockoperator", color: null, - firstActiveAt: Instant.FromUnixTimeSeconds(0), lastActiveAt: Instant.FromUnixTimeSeconds(0), - lastMessageAt: null, pokeyen: 0, tokens: 0, roles: new HashSet { Role.Operator }); - - CommandResult? userResult = await commandProcessor.Process("opsonly", _noArgs, new Message(_mockUser, "", MessageSource.Chat, "")); + User op = new( + id: Guid.NewGuid().ToString(), + name: "operator", twitchDisplayName: "operator", simpleName: "mockoperator", color: null, + firstActiveAt: Instant.FromUnixTimeSeconds(0), lastActiveAt: Instant.FromUnixTimeSeconds(0), + lastMessageAt: null, pokeyen: 0, tokens: 0, roles: new HashSet { Role.Operator }); + + CommandResult? userResult = await commandProcessor.Process( + "opsonly", _noArgs, new Message(_mockUser, "", MessageSource.Chat, "")); Assert.That(userResult?.Response, Is.EqualTo("Only operators can use that command")); - CommandResult? opResult = await commandProcessor.Process("opsonly", _noArgs, new Message(op, "", MessageSource.Chat, "")); + CommandResult? opResult = await commandProcessor.Process( + "opsonly", _noArgs, new Message(op, "", MessageSource.Chat, "")); Assert.That(opResult?.Response, Is.EqualTo("you are an operator")); } @@ -178,7 +187,7 @@ public async Task MaxCommandsPerUser() additionalLoadFactorAtHighThreshold: 6); commandProcessor.InstallCommand(new Command("foo", - _ => Task.FromResult(new CommandResult {Response = "yes!"}))); + _ => Task.FromResult(new CommandResult { Response = "yes!" }))); clockMock.Setup(clock => clock.GetCurrentInstant()).Returns(Instant.FromUnixTimeSeconds(0)); CommandResult? resultOk1 = await commandProcessor.Process(