Beispiel #1
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);
        }
        private static decimal GetWinPercentage(PlayerVersusPlayerStatistics playerVersusPlayerStatistics)
        {
            decimal winPercentage = 0;

            if (playerVersusPlayerStatistics.NumberOfGamesLostVersusThisPlayer + playerVersusPlayerStatistics.NumberOfGamesWonVersusThisPlayer > 0)
            {
                winPercentage = ((decimal)playerVersusPlayerStatistics.NumberOfGamesWonVersusThisPlayer
                    / (playerVersusPlayerStatistics.NumberOfGamesWonVersusThisPlayer
                        + playerVersusPlayerStatistics.NumberOfGamesLostVersusThisPlayer) * 100);
            }
            return winPercentage;
        }