public void ItGetsTheTotalPoints() { using (IDataContext dataContext = new NemeStatsDataContext()) { IPlayerRepository playerRepository = new EntityFrameworkPlayerRepository(dataContext); IPlayedGameRetriever playedGameRetriever = new PlayedGameRetriever(dataContext); IPlayerRetriever playerRetriever = new PlayerRetriever(dataContext, playerRepository, playedGameRetriever); PlayerStatistics playerStatistics = playerRetriever.GetPlayerStatistics(testPlayer1.Id); int totalBasePoints = 0; int totalGameDurationPoints = 0; int totalWeightBonusPoints = 0; foreach(PlayedGame playedGame in testPlayedGames) { if(playedGame.PlayerGameResults.Any(result => result.PlayerId == testPlayer1.Id)) { var playerGameResult = playedGame.PlayerGameResults.First(result => result.PlayerId == testPlayer1.Id); totalBasePoints += playerGameResult.NemeStatsPointsAwarded; totalGameDurationPoints += playerGameResult.GameDurationBonusPoints; totalWeightBonusPoints += playerGameResult.GameWeightBonusPoints; } } Assert.AreEqual(totalBasePoints, playerStatistics.NemePointsSummary.BaseNemePoints); Assert.AreEqual(totalGameDurationPoints, playerStatistics.NemePointsSummary.GameDurationBonusNemePoints); Assert.AreEqual(totalWeightBonusPoints, playerStatistics.NemePointsSummary.WeightBonusNemePoints); } }
public void ItGetsTheGamesPlayedMetrics() { using (IDataContext dataContext = new NemeStatsDataContext()) { IPlayerRepository playerRepository = new EntityFrameworkPlayerRepository(dataContext); IPlayedGameRetriever playedGameRetriever = new PlayedGameRetriever(dataContext); IPlayerRetriever playerRetriever = new PlayerRetriever(dataContext, playerRepository, playedGameRetriever); PlayerStatistics playerStatistics = playerRetriever.GetPlayerStatistics(testPlayer1.Id); int totalGamesForPlayer1 = testPlayedGames .Count(playedGame => playedGame.PlayerGameResults .Any(playerGameResult => playerGameResult.PlayerId == testPlayer1.Id)); Assert.That(playerStatistics.TotalGames, Is.EqualTo(totalGamesForPlayer1)); int totalWinsForPlayer1 = testPlayedGames .Count(playedGame => playedGame.PlayerGameResults .Any(playerGameResult => playerGameResult.PlayerId == testPlayer1.Id && playerGameResult.GameRank == 1)); Assert.That(playerStatistics.TotalGamesWon, Is.EqualTo(totalWinsForPlayer1)); int totalLossesForPlayer1 = testPlayedGames .Count(playedGame => playedGame.PlayerGameResults .Any(playerGameResult => playerGameResult.PlayerId == testPlayer1.Id && playerGameResult.GameRank != 1)); Assert.That(playerStatistics.TotalGamesLost, Is.EqualTo(totalLossesForPlayer1)); int winPercentageForPlayer1 = (int)((decimal)totalWinsForPlayer1 / (totalGamesForPlayer1) * 100); Assert.That(playerStatistics.WinPercentage, Is.EqualTo(winPercentageForPlayer1)); } }
public void ItReturnsZeroesWhenThereAreNoPlayedGames() { using (IDataContext dataContext = new NemeStatsDataContext()) { IPlayedGameRetriever playedGameRetriever = new PlayedGameRetriever(dataContext); var playerRetriever = new PlayerRetriever(dataContext, new EntityFrameworkPlayerRepository(dataContext), playedGameRetriever); var statistics = playerRetriever.GetPlayerStatistics(testPlayerWithNoPlayedGames.Id); Assert.That(statistics.TotalGames, Is.EqualTo(0)); Assert.That(statistics.TotalGamesLost, Is.EqualTo(0)); Assert.That(statistics.TotalGamesWon, Is.EqualTo(0)); Assert.That(statistics.NemePointsSummary, Is.EqualTo(new NemePointsSummary(0, 0, 0))); Assert.That(statistics.WinPercentage, Is.EqualTo(0)); Assert.That(statistics.AveragePlayersPerGame, Is.EqualTo(0)); Assert.That(statistics.GameDefinitionTotals.SummariesOfGameDefinitionTotals.Count, Is.EqualTo(0)); } }
public void ItReturnsTheCorrectStatisticsForAnUndefeatedPlayer() { using (IDataContext dataContext = new NemeStatsDataContext()) { IPlayedGameRetriever playedGameRetriever = new PlayedGameRetriever(dataContext); var playerRetriever = new PlayerRetriever(dataContext, new EntityFrameworkPlayerRepository(dataContext), playedGameRetriever); var statistics = playerRetriever.GetPlayerStatistics(testPlayer9UndefeatedWith5Games.Id); Assert.That(statistics.TotalGames, Is.EqualTo(5)); Assert.That(statistics.TotalGamesLost, Is.EqualTo(0)); Assert.That(statistics.TotalGamesWon, Is.EqualTo(5)); Assert.That(statistics.WinPercentage, Is.EqualTo(100)); var summariesOfGameDefinitionTotals = statistics.GameDefinitionTotals.SummariesOfGameDefinitionTotals; Assert.That(summariesOfGameDefinitionTotals.Count, Is.EqualTo(1)); var gameDefinitionTotal = summariesOfGameDefinitionTotals[0]; Assert.That(gameDefinitionTotal.GameDefinitionId, Is.EqualTo(anotherTestGameDefinitionWithOtherGamingGroupId.Id)); } }
public void ItGetsTheAveragePlayersPerGame() { using (IDataContext dataContext = new NemeStatsDataContext()) { IPlayerRepository playerRepository = new EntityFrameworkPlayerRepository(dataContext); IPlayedGameRetriever playedGameRetriever = new PlayedGameRetriever(dataContext); IPlayerRetriever playerRetriever = new PlayerRetriever(dataContext, playerRepository, playedGameRetriever); PlayerStatistics playerStatistics = playerRetriever.GetPlayerStatistics(testPlayer1.Id); float averagePlayersPerGame = (float)testPlayedGames.Where(game => game.PlayerGameResults.Any(result => result.PlayerId == testPlayer1.Id)) .Average(game => game.NumberOfPlayers); Assert.AreEqual(averagePlayersPerGame, playerStatistics.AveragePlayersPerGame); } }