public void ItReturnsTheCurrentUsersPlayerQuickStatsViewModel()
        {
            var expectedPlayerQuickSummary = new PlayerQuickStats
            {
                PlayerId = 1,
                TotalGamesPlayed = 4,
                TotalGamesWon = 3,
                NemePointsSummary = new NemePointsSummary(1, 3, 5),
                LastGamingGroupGame = new PlayedGameQuickStats
                {
                    BoardGameGeekUri = new Uri("http://a.com"),
                    DatePlayed = new DateTime(),
                    GameDefinitionId = 10,
                    GameDefinitionName = "some game definition name",
                    PlayedGameId = 12,
                    ThumbnailImageUrl = "some url",
                    WinnerType = WinnerTypes.PlayerWin,
                    WinningPlayerId = 13,
                    WinningPlayerName = "some winning player name"
                }
            };

            autoMocker.Get<IPlayerRetriever>()
                .Expect(mock => mock.GetPlayerQuickStatsForUser(currentUser.Id, currentUser.CurrentGamingGroupId))
                .Return(expectedPlayerQuickSummary);

            var result = autoMocker.ClassUnderTest.CurrentPlayerQuickStats(currentUser) as ViewResult;

            Assert.That(result, Is.Not.Null);
            var actualModel = result.Model as PlayerQuickStatsViewModel;
            Assert.That(actualModel, Is.Not.Null);
            Assert.That(actualModel.PlayerId, Is.EqualTo(expectedPlayerQuickSummary.PlayerId));
            var expectedNemePointsSummary = new NemePointsSummaryViewModel(
                expectedPlayerQuickSummary.NemePointsSummary.BaseNemePoints,
                expectedPlayerQuickSummary.NemePointsSummary.GameDurationBonusNemePoints,
                expectedPlayerQuickSummary.NemePointsSummary.WeightBonusNemePoints);
            Assert.That(actualModel.NemePointsSummary, Is.EqualTo(expectedNemePointsSummary));
            Assert.That(actualModel.TotalGamesWon, Is.EqualTo(expectedPlayerQuickSummary.TotalGamesWon));
            Assert.That(actualModel.TotalGamesPlayed, Is.EqualTo(expectedPlayerQuickSummary.TotalGamesPlayed));
            Assert.That(actualModel.LastGamingGroupGame, Is.Not.Null);
            var lastGamingGroupGameViewModel = actualModel.LastGamingGroupGame;
            var playedGameQuickStats = expectedPlayerQuickSummary.LastGamingGroupGame;
            Assert.That(lastGamingGroupGameViewModel.BoardGameGeekUri, Is.EqualTo(playedGameQuickStats.BoardGameGeekUri));
            Assert.That(lastGamingGroupGameViewModel.DatePlayed, Is.EqualTo(playedGameQuickStats.DatePlayed));
            Assert.That(lastGamingGroupGameViewModel.GameDefinitionName, Is.EqualTo(playedGameQuickStats.GameDefinitionName));
            Assert.That(lastGamingGroupGameViewModel.PlayedGameId, Is.EqualTo(playedGameQuickStats.PlayedGameId));
            Assert.That(lastGamingGroupGameViewModel.ThumbnailImageUrl, Is.EqualTo(playedGameQuickStats.ThumbnailImageUrl));
            Assert.That(lastGamingGroupGameViewModel.WinnerType, Is.EqualTo(playedGameQuickStats.WinnerType));
            Assert.That(lastGamingGroupGameViewModel.WinningPlayerId, Is.EqualTo(playedGameQuickStats.WinningPlayerId));
            Assert.That(lastGamingGroupGameViewModel.WinningPlayerName, Is.EqualTo(playedGameQuickStats.WinningPlayerName));
        }
예제 #2
0
        public virtual PlayerQuickStats GetPlayerQuickStatsForUser(string applicationUserId, int gamingGroupId)
        {
            var playerIdForCurrentUser = GetPlayerIdForCurrentUser(applicationUserId, gamingGroupId);

            var returnValue = new PlayerQuickStats();

            if (playerIdForCurrentUser != 0)
            {
                returnValue.PlayerId = playerIdForCurrentUser;
                returnValue.NemePointsSummary = GetNemePointsSummary(playerIdForCurrentUser);

                var gameDefinitionTotals = GetGameDefinitionTotals(playerIdForCurrentUser);
                var topLevelTotals = GetTopLevelTotals(gameDefinitionTotals);
                returnValue.TotalGamesPlayed = topLevelTotals.TotalGames;
                returnValue.TotalGamesWon = topLevelTotals.TotalGamesWon;

                var lastPlayedGameForGamingGroupList = playedGameRetriever.GetRecentGames(1, gamingGroupId);
                if (lastPlayedGameForGamingGroupList.Count() == 1)
                {
                    var lastGame = lastPlayedGameForGamingGroupList[0];
                    returnValue.LastGamingGroupGame = new PlayedGameQuickStats
                    {
                        DatePlayed = lastGame.DatePlayed,
                        GameDefinitionName = lastGame.GameDefinition.Name,
                        GameDefinitionId = lastGame.GameDefinitionId,
                        PlayedGameId = lastGame.Id,
                        WinnerType = lastGame.WinnerType
                    };

                    if (lastGame.WinningPlayer != null)
                    {
                        returnValue.LastGamingGroupGame.WinningPlayerId = lastGame.WinningPlayer.Id;
                        returnValue.LastGamingGroupGame.WinningPlayerName = lastGame.WinningPlayer.Name;
                    }

                    var bggGameDefinition = lastGame.GameDefinition.BoardGameGeekGameDefinition;

                    if (bggGameDefinition != null)
                    {
                        returnValue.LastGamingGroupGame.BoardGameGeekUri = BoardGameGeekUriBuilder.BuildBoardGameGeekGameUri(bggGameDefinition.Id);
                        returnValue.LastGamingGroupGame.ThumbnailImageUrl = bggGameDefinition.Thumbnail;
                    }
                }
            }

            return returnValue;
        }