Example #1
0
        public void TheUserCanNotEditThePlayedGameDetailsViewModelIfTheyDoNotShareGamingGroups()
        {
            currentUser.CurrentGamingGroupId = -1;
            PlayedGameDetailsViewModel viewModel = builder.Build(playedGame, currentUser);

            Assert.False(viewModel.UserCanEdit);
        }
Example #2
0
        public virtual ActionResult Details(int?id, ApplicationUser currentUser)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PlayedGame playedGame = playedGameRetriever.GetPlayedGameDetails(id.Value);

            if (playedGame == null)
            {
                return(HttpNotFound());
            }
            PlayedGameDetailsViewModel playedGameDetails = playedGameDetailsBuilder.Build(playedGame, currentUser);

            return(View(MVC.PlayedGame.Views.Details, playedGameDetails));
        }
        public void It_Returns_The_Specified_Number_Of_Played_Games_In_The_Specific_Gaming_Group_With_The_Specified_Date_Filter()
        {
            //--arrange
            var gamingGroupId   = 1;
            var currentUser     = new ApplicationUser();
            var dateRangeFilter = new BasicDateRangeFilter();
            var numberOfItems   = 2;

            var expectedPlayedGames = new List <PlayedGame>
            {
                new PlayedGame(),
                new PlayedGame()
            };
            var expectedResult1 = new PlayedGameDetailsViewModel();
            var expectedResult2 = new PlayedGameDetailsViewModel();

            autoMocker.Get <IPlayedGameRetriever>()
            .Expect(mock => mock.GetRecentGames(numberOfItems, gamingGroupId, dateRangeFilter))
            .Return(expectedPlayedGames);
            autoMocker.Get <IPlayedGameDetailsViewModelBuilder>()
            .Expect(mock => mock.Build(expectedPlayedGames[0], currentUser))
            .Return(expectedResult1);
            autoMocker.Get <IPlayedGameDetailsViewModelBuilder>()
            .Expect(mock => mock.Build(expectedPlayedGames[1], currentUser))
            .Return(expectedResult2);

            //--act
            var result = autoMocker.ClassUnderTest.GetGamingGroupPlayedGames(gamingGroupId, currentUser, dateRangeFilter, numberOfItems);

            //--assert
            var viewResult = result as PartialViewResult;

            viewResult.ShouldNotBeNull();
            viewResult.ViewName.ShouldBe(MVC.PlayedGame.Views._PlayedGamesPartial);
            var model = viewResult.Model as PlayedGamesViewModel;

            model.ShouldNotBeNull();
            model.GamingGroupId.ShouldBe(gamingGroupId);
            model.ShowSearchLinkInResultsHeader.ShouldBeTrue();
            model.UserCanEdit.ShouldBeFalse("UserCanEdit should only be true if the Gaming Group is the current user's Gaming Group.");
            model.PlayedGameDetailsViewModels.ShouldNotBeNull();
            model.PlayedGameDetailsViewModels.Count.ShouldBe(2);
            model.PlayedGameDetailsViewModels[0].ShouldBeSameAs(expectedResult1);
            model.PlayedGameDetailsViewModels[1].ShouldBeSameAs(expectedResult2);
        }
        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);
        }
Example #5
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);
        }
Example #6
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);
        }
Example #7
0
        public PlayedGameDetailsViewModel Build(PlayedGame playedGame, ApplicationUser currentUser)
        {
            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;

            if (playedGame.GameDefinition.BoardGameGeekGameDefinition != null)
            {
                summary.ThumbnailImageUrl = playedGame.GameDefinition.BoardGameGeekGameDefinition.Thumbnail;
            }
            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>();

            foreach (PlayerGameResult playerGameResult in playedGame.PlayerGameResults)
            {
                summary.PlayerResults.Add(playerResultBuilder.Build(playerGameResult));
            }
            var gameRanks = playedGame.PlayerGameResults.Select(x => x.GameRank).ToList();

            summary.WinnerType = CalculateWinnerType(gameRanks);

            return(summary);
        }
Example #8
0
        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);
            }

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

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

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

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

            this.detailsBuilder = MockRepository.GenerateMock <IGameResultViewModelBuilder>();
            this.builder        = new PlayedGameDetailsViewModelBuilder(this.detailsBuilder);

            int totalPlayerGameResults = this.playedGame.PlayerGameResults.Count;

            for (int i = 0; i < totalPlayerGameResults; i++)
            {
                this.detailsBuilder.Expect(
                    x => x.Build(this.playedGame.PlayerGameResults[i]))
                .Repeat
                .Once()
                .Return(new GameResultViewModel()
                {
                    PlayerId = this.playedGame.PlayerGameResults[i].PlayerId
                });
            }
            this.currentUser = new ApplicationUser()
            {
                CurrentGamingGroupId = this.gamingGroupId
            };

            this.actualViewModel = this.builder.Build(this.playedGame, this.currentUser);
        }
Example #9
0
        public void TheUserCanNotEditThePlayedGameDetailsViewModelIfTheCurrentUserIsUnknown()
        {
            PlayedGameDetailsViewModel viewModel = builder.Build(playedGame, null);

            Assert.False(viewModel.UserCanEdit);
        }
Example #10
0
        public void TheUserCanEditThePlayedGameDetailsViewModelIfTheyShareGamingGroups()
        {
            PlayedGameDetailsViewModel viewModel = builder.Build(playedGame, currentUser);

            Assert.True(viewModel.UserCanEdit);
        }
Example #11
0
        public void FixtureSetUp()
        {
            autoMocker = new RhinoAutoMocker <GameDefinitionDetailsViewModelBuilder>();
            autoMocker.PartialMockTheClassUnderTest();

            expectedPlayerSummary1 = new PlayerSummaryViewModel();
            expectedPlayerSummary2 = new PlayerSummaryViewModel();

            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
            };
            previousChampionPlayer = new Player
            {
                Name = previousChampionName,
                Id   = previousChampionPlayerId
            };
            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 <PlayerWinRecord, PlayerSummaryViewModel>(playerWinRecord1))
            .Return(expectedPlayerSummary1);
            autoMocker.Get <ITransformer>().Expect(mock => mock.Transform <PlayerWinRecord, PlayerSummaryViewModel>(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,
                Champion                      = champion,
                PreviousChampion              = previousChampion,
                PlayerWinRecords              = new List <PlayerWinRecord>
                {
                    playerWinRecord1,
                    playerWinRecord2
                }
            };
            currentUser = new ApplicationUser
            {
                CurrentGamingGroupId = gamingGroupid
            };
            autoMocker.Get <IPlayedGameDetailsViewModelBuilder>().Expect(mock => mock.Build(gameDefinitionSummary.PlayedGames[0], currentUser))
            .Return(playedGameDetailsViewModel1);
            autoMocker.Get <IPlayedGameDetailsViewModelBuilder>().Expect(mock => mock.Build(gameDefinitionSummary.PlayedGames[1], currentUser))
            .Return(playedGameDetailsViewModel2);

            viewModel = autoMocker.ClassUnderTest.Build(gameDefinitionSummary, currentUser);
        }
        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);

            _expectedRegisteredUserDictionary = new Dictionary <int, string>
            {
                { _playerWinRecord1.PlayerId, _expectedPlayer1Email }
            };

            _viewModel = _autoMocker.ClassUnderTest.Build(_gameDefinitionSummary, _expectedRegisteredUserDictionary, _currentUser);
        }