Inheritance: IEditableViewModel, IGamingGroupAssignedViewModel
Beispiel #1
0
        public void ItReturnsThePlayedGameDetailsViewForTheFoundPlayedGame()
        {
            int playedGameId = 13541;

            PlayedGame playedGame = new PlayedGame() { Id = 123 };
            autoMocker.Get<IPlayedGameRetriever>().Expect(x => x.GetPlayedGameDetails(playedGameId))
                .Repeat.Once()
                .Return(playedGame);
            PlayedGameDetailsViewModel playedGameDetails = new PlayedGameDetailsViewModel();
            autoMocker.Get<IPlayedGameDetailsViewModelBuilder>().Expect(builder => builder.Build(playedGame, currentUser, true)).Repeat.Once()
                .Return(playedGameDetails);

            ViewResult result = autoMocker.ClassUnderTest.Details(playedGameId, currentUser) as ViewResult;

            PlayedGameDetailsViewModel viewModel = (PlayedGameDetailsViewModel)result.ViewData.Model;
            Assert.AreEqual(playedGameDetails, viewModel);
        }
        public PlayedGameDetailsViewModel Build(PlayedGame playedGame, ApplicationUser currentUser, bool showPointsScored = false)
        {
            ValidateArguments(playedGame);

            PlayedGameDetailsViewModel summary = new PlayedGameDetailsViewModel();
            summary.GameDefinitionName = playedGame.GameDefinition.Name;
            summary.GameDefinitionId = playedGame.GameDefinitionId;
            summary.PlayedGameId = playedGame.Id;
            summary.DatePlayed = playedGame.DatePlayed;
            summary.GamingGroupId = playedGame.GamingGroup.Id;
            summary.GamingGroupName = playedGame.GamingGroup.Name;
            summary.WinnerType = playedGame.WinnerType;

            if (playedGame.GameDefinition.BoardGameGeekGameDefinition != null)
            {
                summary.ThumbnailImageUrl = playedGame.GameDefinition.BoardGameGeekGameDefinition.Thumbnail;
                summary.ImageUrl = playedGame.GameDefinition.BoardGameGeekGameDefinition.Image;
            }
            summary.BoardGameGeekUri =
                BoardGameGeekUriBuilder.BuildBoardGameGeekGameUri(playedGame.GameDefinition.BoardGameGeekGameDefinitionId);
            if (playedGame.Notes != null)
            {
                summary.Notes = playedGame.Notes.Replace(Environment.NewLine, NEWLINE_REPLACEMENT_FOR_HTML);
            }

            summary.UserCanEdit = (currentUser != null && playedGame.GamingGroupId == currentUser.CurrentGamingGroupId);
            summary.PlayerResults = new List<GameResultViewModel>();

            showPointsScored = showPointsScored && playedGame.PlayerGameResults.All(pgr => pgr.PointsScored.HasValue && pgr.PointsScored > 0);

            foreach (PlayerGameResult playerGameResult in playedGame.PlayerGameResults)
            {
                summary.PlayerResults.Add(playerResultBuilder.Build(playerGameResult, showPointsScored));
            }

            return summary;
        }
Beispiel #3
0
        public void It_Populates_The_Played_Games_For_The_GamingGroup()
        {
            //--arrange
            var expectedPlayedGameDetailViewModel1 = new PlayedGameDetailsViewModel();
            _autoMocker.Get<IPlayedGameDetailsViewModelBuilder>().Expect(mock => mock.Build(_expectedPlayedGame1, _currentUser, true))
                .Return(expectedPlayedGameDetailViewModel1);

            var expectedPlayedGameDetailViewModel2 = new PlayedGameDetailsViewModel();
            _autoMocker.Get<IPlayedGameDetailsViewModelBuilder>().Expect(mock => mock.Build(_expectedPlayedGame2, _currentUser, true))
                .Return(expectedPlayedGameDetailViewModel2);

            //--act
            var result = _autoMocker.ClassUnderTest.Details(_boardGameGeekGameDefinitionId, _currentUser) as ViewResult;

            //--assert
            var model = result.Model as UniversalGameDetailsViewModel;
            var gamingGroupSummary = model.GamingGroupGameDefinitionSummary;
            gamingGroupSummary.PlayedGames.ShouldContain(expectedPlayedGameDetailViewModel1);
            gamingGroupSummary.PlayedGames.ShouldContain(expectedPlayedGameDetailViewModel2);
        }
        public void FixtureSetUp()
        {
            _autoMocker = new RhinoAutoMocker<GameDefinitionDetailsViewModelBuilder>();
            _autoMocker.PartialMockTheClassUnderTest();

            _expectedPlayerSummary1 = new GameDefinitionPlayerSummaryViewModel();
            _expectedPlayerSummary2 = new GameDefinitionPlayerSummaryViewModel();

            List<PlayedGame> playedGames = new List<PlayedGame>();
            playedGames.Add(new PlayedGame
            {
                    Id = 10
                });
            _playedGameDetailsViewModel1 = new PlayedGameDetailsViewModel();
            playedGames.Add(new PlayedGame
            {
                Id = 11
            });
            _playedGameDetailsViewModel2 = new PlayedGameDetailsViewModel();
            _championPlayer = new Player
            {
                Name = _championName,
                Id = _championPlayerId,
                Active = true
            };
            _previousChampionPlayer = new Player
            {
                Name = _previousChampionName,
                Id = _previousChampionPlayerId,
                Active = false
            };
            _champion = new Champion
            {
                Player = _championPlayer,
                WinPercentage = _championWinPercentage,
                NumberOfGames = _championNumberOfGames,
                NumberOfWins = _championNumberOfWins
            };
            _previousChampion = new Champion
            {
                Player = _previousChampionPlayer
            };
            _playerWinRecord1 = new PlayerWinRecord
            {
                GamesWon = 1,
                GamesLost = 2,
                PlayerName = "player name",
                WinPercentage = 33,
                PlayerId = 3
            };
            _playerWinRecord2 = new PlayerWinRecord();

            _autoMocker.Get<ITransformer>().Expect(mock => mock.Transform<GameDefinitionPlayerSummaryViewModel>(_playerWinRecord1))
                       .Return(_expectedPlayerSummary1);
            _autoMocker.Get<ITransformer>().Expect(mock => mock.Transform<GameDefinitionPlayerSummaryViewModel>(_playerWinRecord2))
                 .Return(_expectedPlayerSummary2); 

            _gameDefinitionSummary = new GameDefinitionSummary
            {
                Id = 1,
                Name = "game definition name",
                Description = "game definition description",
                GamingGroupId = _gamingGroupid,
                GamingGroupName = "gaming group name",
                PlayedGames = playedGames,
                TotalNumberOfGamesPlayed = 3,
                AveragePlayersPerGame = 2.2M,
                BoardGameGeekGameDefinitionId = 123,
                BoardGameGeekGameDefinition = new BoardGameGeekGameDefinition() { Id = 123},
                Champion = _champion,
                PreviousChampion = _previousChampion,
                PlayerWinRecords = new List<PlayerWinRecord>
                {
                    _playerWinRecord1,
                    _playerWinRecord2
                },
                BoardGameGeekInfo = new BoardGameGeekInfo()
            };
            _currentUser = new ApplicationUser
            {
                CurrentGamingGroupId = _gamingGroupid
            };
            _autoMocker.Get<IPlayedGameDetailsViewModelBuilder>().Expect(mock => mock.Build(_gameDefinitionSummary.PlayedGames[0], _currentUser, true))
                .Return(_playedGameDetailsViewModel1);
            _autoMocker.Get<IPlayedGameDetailsViewModelBuilder>().Expect(mock => mock.Build(_gameDefinitionSummary.PlayedGames[1], _currentUser, true))
                .Return(_playedGameDetailsViewModel2);

            _expectedBoardGameGeekInfo = new BoardGameGeekInfoViewModel();
            _autoMocker.Get<ITransformer>().Expect(mock => mock.Transform<BoardGameGeekInfoViewModel>(_gameDefinitionSummary.BoardGameGeekInfo))
                .Return(_expectedBoardGameGeekInfo);

            _viewModel = _autoMocker.ClassUnderTest.Build(_gameDefinitionSummary, _currentUser);
        }
        private void SetItAllUp(WinnerTypes winnerType)
        {
            Stack<int> gameRankStack = new Stack<int>();
            if (winnerType == WinnerTypes.PlayerWin)
            {
                gameRankStack.Push(1);
                gameRankStack.Push(2);
                gameRankStack.Push(3);
            }else if (winnerType == WinnerTypes.TeamLoss)
            {
                gameRankStack.Push(2);
                gameRankStack.Push(2);
                gameRankStack.Push(2);
            }else if (winnerType == WinnerTypes.TeamWin)
            {
                gameRankStack.Push(1);
                gameRankStack.Push(1);
                gameRankStack.Push(1);
            }

            _gamingGroup = new GamingGroup
            {
                Id = _gamingGroupId,
                Name = "gaming group name"
            };
            _playedGame = new PlayedGame
            {
                Id = 11111,
                GameDefinition = new GameDefinition(),
                GamingGroup = _gamingGroup,
                GameDefinitionId = 2222,
                PlayerGameResults = new List<PlayerGameResult>(),
                GamingGroupId = _gamingGroupId,
                Notes = "some notes" + Environment.NewLine + "some notes on a separate line",
                WinnerType = winnerType
            };

            _playedGame.PlayerGameResults.Add(new PlayerGameResult()
            {
                GameRank = gameRankStack.Pop(),
                NemeStatsPointsAwarded = 3,
                Id = 1,
                PlayedGameId = _playedGame.Id,
                PlayerId = 1
            });

            _playedGame.PlayerGameResults.Add(new PlayerGameResult()
            {
                GameRank = gameRankStack.Pop(),
                NemeStatsPointsAwarded = 2,
                Id = 2,
                PlayedGameId = _playedGame.Id,
                PlayerId = 2
            });

            _playedGame.PlayerGameResults.Add(new PlayerGameResult()
            {
                GameRank = gameRankStack.Pop(),
                NemeStatsPointsAwarded = 1,
                Id = 3,
                PlayedGameId = _playedGame.Id,
                PlayerId = 3,
                PlayedGame = new PlayedGame()
                {
                    GameDefinition = new GameDefinition()
                    {
                        Id = 135,
                        Name = "Test game name"
                    }
                }
            });

            _detailsBuilder = MockRepository.GenerateMock<IGameResultViewModelBuilder>();
            _builder = new PlayedGameDetailsViewModelBuilder(_detailsBuilder);

            int totalPlayerGameResults = _playedGame.PlayerGameResults.Count;
            for (int i = 0; i < totalPlayerGameResults; i++)
            {
                _detailsBuilder.Expect(
                                      x => x.Build(_playedGame.PlayerGameResults[i]))
                              .Repeat
                              .Once()
                              .Return(new GameResultViewModel()
                              {
                                  PlayerId = _playedGame.PlayerGameResults[i].PlayerId
                              });
            }
            _currentUser = new ApplicationUser()
            {
                CurrentGamingGroupId = _gamingGroupId
            };

            _actualViewModel = _builder.Build(_playedGame, _currentUser, false);
        }