public async Task TryCreateScoresheetWithMoreThanTwoTeamsFails() { ExcelFileScoresheetGenerator generator = new ExcelFileScoresheetGenerator(); ByCommandTeamManager teamManager = new ByCommandTeamManager(); GameState game = new GameState() { Format = Format.TossupBonusesShootout, ReaderId = 1, TeamManager = teamManager }; for (int i = 0; i < 3; i++) { string teamName = $"Team{i}"; Assert.IsTrue(teamManager.TryAddTeam(teamName, out _), $"Couldn't add team {teamName}"); } await game.AddPlayer(2, "Alice"); game.ScorePlayer(10); IResult <Stream> result = await generator.TryCreateScoresheet(game, "Reader X", "Room A"); Assert.IsFalse(result.Success, $"Creation succeeded when it should've failed."); Assert.AreEqual( "Export only works if there are 1 or 2 teams in the game.", result.ErrorMessage, "Unexpected error message"); }
public async Task AddMultipleTeams() { ByCommandTeamManager teamManager = new ByCommandTeamManager(); Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add the first team"); Assert.IsTrue( teamManager.TryAddTeam(SecondTeam, out _), "Couldn't add the second team"); Assert.IsTrue( teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam), "Couldn't add the first player"); Assert.IsTrue( teamManager.TryAddPlayerToTeam(SecondPlayerId, SecondPlayerName, SecondTeam), "Couldn't add the second player"); IEnumerable <PlayerTeamPair> pairs = await teamManager.GetKnownPlayers(); Assert.AreEqual(2, pairs.Count(), "Unexpected number of known players"); PlayerTeamPair firstPair = pairs.FirstOrDefault(pair => pair.PlayerId == FirstPlayerId); Assert.IsNotNull(firstPair, "Couldn't find the first player"); Assert.AreEqual(FirstTeam, firstPair.TeamId, "First player has the wrong team"); Assert.AreEqual(FirstPlayerName, firstPair.PlayerDisplayName, "First player has the wrong name"); PlayerTeamPair secondPair = pairs.FirstOrDefault(pair => pair.PlayerId == SecondPlayerId); Assert.IsNotNull(secondPair, "Couldn't find the second player"); Assert.AreEqual(SecondTeam, secondPair.TeamId, "First player has the wrong team"); Assert.AreEqual(SecondPlayerName, secondPair.PlayerDisplayName, "Second player has the wrong name"); }
public async Task AddingSamePlayerToDifferentTeam() { ByCommandTeamManager teamManager = new ByCommandTeamManager(); Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add the first team"); Assert.IsTrue(teamManager.TryAddTeam(SecondTeam, out _), "Couldn't add the second team"); Assert.IsTrue( teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam), "Couldn't add player to team"); IEnumerable <PlayerTeamPair> pairs = await teamManager.GetKnownPlayers(); Assert.AreEqual(1, pairs.Count(), "Unexpected number of players"); PlayerTeamPair pair = pairs.First(); Assert.AreEqual(FirstPlayerId, pair.PlayerId, "Player should be known"); Assert.AreEqual(FirstTeam, pair.TeamId, "Player should be on the first team"); Assert.AreEqual(FirstPlayerName, pair.PlayerDisplayName, "Player should have the same display name"); Assert.IsTrue( teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, SecondTeam), "Should be able to add the same player to the same team (as a no-op)"); pairs = await teamManager.GetKnownPlayers(); Assert.AreEqual(1, pairs.Count(), "Unexpected number of players after the second add"); pair = pairs.First(); Assert.AreEqual(FirstPlayerId, pair.PlayerId, "Player should still be known"); Assert.AreEqual(FirstPlayerName, pair.PlayerDisplayName, "Player should still have the same display name"); Assert.AreEqual(SecondTeam, pair.TeamId, "Player should be on the second team"); }
public async Task CannotRemovePlayerNotOnTeam() { ulong buzzer = GetExistingNonReaderUserId(); string nickname = $"User_{buzzer}"; this.CreateHandler( out ReaderCommandHandler handler, out GameState currentGame, out MessageStore messageStore); currentGame.ReaderId = DefaultReaderId; ByCommandTeamManager teamManager = new ByCommandTeamManager(); currentGame.TeamManager = teamManager; Assert.IsTrue(teamManager.TryAddTeam("Alpha", out _), "Team should've been added"); Mock <IGuildUser> mockUser = new Mock <IGuildUser>(); mockUser.Setup(user => user.Id).Returns(buzzer); mockUser.Setup(user => user.Nickname).Returns(nickname); await handler.RemovePlayerAsync(mockUser.Object); IEnumerable <PlayerTeamPair> players = await teamManager.GetKnownPlayers(); Assert.IsFalse(players.Any(), "There should be no players"); Assert.AreEqual(1, messageStore.ChannelMessages.Count, "Unexpected number of channel messages."); string message = messageStore.ChannelMessages.First(); Assert.IsTrue( message.Contains($@"Couldn't remove player ""{nickname}""", StringComparison.InvariantCulture), $"Couldn't find failure message in message\n{message}"); }
public async Task GetTeamIdOfNonexistentPlayer() { ByCommandTeamManager teamManager = new ByCommandTeamManager(); Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add the team"); Assert.IsTrue( teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam), "Couldn't add the player"); Assert.IsNull(await teamManager.GetTeamIdOrNull(SecondPlayerId), "Unexpected team ID"); }
private static GameState CreateGameStateWithByCommandTeamManager(out ByCommandTeamManager teamManager) { teamManager = new ByCommandTeamManager(); return(new GameState() { ReaderId = 0, TeamManager = teamManager }); }
public void CannotRemoveNonexistentTeam() { ByCommandTeamManager teamManager = new ByCommandTeamManager(); Assert.IsFalse(teamManager.TryRemoveTeam(FirstTeam, out string errorMessage), "Remove should've failed"); Assert.AreEqual( $@"Cannot remove team ""{FirstTeam}"" because it's not in the current game.", errorMessage, "Unexpected error message"); }
public async Task TryAddTeam() { ByCommandTeamManager teamManager = new ByCommandTeamManager(); Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add team"); IReadOnlyDictionary <string, string> teamIdToName = await teamManager.GetTeamIdToNames(); Assert.IsTrue(teamIdToName.TryGetValue(FirstTeam, out string teamName), "Couldn't find team after adding it"); Assert.AreEqual(FirstTeam, teamName, "Unexpected team name"); }
public async Task TryCreateScoresheetAtLastTossupSucceeds() { ExcelFileScoresheetGenerator generator = new ExcelFileScoresheetGenerator(); ByCommandTeamManager teamManager = new ByCommandTeamManager(); GameState game = new GameState() { Format = Format.CreateTossupBonusesShootout(false), ReaderId = 1, TeamManager = teamManager }; Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add the first team"); Assert.IsTrue(teamManager.TryAddTeam(SecondTeam, out _), "Couldn't add the second team"); Assert.IsTrue(teamManager.TryAddPlayerToTeam(2, "Alice", FirstTeam), "Couldn't add first player to team"); Assert.IsTrue(teamManager.TryAddPlayerToTeam(3, "Bob", SecondTeam), "Couldn't add second player to team"); // The first phase row is the first one, so add 1 to include it in the count int tossupsCount = ExcelFileScoresheetGenerator.LastBonusRow - ExcelFileScoresheetGenerator.FirstPhaseRow + 1; for (int i = 0; i < tossupsCount - 1; i++) { await game.AddPlayer(2, "Alice"); game.ScorePlayer(10); Assert.IsTrue(game.TryScoreBonus("0"), $"Scoring a bonus should've succeeded in phase {i}"); } await game.AddPlayer(3, "Bob"); game.ScorePlayer(-5); await game.AddPlayer(2, "Alice"); game.ScorePlayer(15); Assert.IsTrue(game.TryScoreBonus("10/0/10"), "Scoring the last bonus should've succeeded"); IResult <Stream> result = await generator.TryCreateScoresheet(game, "Reader X", "Room A"); Assert.IsTrue(result.Success, $"Creation should've succeeded at the limit."); using (IXLWorkbook workbook = new XLWorkbook(result.Value)) { Assert.AreEqual(1, workbook.Worksheets.Count, "Unexpected number of worksheets"); IXLWorksheet worksheet = workbook.Worksheet(1); Assert.AreEqual( "15", worksheet.Cell("B31").Value.ToString(), "Alice's power at the end was not recorded"); Assert.AreEqual( "-5", worksheet.Cell("N31").Value.ToString(), "Bob's neg at the end was not recorded"); Assert.AreEqual("10", worksheet.Cell("H31").Value.ToString(), "First bonus part is wrong"); Assert.AreEqual("0", worksheet.Cell("I31").Value.ToString(), "Second bonus part is wrong"); Assert.AreEqual("10", worksheet.Cell("J31").Value.ToString(), "Third bonus part is wrong"); Assert.AreEqual("35", worksheet.Cell("K31").Value.ToString(), "Alice's total for the phase is wrong"); Assert.AreEqual("-5", worksheet.Cell("W31").Value.ToString(), "Bob's total for the phase is wrong"); } }
public async Task GetTeamIdOfPlayerAfterRemoval() { ByCommandTeamManager teamManager = new ByCommandTeamManager(); Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add the team"); Assert.IsTrue( teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam), "Couldn't add the player"); Assert.IsTrue( teamManager.TryRemovePlayerFromTeam(FirstPlayerId), "Couldn't remove the player"); Assert.IsNull(await teamManager.GetTeamIdOrNull(FirstPlayerId), "Unexpected team ID"); }
public async Task TryCreateScoresheetAtPlayerLimitSucceeds() { ExcelFileScoresheetGenerator generator = new ExcelFileScoresheetGenerator(); ByCommandTeamManager teamManager = new ByCommandTeamManager(); GameState game = new GameState() { Format = Format.TossupShootout, ReaderId = 1, TeamManager = teamManager }; Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add the first team"); Assert.IsTrue(teamManager.TryAddTeam(SecondTeam, out _), "Couldn't add the second team"); for (int i = 0; i < ExcelFileScoresheetGenerator.PlayersPerTeamLimit; i++) { Assert.IsTrue( teamManager.TryAddPlayerToTeam((ulong)i + 2, $"FirstPlayer{i}", FirstTeam), $"Couldn't add player #{i} to the first team"); Assert.IsTrue( teamManager.TryAddPlayerToTeam((ulong)i + 200, $"SecondPlayer{i}", SecondTeam), $"Couldn't add player #{i} to the second team"); } IResult <Stream> result = await generator.TryCreateScoresheet(game, "Reader X", "Room A"); Assert.IsTrue(result.Success, $"Creation should've succeeded at the limit."); using (IXLWorkbook workbook = new XLWorkbook(result.Value)) { Assert.AreEqual(1, workbook.Worksheets.Count, "Unexpected number of worksheets"); IXLWorksheet worksheet = workbook.Worksheet(1); for (int i = 2; i <= 7; i++) { string playerName = $"FirstPlayer{i - 2}"; Assert.AreEqual( playerName, worksheet.Cell(7, i).Value.ToString(), $"Unexpected first team player name at column {i}"); } for (int i = 14; i <= 19; i++) { string playerName = $"SecondPlayer{i - 14}"; Assert.AreEqual( playerName, worksheet.Cell(7, i).Value.ToString(), $"Unexpected first team player name at column {i}"); } } }
public async Task RemovePlayerFromTeam() { ByCommandTeamManager teamManager = new ByCommandTeamManager(); Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add team"); Assert.IsTrue( teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam), "Couldn't add player to team"); Assert.IsTrue(teamManager.TryRemovePlayerFromTeam(FirstPlayerId), "Couldn't remove player from team"); IEnumerable <PlayerTeamPair> pairs = await teamManager.GetKnownPlayers(); Assert.IsFalse(pairs.Any(), "There should be no players, but some were found"); }
public async Task AddingPlayerToTeam() { ByCommandTeamManager teamManager = new ByCommandTeamManager(); Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add team"); Assert.IsTrue( teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam), "Couldn't add player to team"); IEnumerable <PlayerTeamPair> pairs = await teamManager.GetKnownPlayers(); Assert.AreEqual(1, pairs.Count(), "Unexpected number of players"); PlayerTeamPair pair = pairs.First(); Assert.AreEqual(FirstPlayerId, pair.PlayerId, "Player should be known"); Assert.AreEqual(FirstTeam, pair.TeamId, "Player should be on the first team"); }
public async Task TryReaddTeam() { ByCommandTeamManager teamManager = new ByCommandTeamManager(); Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add team"); IReadOnlyDictionary <string, string> teamIdToName = await teamManager.GetTeamIdToNames(); Assert.IsTrue(teamIdToName.TryGetValue(FirstTeam, out string teamName), "Couldn't find team after adding it"); Assert.AreEqual(FirstTeam, teamName, "Unexpected team name"); Assert.IsFalse( teamManager.TryAddTeam(FirstTeam, out string errorMessage), "Re-adding a team should fail"); Assert.AreEqual( $@"Team ""{FirstTeam}"" already exists.", errorMessage); }
public async Task RemoveTeamFailsWhenPlayerScored() { const ulong playerId = 2; const string playerName = "Alice"; const string teamName = "Alpha"; this.CreateHandler( out ReaderCommandHandler handler, out GameState currentGame, out MessageStore messageStore); await handler.AddTeamAsync(teamName); ByCommandTeamManager teamManager = currentGame.TeamManager as ByCommandTeamManager; Assert.IsTrue( teamManager.TryAddPlayerToTeam(playerId, playerName, teamName), "Couldn't add the player to the team"); Assert.IsTrue(await currentGame.AddPlayer(playerId, playerName), "Couldn't buzz in for the player"); currentGame.ScorePlayer(10); Mock <IGuildUser> playerUser = new Mock <IGuildUser>(); playerUser.Setup(user => user.Id).Returns(playerId); await handler.RemovePlayerAsync(playerUser.Object); bool hasPlayers = (await teamManager.GetKnownPlayers()).Any(); Assert.IsFalse(hasPlayers, "Player should've been removed"); messageStore.Clear(); await handler.RemoveTeamAsync(teamName); IReadOnlyDictionary <string, string> teamIdToNames = await currentGame.TeamManager.GetTeamIdToNames(); Assert.AreEqual(1, teamIdToNames.Count, "Unexpected number of teams after removal"); Assert.AreEqual(1, messageStore.ChannelMessages.Count, "Unexpected number of messages"); string message = messageStore.ChannelMessages.First(); Assert.AreEqual( @$ "Unable to remove the team. **{playerName}** has already been scored, so the player cannot be removed without affecting the score.", message, "Unexpected message"); }
public async Task CannotRemoveNonexistentPlayerFromTeam() { ByCommandTeamManager teamManager = new ByCommandTeamManager(); Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add team"); Assert.IsTrue( teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam), "Couldn't add player to team"); Assert.IsFalse(teamManager.TryRemovePlayerFromTeam(SecondPlayerId), "Second player shouldn't be removable"); IEnumerable <PlayerTeamPair> pairs = await teamManager.GetKnownPlayers(); Assert.AreEqual(1, pairs.Count(), "Unexpected number of players"); PlayerTeamPair pair = pairs.First(); Assert.AreEqual(FirstPlayerId, pair.PlayerId, "Player should be known"); Assert.AreEqual(FirstTeam, pair.TeamId, "Player should be on the first team"); Assert.AreEqual(FirstPlayerName, pair.PlayerDisplayName, "Player should have a name"); }
public async Task CannotRemoveTeamWithPlayerOnIt() { const string playerName = "Alice"; ByCommandTeamManager teamManager = new ByCommandTeamManager(); Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add the team"); Assert.IsTrue(teamManager.TryAddPlayerToTeam(1, playerName, FirstTeam), "Couldn't add the player"); Assert.IsFalse( teamManager.TryRemoveTeam(FirstTeam, out string message), "We shouldn't have been able to remove the team"); Assert.IsNotNull(message, "We should have an error message"); string playersTeamName = await teamManager.GetTeamIdOrNull(1); Assert.AreEqual(FirstTeam, playersTeamName, "Player should still be on the team"); string teamNameFromId = await teamManager.GetTeamNameOrNull(FirstTeam); Assert.IsNotNull(teamNameFromId, "Team should still be there"); }
public async Task CanAddTeam() { const string teamName = "My Team"; this.CreateHandler( out ReaderCommandHandler handler, out GameState currentGame, out MessageStore messageStore); ISelfManagedTeamManager teamManager = new ByCommandTeamManager(); currentGame.TeamManager = teamManager; await handler.AddTeamAsync(teamName); IReadOnlyDictionary <string, string> teamIdToName = await teamManager.GetTeamIdToNames(); Assert.IsTrue(teamIdToName.ContainsKey(teamName), "Team name wasn't added"); Assert.AreEqual(1, messageStore.ChannelMessages.Count, "Unexpected number of channel messages."); string message = messageStore.ChannelMessages.First(); Assert.AreEqual($@"Added team ""{teamName}"".", message, $"Unexpected message"); }
public async Task TryCreateScoresheetPastPlayerLimitFails() { ExcelFileScoresheetGenerator generator = new ExcelFileScoresheetGenerator(); ByCommandTeamManager teamManager = new ByCommandTeamManager(); GameState game = new GameState() { Format = Format.TossupShootout, ReaderId = 1, TeamManager = teamManager }; Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add the first team"); Assert.IsTrue(teamManager.TryAddTeam(SecondTeam, out _), "Couldn't add the second team"); for (int i = 0; i < ExcelFileScoresheetGenerator.PlayersPerTeamLimit; i++) { Assert.IsTrue( teamManager.TryAddPlayerToTeam((ulong)i + 2, $"Player{i}", FirstTeam), $"Couldn't add player #{i} to the first team"); Assert.IsTrue( teamManager.TryAddPlayerToTeam((ulong)i + 200, $"Player{i}", SecondTeam), $"Couldn't add player #{i} to the second team"); } IResult <Stream> result = await generator.TryCreateScoresheet(game, "Reader X", "Room A"); Assert.IsTrue(result.Success, $"Creation should've succeeded at the limit."); Assert.IsTrue( teamManager.TryAddPlayerToTeam(1111, "OverLimit", FirstTeam), "Adding the player over the limit should've succeeded"); result = await generator.TryCreateScoresheet(game, "Reader X", "Room A"); Assert.IsFalse(result.Success, $"Creation should've failed after the limit."); Assert.AreEqual( $"Export only currently works if there are at most {ExcelFileScoresheetGenerator.PlayersPerTeamLimit} players on a team.", result.ErrorMessage, "Unexpected error message"); }
public async Task AddingPlayerToRemovedTeam() { ByCommandTeamManager teamManager = new ByCommandTeamManager(); Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add team"); IReadOnlyDictionary <string, string> teamIdToName = await teamManager.GetTeamIdToNames(); Assert.IsTrue(teamIdToName.ContainsKey(FirstTeam), "Couldn't find team after adding it"); Assert.IsTrue( teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam), "Couldn't add player to team"); IEnumerable <PlayerTeamPair> pairs = await teamManager.GetKnownPlayers(); Assert.AreEqual(1, pairs.Count(), "Unexpected number of players"); PlayerTeamPair pair = pairs.First(); Assert.AreEqual(FirstPlayerId, pair.PlayerId, "Player should be known"); Assert.AreEqual(FirstTeam, pair.TeamId, "Player should be on the first team"); Assert.AreEqual(FirstPlayerName, pair.PlayerDisplayName, "Player should have a name"); }
public async Task AddRemoveAndReaddTeam() { ByCommandTeamManager teamManager = new ByCommandTeamManager(); Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add team"); IReadOnlyDictionary <string, string> teamIdToName = await teamManager.GetTeamIdToNames(); Assert.IsTrue(teamIdToName.TryGetValue(FirstTeam, out string teamName), "Couldn't find team after adding it"); Assert.AreEqual(FirstTeam, teamName, "Unexpected team name"); Assert.IsTrue(teamManager.TryRemoveTeam(FirstTeam, out _), "Couldn't remove team"); teamIdToName = await teamManager.GetTeamIdToNames(); Assert.AreEqual(0, teamIdToName.Count, "Remove didn't remove the team"); Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Re-adding a team should succeed"); teamIdToName = await teamManager.GetTeamIdToNames(); Assert.IsTrue( teamIdToName.TryGetValue(FirstTeam, out teamName), "Couldn't find team after re-adding it"); Assert.AreEqual(FirstTeam, teamName, "Unexpected team name after re-addition"); }
public async Task TryCreateScoresheetWithoutTeamsFails() { ExcelFileScoresheetGenerator generator = new ExcelFileScoresheetGenerator(); ByCommandTeamManager teamManager = new ByCommandTeamManager(); GameState game = new GameState() { Format = Format.CreateTossupBonusesShootout(false), ReaderId = 1, TeamManager = teamManager }; await game.AddPlayer(2, "Alice"); game.ScorePlayer(10); IResult <Stream> result = await generator.TryCreateScoresheet(game, "Reader X", "Room A"); Assert.IsFalse(result.Success, $"Creation succeeded when it should've failed."); Assert.AreEqual( "Export only works if there are 1 or 2 teams in the game.", result.ErrorMessage, "Unexpected error message"); }
public async Task TryCreateScoresheetPastPhaseLimitFails() { ExcelFileScoresheetGenerator generator = new ExcelFileScoresheetGenerator(); ByCommandTeamManager teamManager = new ByCommandTeamManager(); GameState game = new GameState() { Format = Format.TossupShootout, ReaderId = 1, TeamManager = teamManager }; Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add the team"); Assert.IsTrue(teamManager.TryAddPlayerToTeam(2, "Alice", FirstTeam), "Couldn't add player to team"); for (int i = 0; i < ExcelFileScoresheetGenerator.PhasesLimit; i++) { await game.AddPlayer(2, "Alice"); game.ScorePlayer(10); } IResult <Stream> result = await generator.TryCreateScoresheet(game, "Reader X", "Room A"); Assert.IsTrue(result.Success, $"Creation should've succeeded at the limit."); await game.AddPlayer(2, "Alice"); game.ScorePlayer(10); result = await generator.TryCreateScoresheet(game, "Reader X", "Room A"); Assert.IsFalse(result.Success, $"Creation should've failed after the limit."); Assert.AreEqual( $"Export only currently works if there are at most {ExcelFileScoresheetGenerator.PhasesLimit} tosusps answered in a game.", result.ErrorMessage, "Unexpected error message"); }
public async Task TryCreateScoresheetSucceeds() { const string readerName = "The Reader"; const string roomName = "Room A"; // Do something simple, then read the spreadsheet and verify some fields ExcelFileScoresheetGenerator generator = new ExcelFileScoresheetGenerator(); ByCommandTeamManager teamManager = new ByCommandTeamManager(); GameState game = new GameState() { Format = Format.TossupBonusesShootout, ReaderId = 1, TeamManager = teamManager }; teamManager.TryAddTeam(FirstTeam, out _); teamManager.TryAddTeam(SecondTeam, out _); teamManager.TryAddPlayerToTeam(2, "Alice", FirstTeam); teamManager.TryAddPlayerToTeam(3, "Alan", FirstTeam); teamManager.TryAddPlayerToTeam(4, "Bob", SecondTeam); await game.AddPlayer(2, "Alice"); game.ScorePlayer(15); game.TryScoreBonus("10/0/10"); await game.AddPlayer(3, "Alan"); game.ScorePlayer(-5); await game.AddPlayer(4, "Bob"); game.ScorePlayer(10); game.TryScoreBonus("0/10/0"); IResult <Stream> result = await generator.TryCreateScoresheet(game, readerName, roomName); Assert.IsTrue(result.Success, $"Failed: {(result.Success ? "" : result.ErrorMessage)}"); using (IXLWorkbook workbook = new XLWorkbook(result.Value)) { Assert.AreEqual(1, workbook.Worksheets.Count, "Unexpected number of worksheets"); IXLWorksheet worksheet = workbook.Worksheet(1); Assert.AreEqual(roomName, worksheet.Cell("B2").Value.ToString(), "Unexpected reader"); Assert.AreEqual(readerName, worksheet.Cell("B3").Value.ToString(), "Unexpected reader"); Assert.AreEqual(readerName, worksheet.Cell("L3").Value.ToString(), "Unexpected scorekeeper"); Assert.AreEqual(FirstTeam, worksheet.Cell("B6").Value.ToString(), "Unexpected first team name"); Assert.AreEqual(SecondTeam, worksheet.Cell("N6").Value.ToString(), "Unexpected second team name"); Assert.AreEqual( "15", worksheet.Cell("B8").Value.ToString(), "Alice's power was not recorded"); Assert.AreEqual("10", worksheet.Cell("H8").Value.ToString(), "1st bonus part in 1st bonus is wrong"); Assert.AreEqual("0", worksheet.Cell("I8").Value.ToString(), "2nd bonus part in 1st bonus is wrong"); Assert.AreEqual("10", worksheet.Cell("J8").Value.ToString(), "3rd bonus part in 1st bonus is wrong"); Assert.AreEqual( "35", worksheet.Cell("K8").Value.ToString(), $"{FirstTeam}'s total for the 1st phase is wrong"); Assert.AreEqual( "-5", worksheet.Cell("C9").Value.ToString(), "Alan's neg was not recorded"); Assert.AreEqual( "10", worksheet.Cell("N9").Value.ToString(), "Bob's get was not recorded"); Assert.AreEqual("0", worksheet.Cell("T9").Value.ToString(), "1st bonus part in 2nd bonus is wrong"); Assert.AreEqual("10", worksheet.Cell("U9").Value.ToString(), "2nd bonus part in 2nd bonus is wrong"); Assert.AreEqual("0", worksheet.Cell("V9").Value.ToString(), "3rd bonus part in 2nd bonus is wrong"); Assert.AreEqual( "20", worksheet.Cell("W9").Value.ToString(), $"{SecondTeam}'s total for the 1st phase is wrong"); Assert.AreEqual("-5", worksheet.Cell("K9").Value.ToString(), $"{FirstTeam}'s's total for the phase is wrong"); } }