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 ItOrdersPlayerGameResultsByTheDatePlayedDescending() { using (NemeStatsDbContext dbContext = new NemeStatsDbContext()) { using (IDataContext dataContext = new NemeStatsDataContext(dbContext, securedEntityValidatorFactory)) { int numberOfGamesToRetrieve = 3; INemesisHistoryRetriever nemesisHistoryRetriever = new NemesisHistoryRetriever(dataContext); IPlayerRepository playerRepository = new EntityFrameworkPlayerRepository(dataContext); IPlayedGameRetriever playedGameRetriever = new PlayedGameRetriever(dataContext); IPlayerRetriever playerRetriever = new PlayerRetriever(dataContext, playerRepository, playedGameRetriever); PlayerDetails playerDetails = playerRetriever.GetPlayerDetails(testPlayer1.Id, numberOfGamesToRetrieve); long lastTicks = long.MaxValue;; Assert.IsTrue(playerDetails.PlayerGameResults.Count == numberOfGamesToRetrieve); foreach (PlayerGameResult result in playerDetails.PlayerGameResults) { Assert.GreaterOrEqual(lastTicks, result.PlayedGame.DatePlayed.Ticks); lastTicks = result.PlayedGame.DatePlayed.Ticks; } } } }
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 LocalFixtureSetUp() { using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { PlayedGameRetriever retriever = new PlayedGameRetriever(dataContext); publicGameSummaryResults = retriever.GetRecentPublicGames(NUMBER_OF_GAMES_TO_RETRIEVE); } }
public void ItOnlyReturnsGamesForTheCurrentUsersGamingGroup() { using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { PlayedGameRetriever retriever = new PlayedGameRetriever(dataContext); List <PlayedGame> playedGames = retriever.GetRecentGames(20, testUserWithOtherGamingGroup.CurrentGamingGroupId); Assert.True(playedGames.All(game => game.GamingGroupId == testUserWithOtherGamingGroup.CurrentGamingGroupId)); } }
public void ItReturnsOnlyTwoGamesIfTwoGamesAreSpecified() { using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { PlayedGameRetriever retriever = new PlayedGameRetriever(dataContext); int two = 2; List <PlayedGame> playedGames = retriever.GetRecentGames(two, testUserWithDefaultGamingGroup.CurrentGamingGroupId); Assert.AreEqual(two, playedGames.Count()); } }
public void ItReturnsOnlyOneGameIfOneGameIsSpecified() { using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { PlayedGameRetriever retriever = new PlayedGameRetriever(dataContext); int one = 1; List <PlayedGame> playedGames = retriever.GetRecentGames(one, testUserWithDefaultGamingGroup.CurrentGamingGroupId); Assert.AreEqual(one, playedGames.Count()); } }
public override void FixtureSetUp() { base.FixtureSetUp(); dataContext = new NemeStatsDataContext(); IPlayerRepository playerRepository = new EntityFrameworkPlayerRepository(dataContext); IPlayedGameRetriever playedGameRetriever = new PlayedGameRetriever(dataContext); playerRetriever = new PlayerRetriever(dataContext, playerRepository, playedGameRetriever); player1Details = playerRetriever.GetPlayerDetails(testPlayer1.Id, 0); player5Details = playerRetriever.GetPlayerDetails(testPlayer5.Id, 0); }
public void LocalFixtureSetUp() { using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { var retriever = new PlayedGameRetriever(dataContext); var recentlyPlayedGamesFilter = new RecentlyPlayedGamesFilter { NumberOfGamesToRetrieve = NUMBER_OF_GAMES_TO_RETRIEVE }; publicGameSummaryResults = retriever.GetRecentPublicGames(recentlyPlayedGamesFilter); } }
public void ItThrowsAnEntityDoesNotExistExceptionIfTheIdIsInvalid() { int invalidId = -1; var expectedException = new EntityDoesNotExistException(typeof(PlayedGame), invalidId); using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { PlayedGameRetriever retriever = new PlayedGameRetriever(dataContext); Exception actualException = Assert.Throws <EntityDoesNotExistException>(() => retriever.GetPlayedGameDetails(invalidId)); Assert.That(expectedException.Message, Is.EqualTo(actualException.Message)); } }
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); } }
public void ItSetsPlayerStatistics() { using (NemeStatsDbContext dbContext = new NemeStatsDbContext()) { using (IDataContext dataContext = new NemeStatsDataContext(dbContext, securedEntityValidatorFactory)) { INemesisHistoryRetriever nemesisHistoryRetriever = new NemesisHistoryRetriever(dataContext); IPlayerRepository playerRepository = new EntityFrameworkPlayerRepository(dataContext); IPlayedGameRetriever playedGameRetriever = new PlayedGameRetriever(dataContext); IPlayerRetriever playerRetriever = new PlayerRetriever(dataContext, playerRepository, playedGameRetriever); PlayerDetails playerDetails = playerRetriever.GetPlayerDetails(testPlayer1.Id, 1); Assert.NotNull(playerDetails.PlayerStats); } } }
public void ItEagerlyFetchesPlayerGameResults() { using (NemeStatsDbContext dbContext = new NemeStatsDbContext()) { dbContext.Configuration.LazyLoadingEnabled = false; dbContext.Configuration.ProxyCreationEnabled = false; using (NemeStatsDataContext dataContext = new NemeStatsDataContext(dbContext, securedEntityValidatorFactory)) { PlayedGameRetriever retriever = new PlayedGameRetriever(dataContext); List <PlayedGame> playedGames = retriever.GetRecentGames(1, testUserWithDefaultGamingGroup.CurrentGamingGroupId); ICollection <PlayerGameResult> playerGameResults = playedGames[0].PlayerGameResults; Assert.NotNull(playerGameResults); } } }
public void ItReturnsGamesInDescendingOrderByDatePlayed() { using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { PlayedGameRetriever retriever = new PlayedGameRetriever(dataContext); int five = 5; List <PlayedGame> playedGames = retriever.GetRecentGames(five, testUserWithDefaultGamingGroup.CurrentGamingGroupId); List <PlayedGame> allPlayedGames = dataContext.GetQueryable <PlayedGame>() .Where(game => game.GamingGroupId == testUserWithDefaultGamingGroup.CurrentGamingGroupId) .ToList() .OrderByDescending(playedGame => playedGame.DatePlayed) .ToList(); for (int i = 0; i < five; i++) { Assert.AreEqual(allPlayedGames[i].Id, playedGames[i].Id); } } }
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 PlayerAchievementToPlayerAchievementViewModelMapper( AchievementToAchievementViewModelMapper achievementToAchievementViewModelMapper, IGameDefinitionRetriever gameDefinitionRetriever, GameDefinitionSummaryToGameDefinitionSummaryListViewModelMapper gameDefinitionSummaryToGameDefinitionSummaryListViewModelMapper, PlayedGameRetriever playedGameRetriever, PlayedGameQuickStatsToPlayedGameQuickStatsViewModelMapper playedGameQuickStatsToPlayedGameQuickStatsViewModelMapper, IPlayerRetriever playerRetriever, PlayerToPlayerListSummaryViewModelMapper playerToPlayerListSummaryViewModelMapper ) { _achievementToAchievementViewModelMapper = achievementToAchievementViewModelMapper; _gameDefinitionRetriever = gameDefinitionRetriever; _gameDefinitionSummaryToGameDefinitionSummaryListViewModelMapper = gameDefinitionSummaryToGameDefinitionSummaryListViewModelMapper; _playedGameRetriever = playedGameRetriever; _playedGameQuickStatsToPlayedGameQuickStatsViewModelMapper = playedGameQuickStatsToPlayedGameQuickStatsViewModelMapper; _playerRetriever = playerRetriever; _playerToPlayerListSummaryViewModelMapper = playerToPlayerListSummaryViewModelMapper; }
public void ItEagerlyFetchesGameDefinitions() { using (NemeStatsDbContext dbContext = new NemeStatsDbContext()) { using (IDataContext dataContext = new NemeStatsDataContext(dbContext, securedEntityValidatorFactory)) { dbContext.Configuration.LazyLoadingEnabled = false; dbContext.Configuration.ProxyCreationEnabled = false; INemesisHistoryRetriever nemesisHistoryRetriever = new NemesisHistoryRetriever(dataContext); IPlayerRepository playerRepository = new EntityFrameworkPlayerRepository(dataContext); IPlayedGameRetriever playedGameRetriever = new PlayedGameRetriever(dataContext); IPlayerRetriever playerRetriever = new PlayerRetriever(dataContext, playerRepository, playedGameRetriever); PlayerDetails testPlayerDetails = playerRetriever.GetPlayerDetails(testPlayer1.Id, 1); Assert.NotNull(testPlayerDetails.PlayerGameResults.First().PlayedGame.GameDefinition); } } }
public void ItOnlyGetsTheSpecifiedNumberOfRecentGames() { using (NemeStatsDbContext dbContext = new NemeStatsDbContext()) { using (IDataContext dataContext = new NemeStatsDataContext(dbContext, securedEntityValidatorFactory)) { int numberOfGamesToRetrieve = 1; INemesisHistoryRetriever nemesisHistoryRetriever = new NemesisHistoryRetriever(dataContext); IPlayerRepository playerRepository = new EntityFrameworkPlayerRepository(dataContext); IPlayedGameRetriever playedGameRetriever = new PlayedGameRetriever(dataContext); IPlayerRetriever playerRetriever = new PlayerRetriever(dataContext, playerRepository, playedGameRetriever); PlayerDetails playerDetails = playerRetriever.GetPlayerDetails(testPlayer1.Id, numberOfGamesToRetrieve); Assert.AreEqual(numberOfGamesToRetrieve, playerDetails.PlayerGameResults.Count); } } }
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 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 totalPoints = 0; foreach (PlayedGame playedGame in testPlayedGames) { if (playedGame.PlayerGameResults.Any(result => result.PlayerId == testPlayer1.Id)) { totalPoints += playedGame.PlayerGameResults.First(result => result.PlayerId == testPlayer1.Id).NemeStatsPointsAwarded; } } Assert.AreEqual(totalPoints, playerStatistics.TotalPoints); } }
public void ItReturnsOrderedPlayerRankDescendingWithinAGivenGame() { using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { PlayedGameRetriever retriever = new PlayedGameRetriever(dataContext); int five = 5; List <PlayedGame> playedGames = retriever.GetRecentGames(five, testUserWithDefaultGamingGroup.CurrentGamingGroupId); int lastRank = -1; foreach (PlayedGame playedGame in playedGames) { foreach (PlayerGameResult playerGameResult in playedGame.PlayerGameResults) { Assert.True(lastRank <= playerGameResult.GameRank); lastRank = playerGameResult.GameRank; } lastRank = -1; } } }
public void SetUp() { _playedGameRetriever = GetInstance <PlayedGameRetriever>(); }