Inheritance: IEditableViewModel, IGamingGroupAssignedViewModel
        public PlayerDetailsViewModel Build(PlayerDetails playerDetails, string urlForMinionBragging, ApplicationUser currentUser = null)
        {
            Validate(playerDetails);

            var playerDetailsViewModel = new PlayerDetailsViewModel
            {
                PlayerId = playerDetails.Id,
                PlayerName = playerDetails.Name,
                PlayerRegistered = playerDetails.ApplicationUserId != null,
                Active = playerDetails.Active,
                GamingGroupName = playerDetails.GamingGroupName,
                GamingGroupId = playerDetails.GamingGroupId,
                TotalGamesPlayed = playerDetails.PlayerStats.TotalGames,
                NemePointsSummary = new NemePointsSummaryViewModel(playerDetails.NemePointsSummary),
                TotalGamesWon = playerDetails.PlayerStats.TotalGamesWon,
                TotalGamesLost = playerDetails.PlayerStats.TotalGamesLost,
                WinPercentage = playerDetails.PlayerStats.WinPercentage,
                TotalChampionedGames = playerDetails.ChampionedGames.Count,
                LongestWinningStreak = playerDetails.LongestWinningStreak,
                PlayerAchievements = playerDetails.Achievements?.Select(pa => _mapperFactory.GetMapper<PlayerAchievement,PlayerAchievementSummaryViewModel>().Map(pa)).OrderByDescending(a=>a.AchievementLevel).ThenByDescending(a=>a.LastUpdatedDate).ToList() ?? new List<PlayerAchievementSummaryViewModel>()
            };

            PopulatePlayerVersusPlayersViewModel(playerDetails, playerDetailsViewModel);

            SetTwitterBraggingUrlIfThePlayerIsTheCurrentlyLoggedInUser(playerDetails, urlForMinionBragging, currentUser, playerDetailsViewModel);

            SetAveragePointsPerGame(playerDetails, playerDetailsViewModel);
            playerDetailsViewModel.AveragePlayersPerGame = playerDetails.PlayerStats.AveragePlayersPerGame;
            SetAveragePointsPerPlayer(playerDetails, playerDetailsViewModel);
            SetUserCanEditFlag(playerDetails, currentUser, playerDetailsViewModel);

            PopulatePlayerGameResults(playerDetails, playerDetailsViewModel);

            PopulateNemesisData(playerDetails.CurrentNemesis, playerDetailsViewModel);

            playerDetailsViewModel.Minions = (from Player player in playerDetails.Minions
                                              select _minionViewModelBuilder.Build(player)).ToList();

            playerDetailsViewModel.PlayerGameSummaries = playerDetails.PlayerGameSummaries.Select(Mapper.Map<PlayerGameSummaryViewModel>).ToList();

            SetChampionedGames(playerDetails, playerDetailsViewModel);

            SetFormerChampionedGames(playerDetails, playerDetailsViewModel);

            return playerDetailsViewModel;
        }
Ejemplo n.º 2
0
        public void ItReturnsThePlayerDetailsViewWhenThePlayerIsFound()
        {
            PlayerDetails playerDetails = new PlayerDetails(){ PlayerGameResults = new List<PlayerGameResult>() };
            autoMocker.Get<IPlayerRetriever>().Expect(playerLogic => playerLogic.GetPlayerDetails(playerId, PlayerController.NUMBER_OF_RECENT_GAMES_TO_RETRIEVE))
                .Repeat.Once()
                .Return(playerDetails);

            PlayerDetailsViewModel playerDetailsViewModel = new PlayerDetailsViewModel()
            {
                PlayerId = playerId,
                PlayerGameResultDetails = new List<GameResultViewModel>()
            };
            autoMocker.Get<IPlayerDetailsViewModelBuilder>().Expect(viewModelBuilder => viewModelBuilder.Build(playerDetails, expectedMinionUrl, currentUser))
                .Repeat
                .Once()
                .Return(playerDetailsViewModel);
            ViewResult viewResult = autoMocker.ClassUnderTest.Details(playerId, currentUser) as ViewResult;

            Assert.AreEqual(MVC.Player.Views.Details, viewResult.ViewName);
        }
Ejemplo n.º 3
0
        public void ItPutsTheRecentGamesMessageOnTheViewbag()
        {
            PlayerDetails playerDetails = new PlayerDetails(){ PlayerGameResults = new List<PlayerGameResult>() };
            autoMocker.Get<IPlayerRetriever>().Expect(playerLogic => playerLogic.GetPlayerDetails(
                playerId, 
                PlayerController.NUMBER_OF_RECENT_GAMES_TO_RETRIEVE))
                .Repeat.Once()
                .Return(playerDetails);

            PlayerDetailsViewModel playerDetailsViewModel = new PlayerDetailsViewModel()
            {
                PlayerId = playerId,
                PlayerGameResultDetails = new List<GameResultViewModel>()
            };
            autoMocker.Get<IPlayerDetailsViewModelBuilder>().Expect(viewModelBuilder => viewModelBuilder.Build(playerDetails, expectedMinionUrl, currentUser))
                .Repeat
                .Once()
                .Return(playerDetailsViewModel);
            string expectedMessage = "expected message";
            autoMocker.Get<IShowingXResultsMessageBuilder>().Expect(mock => mock.BuildMessage(
                PlayerController.NUMBER_OF_RECENT_GAMES_TO_RETRIEVE,
                playerDetailsViewModel.PlayerGameResultDetails.Count))
                    .Return(expectedMessage);

            autoMocker.ClassUnderTest.Details(playerId, currentUser);

            Assert.AreEqual(expectedMessage, autoMocker.ClassUnderTest.ViewBag.RecentGamesMessage);
        }
Ejemplo n.º 4
0
        public void TestFixtureSetUp()
        {
            AutomapperConfiguration.Configure();
            minionViewModelBuilderMock = MockRepository.GenerateMock<IMinionViewModelBuilder>();
            mapperFactory = MockRepository.GenerateStub<IMapperFactory>();

            currentUser = new ApplicationUser()
            {
                CurrentGamingGroupId = gamingGroupId,
                Id = "application user id"
            };

            var gameDefinition1 = new GameDefinition()
            {
                Name = "test game 1",
                Id = gameDefinitionIdThatIsChampionedByCurrentPlayer,
            };
            gameDefinitionThatIsFormerlyChampionedByCurrentPlayer = new GameDefinition
            {
                Name = "formerly championed game",
                Id = gameDefinitionIdThatIsFormerlyChampionedByCurrentPlayer
            };
            gameDefinitionThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer = new GameDefinition
            {
                Name = "currently and formerly championed game",
                Id = gameDefinitionIdThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer
            };
            var playedGame1 = new PlayedGame()
            {
                Id = 1,
                GameDefinition = gameDefinition1
            };

            var playedGame2 = new PlayedGame()
            {
                Id = 2,
                GameDefinitionId = gameDefinitionIdThatIsFormerlyChampionedByCurrentPlayer
            };
            var playerGameResults = new List<PlayerGameResult>()
            {
                new PlayerGameResult(){ PlayedGameId = 12, PlayedGame = playedGame1 },
                new PlayerGameResult(){ PlayedGameId = 13, PlayedGame = playedGame2 }
            };

            normalPlayer = new PlayerVersusPlayerStatistics
            {
                OpposingPlayerName = "Jim",
                OpposingPlayerId = 1,
                OpposingPlayerActive = false,
                NumberOfGamesWonVersusThisPlayer = 10,
                NumberOfGamesLostVersusThisPlayer = 10
            };

            playerWithNoGamesPlayed = new PlayerVersusPlayerStatistics
            {
                OpposingPlayerId = 2
            };

            minionPlayer = new PlayerVersusPlayerStatistics
            {
                OpposingPlayerName = "Minion Player",
                OpposingPlayerId = 5,
                NumberOfGamesWonVersusThisPlayer = 20,
                NumberOfGamesLostVersusThisPlayer = 0
            };

            nemesisPlayer = new PlayerVersusPlayerStatistics
            {
                OpposingPlayerName = "nemesis player",
                OpposingPlayerId = 3,
                NumberOfGamesWonVersusThisPlayer = 0,
                NumberOfGamesLostVersusThisPlayer = 100
            };

            previousNemesisPlayer = new PlayerVersusPlayerStatistics

            {
                OpposingPlayerName = "Previous Nemesis Player",
                OpposingPlayerId = 13,
                NumberOfGamesWonVersusThisPlayer = 0,
                NumberOfGamesLostVersusThisPlayer = 42
            };

            var nemesis = new Nemesis()
            {
                NemesisPlayerId = nemesisPlayer.OpposingPlayerId,
                NumberOfGamesLost = 3,
                LossPercentage = 75,
                NemesisPlayer = new Player()
                {
                    Name = "Ace Nemesis",
                }
            };

            var previousNemesis = new Nemesis()
            {
                NemesisPlayerId = previousNemesisPlayer.OpposingPlayerId,
                NumberOfGamesLost = 5,
                LossPercentage = 66,
                NemesisPlayer = new Player()
                {
                    Name = "Bravo Nemesis",
                }
            };

            playerDetails = new PlayerDetails()
            {
                Id = playerId,
                ApplicationUserId = currentUser.Id,
                Active = true,
                Name = "Skipper",
                LongestWinningStreak = 39,
                PlayerGameResults = playerGameResults,
                PlayerStats = new PlayerStatistics()
                {
                    TotalGames = 5,
                    NemePointsSummary = new NemePointsSummary(1, 3, 5),
                    AveragePlayersPerGame = 3,
                    TotalGamesLost = 1,
                    TotalGamesWon = 4,
                    WinPercentage = 20
                },
                CurrentNemesis = nemesis,
                PreviousNemesis = previousNemesis,
                Minions = new List<Player>
                {
                    new Player
                    {
                        Id = minionPlayer.OpposingPlayerId
                    }
                },
                GamingGroupId = gamingGroupId,
                GamingGroupName = "gaming group name",
                PlayerVersusPlayersStatistics = new List<PlayerVersusPlayerStatistics>
                {
                    normalPlayer,
                    playerWithNoGamesPlayed,
                    nemesisPlayer,
                    previousNemesisPlayer,
                    minionPlayer
                },
                PlayerGameSummaries = new List<PlayerGameSummary>
                {
                    new PlayerGameSummary
                    {
                        GameDefinitionId = gameDefinitionIdThatIsChampionedByCurrentPlayer
                    },
                    new PlayerGameSummary
                    {
                        GameDefinitionId = gameDefinitionIdThatIsFormerlyChampionedByCurrentPlayer
                    },
                    new PlayerGameSummary
                    {
                        GameDefinitionId = gameDefinitionIdThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer
                    }
                },
                NemePointsSummary = new NemePointsSummary(1, 3, 5)
            };

            gameResultViewModelBuilder
                = MockRepository.GenerateMock<IGameResultViewModelBuilder>();
            gameResultViewModelBuilder.Expect(build => build.Build(playerGameResults[0]))
                    .Repeat
                    .Once()
                    .Return(new Models.PlayedGame.GameResultViewModel() { PlayedGameId = playerGameResults[0].PlayedGameId });
            gameResultViewModelBuilder.Expect(build => build.Build(playerGameResults[1]))
                    .Repeat
                    .Once()
                    .Return(new Models.PlayedGame.GameResultViewModel() { PlayedGameId = playerGameResults[1].PlayedGameId });
            foreach (var player in playerDetails.Minions)
            {
                minionViewModelBuilderMock.Expect(mock => mock.Build(player))
                    .Return(new MinionViewModel() { MinionPlayerId = player.Id });
            }

            var championedGames = new List<Champion>
            {
                new Champion { GameDefinition = gameDefinition1, GameDefinitionId = gameDefinitionIdThatIsChampionedByCurrentPlayer },
                new Champion { GameDefinition = gameDefinitionThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer, GameDefinitionId = gameDefinitionIdThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer }
            };
            playerDetails.ChampionedGames = championedGames;

            var formerChampionedGames = new List<GameDefinition>
            {
                gameDefinitionThatIsFormerlyChampionedByCurrentPlayer,
                gameDefinitionThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer
            };
            playerDetails.FormerChampionedGames = formerChampionedGames;

          

            builder = new PlayerDetailsViewModelBuilder(gameResultViewModelBuilder, minionViewModelBuilderMock, mapperFactory);

            playerDetailsViewModel = builder.Build(playerDetails, twitterMinionBraggingUrl, currentUser);
        }
Ejemplo n.º 5
0
        public void ItSetsTheAveragePointsPerGameToZeroIfNoGamesHaveBeenPlayed()
        {
            playerDetails.PlayerStats.TotalGames = 0;

            playerDetailsViewModel = builder.Build(playerDetails, twitterMinionBraggingUrl, currentUser);

            Assert.AreEqual(0, playerDetailsViewModel.AveragePointsPerGame);
        }
Ejemplo n.º 6
0
        public void ItSetsThePlayerRegisteredFlagToFalseIfThereIsNoApplicationUserIdOnThePlayer()
        {
            playerDetails.ApplicationUserId = null;
            playerDetailsViewModel = builder.Build(playerDetails, twitterMinionBraggingUrl, currentUser);

            Assert.AreEqual(false, playerDetailsViewModel.PlayerRegistered);
        }
 private void SetFormerChampionedGames(PlayerDetails playerDetails, PlayerDetailsViewModel playerDetailsViewModel)
 {
     if (playerDetails.PlayerGameSummaries == null)
     {
         return;
     }
     playerDetailsViewModel.PlayerGameSummaries
         .Where(summary => playerDetails.FormerChampionedGames.Select(fcg => fcg.Id).Contains(summary.GameDefinitionId)
             //take the current champion out of the former champions list
             && !summary.IsChampion)
         .ToList()
         .ForEach(x => x.IsFormerChampion = true);
 }
 private void PopulatePlayerGameResults(PlayerDetails playerDetails, PlayerDetailsViewModel playerDetailsViewModel)
 {
     playerDetailsViewModel.PlayerGameResultDetails = new List<GameResultViewModel>();
     GameResultViewModel gameResultViewModel;
     foreach (PlayerGameResult playerGameResult in playerDetails.PlayerGameResults)
     {
         gameResultViewModel = _gameResultViewModelBuilder.Build(playerGameResult);
         playerDetailsViewModel.PlayerGameResultDetails.Add(gameResultViewModel);
     }
 }
 private static void PopulateNemesisData(Nemesis nemesis, PlayerDetailsViewModel playerDetailsViewModel)
 {
     playerDetailsViewModel.HasNemesis = !(nemesis is NullNemesis);
     if (playerDetailsViewModel.HasNemesis)
     {
         playerDetailsViewModel.NemesisPlayerId = nemesis.NemesisPlayerId;
         playerDetailsViewModel.NemesisName = nemesis.NemesisPlayer.Name;
         playerDetailsViewModel.NumberOfGamesLostVersusNemesis = nemesis.NumberOfGamesLost;
         playerDetailsViewModel.LossPercentageVersusPlayer = nemesis.LossPercentage;
     }
 }
 private void SetChampionedGames(PlayerDetails playerDetails, PlayerDetailsViewModel playerDetailsViewModel)
 {
     if (playerDetails.PlayerGameSummaries == null)
     {
         return;
     }
     playerDetailsViewModel.PlayerGameSummaries
         .Where(summary => playerDetails.ChampionedGames
                             .Select(championedGame => championedGame.GameDefinitionId)
                             .Contains(summary.GameDefinitionId))
         .ToList()
         .ForEach(x => x.IsChampion = true);
 }
 private static void SetUserCanEditFlag(PlayerDetails playerDetails, ApplicationUser currentUser, PlayerDetailsViewModel playerDetailsViewModel)
 {
     if (currentUser == null || playerDetails.GamingGroupId != currentUser.CurrentGamingGroupId)
     {
         playerDetailsViewModel.UserCanEdit = false;
     }
     else
     {
         playerDetailsViewModel.UserCanEdit = true;
     }
 }
 private static void SetAveragePointsPerPlayer(PlayerDetails playerDetails, PlayerDetailsViewModel playerDetailsViewModel)
 {
     if (playerDetails.PlayerStats.AveragePlayersPerGame == 0)
     {
         playerDetailsViewModel.AveragePointsPerPlayer = 0;
     }
     else
     {
         playerDetailsViewModel.AveragePointsPerPlayer
             = playerDetailsViewModel.AveragePointsPerGame / playerDetails.PlayerStats.AveragePlayersPerGame;
     }
 }
 private static void SetAveragePointsPerGame(PlayerDetails playerDetails, PlayerDetailsViewModel playerDetailsViewModel)
 {
     if (playerDetails.PlayerStats.TotalGames == 0)
     {
         playerDetailsViewModel.AveragePointsPerGame = 0;
     }
     else
     {
         playerDetailsViewModel.AveragePointsPerGame = (float)playerDetails.PlayerStats.NemePointsSummary.TotalPoints / (float)playerDetails.PlayerStats.TotalGames;
     }
 }
 private static void SetTwitterBraggingUrlIfThePlayerIsTheCurrentlyLoggedInUser(PlayerDetails playerDetails,
                                                                                string urlForMinionBragging,
                                                                                ApplicationUser currentUser,
                                                                                PlayerDetailsViewModel playerDetailsViewModel)
 {
     if (currentUser != null && currentUser.Id == playerDetails.ApplicationUserId)
     {
         playerDetailsViewModel.MinionBraggingTweetUrl = urlForMinionBragging;
     }
 }
        private static void PopulatePlayerVersusPlayersViewModel(PlayerDetails playerDetails, PlayerDetailsViewModel playerDetailsViewModel)
        {
            var playerVersusPlayers = new PlayersSummaryViewModel
            {
                WinLossHeader = "Win - Loss Record vs. Player"
            };

            foreach (var playerVersusPlayerStatistics in playerDetails.PlayerVersusPlayersStatistics)
            {
                var winPercentage = GetWinPercentage(playerVersusPlayerStatistics);

                var playerSummaryViewModel = new PlayerSummaryViewModel
                {
                    PlayerName = PlayerNameBuilder.BuildPlayerName(playerVersusPlayerStatistics.OpposingPlayerName, playerVersusPlayerStatistics.OpposingPlayerActive),
                    PlayerId = playerVersusPlayerStatistics.OpposingPlayerId,
                    GamesWon = playerVersusPlayerStatistics.NumberOfGamesWonVersusThisPlayer,
                    GamesLost = playerVersusPlayerStatistics.NumberOfGamesLostVersusThisPlayer,
                    WinPercentage = (int)winPercentage
                };

                if (playerDetails.CurrentNemesis != null
                    && playerDetails.CurrentNemesis.NemesisPlayerId == playerVersusPlayerStatistics.OpposingPlayerId)
                {
                    playerSummaryViewModel.SpecialBadgeTypes.Add(new NemesisBadgeViewModel());
                }

                if (playerDetails.PreviousNemesis?.NemesisPlayerId == playerVersusPlayerStatistics.OpposingPlayerId)
                {
                    playerSummaryViewModel.SpecialBadgeTypes.Add(new PreviousNemesisBadgeViewModel());
                }

                if (playerDetails.Minions.Any(x => x.Id == playerVersusPlayerStatistics.OpposingPlayerId))
                {
                    playerSummaryViewModel.SpecialBadgeTypes.Add(new MinionBadgeViewModel());
                }

                playerVersusPlayers.PlayerSummaries.Add(playerSummaryViewModel);
            }

            playerDetailsViewModel.PlayerVersusPlayers = playerVersusPlayers;
        }