public GameResultViewModel Build(PlayerGameResult playerGameResult, bool showPointsScored = false)
        {
            Validate(playerGameResult);

            GameResultViewModel result = new GameResultViewModel
            {
                PlayerId = playerGameResult.PlayerId,
                PlayerName = PlayerNameBuilder.BuildPlayerName(playerGameResult.Player.Name, playerGameResult.Player.Active),
                PointsScored = playerGameResult.PointsScored,
                GameRank = playerGameResult.GameRank,
                NemePointsSummary = new NemePointsSummaryViewModel(playerGameResult.NemeStatsPointsAwarded, playerGameResult.GameDurationBonusPoints, playerGameResult.GameWeightBonusPoints),
                GameDefinitionId = playerGameResult.PlayedGame.GameDefinition.Id,
                GameDefinitionName = playerGameResult.PlayedGame.GameDefinition.Name,
                PlayedGameId = playerGameResult.PlayedGameId,
                DatePlayed = playerGameResult.PlayedGame.DatePlayed,
                BoardGameGeekUri = BoardGameGeekUriBuilder.BuildBoardGameGeekGameUri(playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinitionId),
                WinnerType = playerGameResult.PlayedGame.WinnerType,
                ShowPointsScored = showPointsScored
            };
            if(playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinition != null)
            {
                result.ThumbnailImageUrl = playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinition.Thumbnail;
                result.ImageUrl = playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinition.Image;
            }

            return result;
        }
Пример #2
0
        public void SetUp()
        {
            builder = new GameResultViewModelBuilder();
            GameDefinition gameDefinition = new GameDefinition()
            {
                Id = 15131,
                Name = "Yodle-masters 2014"
            };
            PlayedGame playedGame = new PlayedGame()
            {
                GameDefinition = gameDefinition,
                DatePlayed = new DateTime(2014, 09, 15),
                WinnerType = WinnerTypes.TeamWin
            };
            playerGameResult = new PlayerGameResult()
            {
                GameRank = 1,
                NemeStatsPointsAwarded = 2,
                Id = 151,
                PlayerId = 15135,
                Player = new Player()
                {
                    Name = "Test Player",
                    Active = false
                },
                PlayedGameId = 1432,
                PlayedGame = playedGame
            };

            playerGameResultDetails = builder.Build(playerGameResult);
        }
Пример #3
0
        public static MvcHtmlString GameResults(this HtmlHelper htmlHelper, GameResultViewModel playerGameResultDetails, WinnerTypes? winnerType)
        {
            Validate(playerGameResultDetails);

            string cssPlace;
            string gameRankText;

            if (winnerType == WinnerTypes.TeamWin)
            {
                cssPlace = CSS_CLASS_TEAM_WIN;
                gameRankText = PLACE_TEAM_WIN;
            }
            else if (winnerType == WinnerTypes.TeamLoss)
            {
                cssPlace = CSS_CLASS_TEAM_LOSS;
                gameRankText = PLACE_EVERYONE_LOST;
            }
            else
            {
                switch (playerGameResultDetails.GameRank)
                {
                    case 1:
                        cssPlace = CSS_CLASS_FIRST_PLACE;
                        gameRankText = PLACE_FIRST;
                        break;
                    case 2:
                        cssPlace = CSS_CLASS_SECOND_PLACE;
                        gameRankText = PLACE_SECOND;
                        break;
                    case 3:
                        cssPlace = CSS_CLASS_THIRD_PLACE;
                        gameRankText = PLACE_THIRD;
                        break;
                    case 4:
                        cssPlace = CSS_CLASS_FOURTH_PLACE;
                        gameRankText = PLACE_FOURTH;
                        break;
                    default:
                        cssPlace = CSS_CLASS_LOSER_PLACE;
                        gameRankText = PLACE_BIG_LOSER;
                        break;
                }
            }


            string nemeStatsPointsComponent = string.Format(HTML_NEME_POINTS_TEMPLATE, playerGameResultDetails.NemePointsSummary.TotalNemePoints, htmlHelper.NemePointsIco(showTooltip: true, tooltip: NEMEPOINTICO_TOOLTIP, tooltipPosition: NEMEPOINTSICO_TOOLTIP_POSITION));
            return MvcHtmlString.Create(string.Format(HTML_TEMPLATE,
                CSS_CLASS_GAME_RANK,
                cssPlace,
                gameRankText,
                nemeStatsPointsComponent));
        }
Пример #4
0
        public void ItRendersTheGameRankInASpanWithTheGameRankClass()
        {
            HtmlHelper helper = new HtmlHelper(new ViewContext(), new ViewPage());
            GameResultViewModel playerGameResultDetails = new GameResultViewModel()
            {
                GameRank = 1151,
                NemePointsSummary = new NemePointsSummaryViewModel(0, 0, 0)
            };

            XElement result = helper.GameResults(playerGameResultDetails, WinnerTypes.PlayerWin).ToXElement();

            Assert.AreEqual("span", result.Name.ToString());
            Assert.True(result.FirstAttribute.ToString().Contains("class=\"" + PlayedGameHelper.CSS_CLASS_GAME_RANK));
        }
Пример #5
0
        private void TestRenderingForGivenRank(int gameRank, WinnerTypes winnerType, string expectedCssClass, string expectedRankText)
        {
            HtmlHelper helper = new HtmlHelper(new ViewContext(), new ViewPage());
            GameResultViewModel playerGameResultDetails = new GameResultViewModel()
            {
                GameRank = gameRank,
                NemePointsSummary = new NemePointsSummaryViewModel(0, 0, 0)
            };

            XElement result = helper.GameResults(playerGameResultDetails, winnerType).ToXElement();

            string firstAttribute = result.FirstAttribute.ToString();
            StringAssert.Contains("class=\"", firstAttribute);
            StringAssert.Contains(expectedCssClass, firstAttribute);
            string firstNodeText = result.FirstNode.ToString();
            StringAssert.StartsWith(expectedRankText, firstNodeText);
        }
Пример #6
0
        public void ItRendersNemeStatsPoints()
        {
            HtmlHelper helper = new HtmlHelper(new ViewContext(), new ViewPage());
            GameResultViewModel playerGameResultDetails = new GameResultViewModel()
            {
                NemePointsSummary = new NemePointsSummaryViewModel(1, 2, 3)
            };

            XElement result = helper.GameResults(playerGameResultDetails, WinnerTypes.PlayerWin).ToXElement();

            string firstNodeText = result.FirstNode.ToString();

            Assert.True(firstNodeText.Contains(playerGameResultDetails.NemePointsSummary.TotalNemePoints.ToString()));
        }
Пример #7
0
 private static void ValidatePlayerGameResultsDetailsAreNotNull(GameResultViewModel playerGameResultDetails)
 {
     if (playerGameResultDetails == null)
     {
         throw new ArgumentNullException("playerGameResultDetails");
     }
 }
Пример #8
0
 private static void Validate(GameResultViewModel playerGameResultDetails)
 {
     ValidatePlayerGameResultsDetailsAreNotNull(playerGameResultDetails);
 }