Example #1
0
        public void SetUp()
        {
            this.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)
            };

            this.playerGameResult = new PlayerGameResult()
            {
                GameRank = 1,
                NemeStatsPointsAwarded = 2,
                Id       = 151,
                PlayerId = 15135,
                Player   = new Player()
                {
                    Name = "Test Player"
                },
                PlayedGameId = 1432,
                PlayedGame   = playedGame
            };

            this.playerGameResultDetails = this.builder.Build(this.playerGameResult);
        }
Example #2
0
        public JsonResult PlayGame(int gameId)
        {
            using (PlayingDataContext db = new PlayingDataContext())
            {
                var playingGame = db.PlayedGames.SingleOrDefault(m => m.UserName == User.Identity.Name);

                if (playingGame != null)
                {
                    PlayedGame game = new PlayedGame();
                    game.UserName = User.Identity.Name;
                    game.GameId   = gameId;

                    db.PlayedGames.Remove(playingGame);
                    db.PlayedGames.Add(game);
                    db.SaveChanges();
                }
                else
                {
                    PlayedGame game = new PlayedGame();
                    game.UserName = User.Identity.Name;
                    game.GameId   = gameId;

                    db.PlayedGames.Add(game);
                    db.SaveChanges();
                }
            }

            return(Json("{\"success\": true}", JsonRequestBehavior.AllowGet));
        }
Example #3
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);
        }
Example #4
0
        public void SetUp()
        {
            _currentUser = new ApplicationUser();

            _expectedGameDefinition = new GameDefinition
            {
                Name          = "game definition name",
                GamingGroupId = GAMING_GROUP_ID,
                Id            = 9598
            };

            _expectedPlayedGame = new PlayedGame
            {
                Id = 2,
                GameDefinitionId = _expectedGameDefinition.Id,
                NumberOfPlayers  = 3
            };

            _autoMocker  = new RhinoAutoMocker <CreatePlayedGameComponent>();
            _dataContext = MockRepository.GenerateMock <IDataContext>();

            _autoMocker.Get <ISecuredEntityValidator>().Expect(mock => mock.RetrieveAndValidateAccess <GameDefinition>(
                                                                   Arg <int> .Is.Anything,
                                                                   Arg <ApplicationUser> .Is.Anything))
            .Return(_expectedGameDefinition);

            _autoMocker.Get <IPlayedGameSaver>().Expect(mock => mock.TransformNewlyCompletedGameIntoPlayedGame(null, 0, null, null))
            .IgnoreArguments()
            .Return(_expectedPlayedGame);

            _dataContext
            .Expect(s => s.Save(Arg <PlayedGame> .Is.Anything, Arg <ApplicationUser> .Is.Anything))
            .Return(_expectedPlayedGame);
        }
Example #5
0
        //TODO this should be in its own class or just in AutoMapperConfiguration
        public virtual PlayedGame TransformNewlyCompletedGameIntoPlayedGame(
            SaveableGameBase savedGame,
            int gamingGroupId,
            string applicationUserId,
            List <PlayerGameResult> playerGameResults)
        {
            var winnerType = WinnerTypes.PlayerWin;

            if (playerGameResults.All(x => x.GameRank == 1))
            {
                winnerType = WinnerTypes.TeamWin;
            }
            else if (playerGameResults.All(x => x.GameRank > 1))
            {
                winnerType = WinnerTypes.TeamLoss;
            }

            var numberOfPlayers = savedGame.PlayerRanks.Count;
            var playedGame      = new PlayedGame
            {
                GameDefinitionId           = savedGame.GameDefinitionId,
                NumberOfPlayers            = numberOfPlayers,
                WinnerType                 = winnerType,
                PlayerGameResults          = playerGameResults,
                DatePlayed                 = savedGame.DatePlayed,
                GamingGroupId              = gamingGroupId,
                Notes                      = savedGame.Notes,
                CreatedByApplicationUserId = applicationUserId
            };

            return(playedGame);
        }
Example #6
0
        public void SetUp()
        {
            _dataContextMock          = MockRepository.GenerateMock <IDataContext>();
            _nemesisRecalculatorMock  = MockRepository.GenerateMock <INemesisRecalculator>();
            _championRecalculatorMock = MockRepository.GenerateMock <IChampionRecalculator>();
            _playedGameDeleter        = new PlayedGameDeleter(_dataContextMock, _nemesisRecalculatorMock, _championRecalculatorMock);

            _currentUser = new ApplicationUser();

            _playedGame = new PlayedGame()
            {
                GameDefinitionId = _gameDefinitionId
            };

            _playerGameResults = new List <PlayerGameResult>()
            {
                new PlayerGameResult()
                {
                    PlayerId = _playerInGame1Id, PlayedGameId = _playedGameId, PlayedGame = _playedGame
                },
                new PlayerGameResult()
                {
                    PlayerId = _playerInGame2Id, PlayedGameId = _playedGameId, PlayedGame = _playedGame
                },
                new PlayerGameResult()
                {
                    PlayerId = 3, PlayedGameId = _playedGameId + 9999, PlayedGame = _playedGame
                }
            };

            _dataContextMock.Expect(mock => mock.GetQueryable <PlayerGameResult>())
            .Return(_playerGameResults.AsQueryable());
        }
Example #7
0
        //TODO need to have validation logic here (or on PlayedGame similar to what is on NewlyCompletedGame)
        public PlayedGame CreatePlayedGame(NewlyCompletedGame newlyCompletedGame, TransactionSource transactionSource, ApplicationUser currentUser)
        {
            GameDefinition gameDefinition = dataContext.FindById <GameDefinition>(newlyCompletedGame.GameDefinitionId);

            securedEntityValidatorForGameDefinition.ValidateAccess(gameDefinition, currentUser, typeof(GameDefinition), newlyCompletedGame.GameDefinitionId);

            this.ValidateAccessToPlayers(newlyCompletedGame, currentUser);

            List <PlayerGameResult> playerGameResults = TransformNewlyCompletedGamePlayerRanksToPlayerGameResults(newlyCompletedGame);

            PlayedGame playedGame = TransformNewlyCompletedGameIntoPlayedGame(
                newlyCompletedGame,
                currentUser.CurrentGamingGroupId,
                currentUser.Id,
                playerGameResults);

            dataContext.Save(playedGame, currentUser);

            playedGameTracker.TrackPlayedGame(currentUser, transactionSource);

            foreach (PlayerGameResult result in playerGameResults)
            {
                nemesisRecalculator.RecalculateNemesis(result.PlayerId, currentUser);
            }
            championRecalculator.RecalculateChampion(playedGame.GameDefinitionId, currentUser);

            return(playedGame);
        }
Example #8
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);
        }
 public void ItRetrievesThePlayedGame()
 {
     using (NemeStatsDataContext dbContext = new NemeStatsDataContext())
     {
         PlayedGame playedGame = GetTestSubjectPlayedGame(dbContext);
         Assert.NotNull(playedGame);
     }
 }
Example #10
0
        private static bool IsDataValid(PlayedGame playedGame)
        {
            if (playedGame == null)
            {
                return(false);
            }

            return(true);
        }
        public void ItCreatesATwoPlayerPlayedGameAndSetsTheNumberOfPlayers()
        {
            using (NemeStatsDbContext dbContext = new NemeStatsDbContext())
            {
                PlayedGame playedGameFromTheDatabase = dbContext.PlayedGames.Find(testPlayedGames[0].Id);

                Assert.IsTrue(playedGameFromTheDatabase.NumberOfPlayers == 2);
            }
        }
Example #12
0
        public void ItOnlyReturnsCountsForPlayedGamesThatHappenedXDaysAgoOrLater()
        {
            int days = 1;

            var expectedPlayedGame = new PlayedGame
            {
                DatePlayed = DateTime.Now.Date.AddDays(days * -1),
            };
            var excludedPlayedGame = new PlayedGame
            {
                DatePlayed     = DateTime.Now.Date.AddDays((days + 1) * -1),
                GameDefinition = new GameDefinition
                {
                    BoardGameGeekGameDefinition = new BoardGameGeekGameDefinition()
                }
            };
            var playedGames = new List <PlayedGame>
            {
                expectedPlayedGame,
                excludedPlayedGame
            };
            var boardGameGeekGameDefinitionQueryable = new List <BoardGameGeekGameDefinition>
            {
                new BoardGameGeekGameDefinition
                {
                    GameDefinitions = new List <GameDefinition>
                    {
                        //--this has one included played game
                        new GameDefinition
                        {
                            PlayedGames = playedGames
                        },
                        //--this has one included played game
                        new GameDefinition
                        {
                            PlayedGames = playedGames
                        },
                        new GameDefinition
                        {
                            PlayedGames = new List <PlayedGame>
                            {
                                excludedPlayedGame
                            }
                        }
                    }
                }
            }.AsQueryable();

            autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <BoardGameGeekGameDefinition>()).Return(boardGameGeekGameDefinitionQueryable);

            var results = autoMocker.ClassUnderTest.GetTrendingGames(100, days);

            Assert.That(results.Count, Is.EqualTo(1));
            Assert.That(results[0].GamesPlayed, Is.EqualTo(2));
            Assert.That(results[0].GamingGroupsPlayingThisGame, Is.EqualTo(2));
        }
        public void ItOnlyReturnsCountsForPlayedGamesThatHappenedXDaysAgoOrLater()
        {
            int days = 1;

            var expectedPlayedGame = new PlayedGame
            {
                DatePlayed = DateTime.Now.Date.AddDays(days * -1),
            };
            var excludedPlayedGame = new PlayedGame
            {
                DatePlayed = DateTime.Now.Date.AddDays((days + 1) * -1),
                GameDefinition = new GameDefinition
                {
                    BoardGameGeekGameDefinition = new BoardGameGeekGameDefinition()
                }
            };
            var playedGames = new List<PlayedGame>
            {
                expectedPlayedGame,
                excludedPlayedGame
            };
            var boardGameGeekGameDefinitionQueryable = new List<BoardGameGeekGameDefinition>
            {
                new BoardGameGeekGameDefinition
                {
                    GameDefinitions = new List<GameDefinition>
                    {
                        //--this has one included played game
                        new GameDefinition
                        {
                            PlayedGames = playedGames
                        },
                        //--this has one included played game
                        new GameDefinition
                        {
                            PlayedGames = playedGames
                        },
                        new GameDefinition
                        {
                            PlayedGames = new List<PlayedGame>
                            {
                                excludedPlayedGame
                            }
                        }
                    }
                }
            }.AsQueryable();
            autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<BoardGameGeekGameDefinition>()).Return(boardGameGeekGameDefinitionQueryable);

            var results = autoMocker.ClassUnderTest.GetTrendingGames(100, days);

            Assert.That(results.Count, Is.EqualTo(1));
            Assert.That(results[0].GamesPlayed, Is.EqualTo(2));
            Assert.That(results[0].GamingGroupsPlayingThisGame, Is.EqualTo(2));
        }
 public void ItEagerlyFetchesThePlayers()
 {
     using (NemeStatsDbContext dbContext = new NemeStatsDbContext())
     {
         dbContext.Configuration.LazyLoadingEnabled = false;
         using (NemeStatsDataContext dataContext = new NemeStatsDataContext(dbContext, securedEntityValidatorFactory))
         {
             PlayedGame playedGame = GetTestSubjectPlayedGame(dataContext);
             Assert.NotNull(playedGame.PlayerGameResults[0].Player);
         }
     }
 }
Example #15
0
        public HttpResponseMessage RecordPlayedGame([FromBody] PlayedGameMessage playedGameMessage, [FromUri] int gamingGroupId)
        {
            var newlyCompletedGame = BuildNewlyPlayedGame(playedGameMessage);

            PlayedGame playedGame = playedGameCreator.CreatePlayedGame(newlyCompletedGame, TransactionSource.RestApi, CurrentUser);
            var        newlyRecordedPlayedGameMessage = new NewlyRecordedPlayedGameMessage
            {
                PlayedGameId = playedGame.Id
            };

            return(Request.CreateResponse(HttpStatusCode.OK, newlyRecordedPlayedGameMessage));
        }
Example #16
0
        public virtual ActionResult Delete(int?id, ApplicationUser currentUser)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PlayedGame playedgame = dataContext.GetQueryable <PlayedGame>().FirstOrDefault(playedGame => playedGame.Id == id.Value);

            if (playedgame == null)
            {
                return(HttpNotFound());
            }
            return(View(playedgame));
        }
Example #17
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 ItCreatesAnApplicationLinkageForEachSpecifiedApplicationLinkage()
        {
            //--arrange
            var expectedApplicationLinkage1 = new ApplicationLinkage
            {
                ApplicationName = "app1",
                EntityId        = "1"
            };
            var expectedApplicationLinkage2 = new ApplicationLinkage
            {
                ApplicationName = "app2",
                EntityId        = "2"
            };
            var applicationLinkages = new List <ApplicationLinkage>
            {
                expectedApplicationLinkage1,
                expectedApplicationLinkage2
            };

            var expectedPlayedGame = new PlayedGame
            {
                Id = EXPECTED_PLAYED_GAME_ID
            };

            AutoMocker.Get <IPlayedGameSaver>().Expect(partialMock => partialMock.TransformNewlyCompletedGameIntoPlayedGame(null, 0, null, null))
            .IgnoreArguments()
            .Return(expectedPlayedGame);

            var dataContext = MockRepository.GenerateMock <IDataContext>();

            //--act
            AutoMocker.ClassUnderTest.CreateApplicationLinkages(applicationLinkages, expectedPlayedGame.Id, dataContext);

            //--assert
            AutoMocker.Get <IApplicationLinker>().AssertWasCalled(mock => mock.LinkApplication(
                                                                      EXPECTED_PLAYED_GAME_ID,
                                                                      expectedApplicationLinkage1.ApplicationName,
                                                                      expectedApplicationLinkage1.EntityId,
                                                                      dataContext));

            AutoMocker.Get <IApplicationLinker>().AssertWasCalled(mock => mock.LinkApplication(
                                                                      EXPECTED_PLAYED_GAME_ID,
                                                                      expectedApplicationLinkage2.ApplicationName,
                                                                      expectedApplicationLinkage2.EntityId,
                                                                      dataContext));
        }
Example #19
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);
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        for (int i = 0; i < NumGames; i++)
        {
            ZGSSController controller = (ZGSSController)Application["Domain"];
            PlayedGame     game       = controller.getGame(_listGameIDs[i]);

            TableRow tempRow = new TableRow();

            TableCell tempCell1 = new TableCell();
            tempCell1.Text = game.PlayedOn.ToShortDateString();
            tempRow.Cells.Add(tempCell1);

            TableCell tempCell2 = new TableCell();
            tempCell2.Text = game.Duration.ToString();
            tempRow.Cells.Add(tempCell2);

            TableCell tempCell3 = new TableCell();
            tempCell3.Text = game.GameType.GameName;
            tempRow.Cells.Add(tempCell3);

            TableCell tempCell4 = new TableCell();
            tempCell4.Text = game.Map.Name;
            tempRow.Cells.Add(tempCell4);

            string    players   = game.getPlayers();
            TableCell tempCell5 = new TableCell();
            tempCell5.Text = players;
            tempRow.Cells.Add(tempCell5);

            TeamParticipatingInGame winner = game.getWinner();
            TableCell tempCell6            = new TableCell();
            tempCell6.Text = winner.TeamInGame.getTeamName();
            tempRow.Cells.Add(tempCell6);

            TableCell tempCell7 = new TableCell();
            tempCell7.Text = "<a href=\"frmPlayedGame.aspx?GameID=" + game.GameID.ToString() + "\">detalji </a>";
//      tempCell7.Text = "<asp:HyperLink ID=\"HyperLink1\" runat=\"server\" NavigateUrl=\"~/frmPlayedGame.aspx?GameID=0\">detalji</asp:HyperLink>&nbsp;</p>";
            tempRow.Cells.Add(tempCell7);



            tblGameList.Rows.Add(tempRow);
        }
    }
        public void ItCreatesAnApplicationLinkageForEachSpecifiedApplicationLinkage()
        {
            //--arrange
            var newlyCompletedPlayedGame    = CreateValidNewlyCompletedGame();
            var expectedApplicationLinkage1 = new ApplicationLinkage
            {
                ApplicationName = "app1",
                EntityId        = "1"
            };
            var expectedApplicationLinkage2 = new ApplicationLinkage
            {
                ApplicationName = "app2",
                EntityId        = "2"
            };

            newlyCompletedPlayedGame.ApplicationLinkages = new List <ApplicationLinkage>
            {
                expectedApplicationLinkage1,
                expectedApplicationLinkage2
            };

            var expectedPlayedGame = new PlayedGame
            {
                Id = EXPECTED_PLAYED_GAME_ID
            };

            autoMocker.ClassUnderTest.Expect(partialMock => partialMock.TransformNewlyCompletedGameIntoPlayedGame(null, 0, null, null))
            .IgnoreArguments()
            .Return(expectedPlayedGame);

            //--act
            autoMocker.ClassUnderTest.CreatePlayedGame(newlyCompletedPlayedGame, TransactionSource.WebApplication, currentUser);

            //--assert
            autoMocker.Get <IApplicationLinker>().AssertWasCalled(mock => mock.LinkApplication(
                                                                      EXPECTED_PLAYED_GAME_ID,
                                                                      expectedApplicationLinkage1.ApplicationName,
                                                                      expectedApplicationLinkage1.EntityId));

            autoMocker.Get <IApplicationLinker>().AssertWasCalled(mock => mock.LinkApplication(
                                                                      EXPECTED_PLAYED_GAME_ID,
                                                                      expectedApplicationLinkage2.ApplicationName,
                                                                      expectedApplicationLinkage2.EntityId));
        }
Example #22
0
        public void ItSetsTheCorrectFields()
        {
            int expectedBoardGameGeekGameDefinitionId1 = 1;
            var expectedPlayedGame = new PlayedGame
            {
                Id = 1
            };
            var playedGames = new List <PlayedGame>
            {
                expectedPlayedGame,
                expectedPlayedGame
            };
            string expectedName      = "some game definition name";
            string expectedThumbnail = "some expected thumbnail";

            var boardGameGeekGameDefinitionQueryable = new List <BoardGameGeekGameDefinition>
            {
                new BoardGameGeekGameDefinition
                {
                    Id              = expectedBoardGameGeekGameDefinitionId1,
                    Name            = expectedName,
                    Thumbnail       = expectedThumbnail,
                    GameDefinitions = new List <GameDefinition>
                    {
                        new GameDefinition
                        {
                            PlayedGames = playedGames
                        }
                    }
                }
            }.AsQueryable();

            autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <BoardGameGeekGameDefinition>()).Return(boardGameGeekGameDefinitionQueryable);
            int expectedNumberOfGames = 2;

            var results = autoMocker.ClassUnderTest.GetTrendingGames(expectedNumberOfGames, 1);

            Assert.That(results[0].BoardGameGeekGameDefinitionId, Is.EqualTo(expectedBoardGameGeekGameDefinitionId1));
            Assert.That(results[0].BoardGameGeekUri, Is.EqualTo(BoardGameGeekUriBuilder.BuildBoardGameGeekGameUri(expectedBoardGameGeekGameDefinitionId1)));
            Assert.That(results[0].GamingGroupsPlayingThisGame, Is.EqualTo(1));
            Assert.That(results[0].GamesPlayed, Is.EqualTo(2));
            Assert.That(results[0].Name, Is.EqualTo(expectedName));
            Assert.That(results[0].ThumbnailImageUrl, Is.EqualTo(expectedThumbnail));
        }
Example #23
0
        public Result UpdateGame(UpdatePlayedGameDto newGameDto)
        {
            Result result = new Result();

            try
            {
                PlayedGame oldPlayedGame = this.gamesRepository.FindRough(newGameDto.ID);
                if (newGameDto == null)
                {
                    return(result.SetError($"There is no game with #{ newGameDto.ID }!"));
                }

                using (var scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    UpdatePlayedGameDto oldGameDto = Mapper.Map <PlayedGame, UpdatePlayedGameDto>(oldPlayedGame);
                    Result updatePointsResult      = this.UpdateTeamsPoints(oldGameDto, gameDeletion: true);
                    if (updatePointsResult.IsError)
                    {
                        result.SetError(updatePointsResult.Message);

                        return(result);
                    }

                    oldPlayedGame.Result = newGameDto.Result;
                    this.gamesRepository.Update(oldPlayedGame);

                    updatePointsResult = this.UpdateTeamsPoints(newGameDto, gameDeletion: false);
                    if (updatePointsResult.IsError)
                    {
                        result.SetError(updatePointsResult.Message);

                        return(result);
                    }

                    scope.Complete();
                }

                return(result.SetSuccess("Game updated successfully."));
            }
            catch (Exception ex)
            {
                return(result.SetError(ex.Message));
            }
        }
Example #24
0
        public void ItSetsnemeStatsPointsForEachPlayerGameResult()
        {
            int playerOneId               = 1;
            int playerTwoId               = 2;
            int playerOneGameRank         = 1;
            int playerTwoGameRank         = 2;
            List <PlayerRank> playerRanks = new List <PlayerRank>()
            {
                new PlayerRank()
                {
                    PlayerId = playerOneId,
                    GameRank = playerOneGameRank
                },
                new PlayerRank()
                {
                    PlayerId = playerTwoId,
                    GameRank = playerTwoGameRank
                }
            };
            NewlyCompletedGame newlyCompletedGame = new NewlyCompletedGame()
            {
                GameDefinitionId = gameDefinition.Id,
                PlayerRanks      = playerRanks
            };

            var pointsDictionary = PointsCalculator.CalculatePoints(playerRanks);

            int             playerOneExpectednemeStatsPoints = pointsDictionary[playerOneId];
            ApplicationUser user = new ApplicationUser();

            PlayedGame playedGame = autoMocker.ClassUnderTest.CreatePlayedGame(newlyCompletedGame, TransactionSource.WebApplication, this.currentUser);

            Assert.AreEqual(playerOneExpectednemeStatsPoints, playedGame.PlayerGameResults
                            .First(gameResult => gameResult.PlayerId == playerOneId)
                            .NemeStatsPointsAwarded);

            int playerTwoExpectednemeStatsPoints = pointsDictionary[playerTwoId];

            Assert.AreEqual(playerTwoExpectednemeStatsPoints, playedGame.PlayerGameResults
                            .First(gameResult => gameResult.PlayerId == playerTwoId)
                            .NemeStatsPointsAwarded);
        }
Example #25
0
        public void LocalSetUp()
        {
            this.playedGameMessage = new PlayedGameMessage
            {
                DatePlayed       = "2015-04-10",
                GameDefinitionId = 1,
                Notes            = "some notes"
            };

            PlayedGame expectedPlayedGame = new PlayedGame
            {
                Id = EXPECTED_PLAYED_GAME_ID
            };

            this.autoMocker.Get <IPlayedGameCreator>().Expect(mock => mock.CreatePlayedGame(
                                                                  Arg <NewlyCompletedGame> .Is.Anything,
                                                                  Arg <TransactionSource> .Is.Anything,
                                                                  Arg <ApplicationUser> .Is.Anything))
            .Return(expectedPlayedGame);
        }
Example #26
0
        public PlayedGame GetPlayedGameDetails(int playedGameId)
        {
            PlayedGame result = dataContext.GetQueryable <PlayedGame>()
                                .Where(playedGame => playedGame.Id == playedGameId)
                                .Include(playedGame => playedGame.GameDefinition)
                                .Include(playedGame => playedGame.GameDefinition.BoardGameGeekGameDefinition)
                                .Include(playedGame => playedGame.GamingGroup)
                                .Include(playedGame => playedGame.PlayerGameResults
                                         .Select(playerGameResult => playerGameResult.Player))
                                .FirstOrDefault();

            if (result == null)
            {
                throw new EntityDoesNotExistException(typeof(PlayedGame), playedGameId);
            }

            result.PlayerGameResults = result.PlayerGameResults.OrderBy(playerGameResult => playerGameResult.GameRank).ToList();

            return(result);
        }
Example #27
0
        //TODO this should be in its own class
        internal virtual PlayedGame TransformNewlyCompletedGameIntoPlayedGame(
            NewlyCompletedGame newlyCompletedGame,
            int gamingGroupId,
            string applicationUserId,
            List <PlayerGameResult> playerGameResults)
        {
            int        numberOfPlayers = newlyCompletedGame.PlayerRanks.Count();
            PlayedGame playedGame      = new PlayedGame()
            {
                GameDefinitionId           = newlyCompletedGame.GameDefinitionId.Value,
                NumberOfPlayers            = numberOfPlayers,
                PlayerGameResults          = playerGameResults,
                DatePlayed                 = newlyCompletedGame.DatePlayed,
                GamingGroupId              = gamingGroupId,
                Notes                      = newlyCompletedGame.Notes,
                CreatedByApplicationUserId = applicationUserId
            };

            return(playedGame);
        }
Example #28
0
        public void SetUp()
        {
            _autoMocker = new RhinoAutoMocker<UniversalGameController>();
            _currentUser = new ApplicationUser();

            _expectedPlayedGame1 = new PlayedGame();
            _expectedPlayedGame2 = new PlayedGame();
            _expectedPlayerWinRecord1 = new PlayerWinRecord();
            _expectedPlayerWinRecord2 = new PlayerWinRecord();
            _expectedGameDefinitionSummary = new GameDefinitionSummary
            {
                Id = 50,
                AveragePlayersPerGame = 2.59M,
                GamingGroupName = "some gaming group name",
                TotalNumberOfGamesPlayed = 3,
                PlayedGames = new List<PlayedGame>
                {
                    _expectedPlayedGame1,
                    _expectedPlayedGame2
                },
                PlayerWinRecords = new List<PlayerWinRecord>
                {
                    _expectedPlayerWinRecord1,
                    _expectedPlayerWinRecord2
                }
            };
            _expectedBoardGameGeekGameSummary = new BoardGameGeekGameSummary
            {
                GamingGroupGameDefinitionSummary = _expectedGameDefinitionSummary
            };
            _expectedUniversalGameDetailsViewModel = new UniversalGameDetailsViewModel
            {
                BoardGameGeekInfo = new BoardGameGeekInfoViewModel()
            };

            _autoMocker.Get<IUniversalGameRetriever>().Expect(mock => mock.GetBoardGameGeekGameSummary(Arg<int>.Is.Anything, Arg<ApplicationUser>.Is.Anything, Arg<int>.Is.Anything))
                .Return(_expectedBoardGameGeekGameSummary);
            _autoMocker.Get<ITransformer>()
                .Expect(mock => mock.Transform<UniversalGameDetailsViewModel>(Arg<BoardGameGeekGameSummary>.Is.Anything))
                .Return(_expectedUniversalGameDetailsViewModel);
        }
Example #29
0
        public void SetUp()
        {
            _autoMocker  = new RhinoAutoMocker <UniversalGameController>();
            _currentUser = new ApplicationUser();

            _expectedPlayedGame1           = new PlayedGame();
            _expectedPlayedGame2           = new PlayedGame();
            _expectedPlayerWinRecord1      = new PlayerWinRecord();
            _expectedPlayerWinRecord2      = new PlayerWinRecord();
            _expectedGameDefinitionSummary = new GameDefinitionSummary
            {
                Id = 50,
                AveragePlayersPerGame    = 2.59M,
                GamingGroupName          = "some gaming group name",
                TotalNumberOfGamesPlayed = 3,
                PlayedGames = new List <PlayedGame>
                {
                    _expectedPlayedGame1,
                    _expectedPlayedGame2
                },
                PlayerWinRecords = new List <PlayerWinRecord>
                {
                    _expectedPlayerWinRecord1,
                    _expectedPlayerWinRecord2
                }
            };
            _expectedBoardGameGeekGameSummary = new BoardGameGeekGameSummary
            {
                GamingGroupGameDefinitionSummary = _expectedGameDefinitionSummary
            };
            _expectedUniversalGameDetailsViewModel = new UniversalGameDetailsViewModel
            {
                BoardGameGeekInfo = new BoardGameGeekInfoViewModel()
            };

            _autoMocker.Get <IUniversalGameRetriever>().Expect(mock => mock.GetBoardGameGeekGameSummary(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything, Arg <int> .Is.Anything))
            .Return(_expectedBoardGameGeekGameSummary);
            _autoMocker.Get <ITransformer>()
            .Expect(mock => mock.Transform <UniversalGameDetailsViewModel>(Arg <BoardGameGeekGameSummary> .Is.Anything))
            .Return(_expectedUniversalGameDetailsViewModel);
        }
        private static void ValidateArguments(PlayedGame playedGame)
        {
            if (playedGame == null)
            {
                throw new ArgumentNullException("playedGame");
            }

            if (playedGame.GamingGroup == null)
            {
                throw new ArgumentException(EXCEPTION_MESSAGE_GAMING_GROUP_CANNOT_BE_NULL);
            }

            if (playedGame.GameDefinition == null)
            {
                throw new ArgumentException(EXCEPTION_MESSAGE_GAME_DEFINITION_CANNOT_BE_NULL);
            }

            if (playedGame.PlayerGameResults == null)
            {
                throw new ArgumentException(EXCEPTION_MESSAGE_PLAYER_GAME_RESULTS_CANNOT_BE_NULL);
            }
        }
Example #31
0
        /// <summary>
        /// Get the played games for the Playstation Network Profile
        /// </summary>
        /// <returns>Played games</returns>
        internal List <Core.PlayedGame> GetPlayedGames()
        {
            List <Core.PlayedGame> parsedPlayedGames = new List <PlayedGame>();

            foreach (HtmlNode htmlNode in _htmlDocument.DocumentNode.SelectNodes("//div[@class='slot']"))
            {
                //var idElement = htmlNode.Descendants("a").FirstOrDefault(n => n.ParentNode.Name == "div" && n.ParentNode.Attributes["class"].Value == "titlelogo").Attributes["href"].Value.Split(Convert.ToChar("/")).Last();

                PlayedGame parsedPlayedGame = new PlayedGame()
                {
                    Id          = GetId(htmlNode),
                    Title       = GetName(htmlNode),
                    Image       = GetImage(htmlNode),
                    Progress    = GetProgress(htmlNode),
                    TrophyCount = GetTrophyCount(htmlNode)
                };

                parsedPlayedGames.Add(parsedPlayedGame);
            }

            return(parsedPlayedGames);
        }
Example #32
0
        private static void ValidateArguments(PlayedGame playedGame)
        {
            if (playedGame == null)
            {
                throw new ArgumentNullException("playedGame");
            }

            if (playedGame.GamingGroup == null)
            {
                throw new ArgumentException(EXCEPTION_MESSAGE_GAMING_GROUP_CANNOT_BE_NULL);
            }

            if (playedGame.GameDefinition == null)
            {
                throw new ArgumentException(EXCEPTION_MESSAGE_GAME_DEFINITION_CANNOT_BE_NULL);
            }

            if (playedGame.PlayerGameResults == null)
            {
                throw new ArgumentException(EXCEPTION_MESSAGE_PLAYER_GAME_RESULTS_CANNOT_BE_NULL);
            }
        }
        public void LocalSetUp()
        {
            _playedGameMessage = new PlayedGameMessage();

            _expectedNewlyCompletedGame = new NewlyCompletedGame();

            _autoMocker.Get <ITransformer>()
            .Expect(mock => mock.Transform <NewlyCompletedGame>(_playedGameMessage))
            .IgnoreArguments()
            .Return(_expectedNewlyCompletedGame);

            var expectedPlayedGame = new PlayedGame
            {
                Id            = EXPECTED_PLAYED_GAME_ID,
                GamingGroupId = EXPECTED_GAMING_GROUP_ID
            };

            _autoMocker.Get <ICreatePlayedGameComponent>().Expect(mock => mock.Execute(
                                                                      Arg <NewlyCompletedGame> .Is.Anything,
                                                                      Arg <ApplicationUser> .Is.Anything))
            .Return(expectedPlayedGame);
        }
        /// <summary>
        /// Get the played games for the Playstation Network Profile
        /// </summary>
        /// <returns>Played games</returns>
        internal List<Core.PlayedGame> GetPlayedGames()
        {
            List<Core.PlayedGame> parsedPlayedGames = new List<PlayedGame>();

            foreach (HtmlNode htmlNode in _htmlDocument.DocumentNode.SelectNodes("//div[@class='slot']"))
            {
                //var idElement = htmlNode.Descendants("a").FirstOrDefault(n => n.ParentNode.Name == "div" && n.ParentNode.Attributes["class"].Value == "titlelogo").Attributes["href"].Value.Split(Convert.ToChar("/")).Last();

                PlayedGame parsedPlayedGame = new PlayedGame()
                {
                    Id = GetId(htmlNode),
                    Title = GetName(htmlNode),
                    Image = GetImage(htmlNode),
                    Progress = GetProgress(htmlNode),
                    TrophyCount = GetTrophyCount(htmlNode)
                };

                parsedPlayedGames.Add(parsedPlayedGame);
            }

            return parsedPlayedGames;
        }
        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 #36
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;
        }
        public void SetUp()
        {
            dataContextMock = MockRepository.GenerateMock<IDataContext>();
            nemesisRecalculatorMock = MockRepository.GenerateMock<INemesisRecalculator>();
            championRecalculatorMock = MockRepository.GenerateMock<IChampionRecalculator>();
            playedGameDeleter = new PlayedGameDeleter(dataContextMock, nemesisRecalculatorMock, championRecalculatorMock);

            currentUser = new ApplicationUser();

            playedGame = new PlayedGame()
            {
                GameDefinitionId = gameDefinitionId
            };

            playerGameResults = new List<PlayerGameResult>()
            {
                new PlayerGameResult(){ PlayerId = playerInGame1Id, PlayedGameId = playedGameId, PlayedGame = playedGame },
                new PlayerGameResult(){ PlayerId = playerInGame2Id, PlayedGameId = playedGameId, PlayedGame = playedGame },
                new PlayerGameResult(){ PlayerId = 3, PlayedGameId = playedGameId + 9999, PlayedGame = playedGame }
            };

            dataContextMock.Expect(mock => mock.GetQueryable<PlayerGameResult>())
                .Return(playerGameResults.AsQueryable());
        }
        public void ItCreatesAnApplicationLinkageForNemeStats()
        {
            //--arrange
            var newlyCompletedPlayedGame = CreateValidNewlyCompletedGame();

            var expectedPlayedGame = new PlayedGame
            {
                Id = EXPECTED_PLAYED_GAME_ID
            };
            autoMocker.ClassUnderTest.Expect(partialMock => partialMock.TransformNewlyCompletedGameIntoPlayedGame(null, 0, null, null))
                .IgnoreArguments()
                .Return(expectedPlayedGame);

            //--act
            autoMocker.ClassUnderTest.CreatePlayedGame(newlyCompletedPlayedGame, TransactionSource.WebApplication, currentUser);

            //--assert
            autoMocker.Get<IApplicationLinker>().AssertWasCalled(mock => mock.LinkApplication(
                EXPECTED_PLAYED_GAME_ID,
                ApplicationLinker.APPLICATION_NAME_NEMESTATS,
                EXPECTED_PLAYED_GAME_ID.ToString()));
        }
        public void ItCreatesAnApplicationLinkageForEachSpecifiedApplicationLinkage()
        {
            //--arrange
            var newlyCompletedPlayedGame = CreateValidNewlyCompletedGame();
            var expectedApplicationLinkage1 = new ApplicationLinkage
            {
                ApplicationName = "app1",
                EntityId = "1"
            };
            var expectedApplicationLinkage2 = new ApplicationLinkage
            {
                ApplicationName = "app2",
                EntityId = "2"
            };
            newlyCompletedPlayedGame.ApplicationLinkages = new List<ApplicationLinkage>
            {
                expectedApplicationLinkage1,
                expectedApplicationLinkage2
            };

            var expectedPlayedGame = new PlayedGame
            {
                Id = EXPECTED_PLAYED_GAME_ID
            };
            autoMocker.ClassUnderTest.Expect(partialMock => partialMock.TransformNewlyCompletedGameIntoPlayedGame(null, 0, null, null))
                .IgnoreArguments()
                .Return(expectedPlayedGame);

            //--act
            autoMocker.ClassUnderTest.CreatePlayedGame(newlyCompletedPlayedGame, TransactionSource.WebApplication, currentUser);

            //--assert
            autoMocker.Get<IApplicationLinker>().AssertWasCalled(mock => mock.LinkApplication(
                EXPECTED_PLAYED_GAME_ID,
                expectedApplicationLinkage1.ApplicationName,
                expectedApplicationLinkage1.EntityId));

            autoMocker.Get<IApplicationLinker>().AssertWasCalled(mock => mock.LinkApplication(
              EXPECTED_PLAYED_GAME_ID,
              expectedApplicationLinkage2.ApplicationName,
              expectedApplicationLinkage2.EntityId));
        }
        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);
        }
        public void ItSetsTheCorrectFields()
        {
            int expectedBoardGameGeekGameDefinitionId1 = 1;
            var expectedPlayedGame = new PlayedGame
            {
                Id = 1
            };
            var playedGames = new List<PlayedGame>
            {
                expectedPlayedGame,
                expectedPlayedGame
            };
            string expectedName = "some game definition name";
            string expectedThumbnail = "some expected thumbnail";

            var boardGameGeekGameDefinitionQueryable = new List<BoardGameGeekGameDefinition>
            {
                new BoardGameGeekGameDefinition
                {
                    Id = expectedBoardGameGeekGameDefinitionId1,
                    Name = expectedName,
                    Thumbnail = expectedThumbnail,
                    GameDefinitions = new List<GameDefinition>
                    {
                        new GameDefinition
                        {
                            PlayedGames = playedGames
                        }
                    }
                }
            }.AsQueryable();
            autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<BoardGameGeekGameDefinition>()).Return(boardGameGeekGameDefinitionQueryable);
            int expectedNumberOfGames = 2;

            var results = autoMocker.ClassUnderTest.GetTrendingGames(expectedNumberOfGames, 1);

            Assert.That(results[0].BoardGameGeekGameDefinitionId, Is.EqualTo(expectedBoardGameGeekGameDefinitionId1));
            Assert.That(results[0].BoardGameGeekUri, Is.EqualTo(BoardGameGeekUriBuilder.BuildBoardGameGeekGameUri(expectedBoardGameGeekGameDefinitionId1)));
            Assert.That(results[0].GamingGroupsPlayingThisGame, Is.EqualTo(1));
            Assert.That(results[0].GamesPlayed, Is.EqualTo(2));
            Assert.That(results[0].Name, Is.EqualTo(expectedName));
            Assert.That(results[0].ThumbnailImageUrl, Is.EqualTo(expectedThumbnail));
        }
        public void ItSetsAllTheFields()
        {
            autoMocker = new RhinoAutoMocker<PlayedGameRetriever>();

            var playedGame = new PlayedGame
            {
                Id = 1,
                DateCreated = new DateTime(2015, 11, 1, 2, 2, 2),
                DatePlayed = new DateTime(2015, 10, 1, 3, 3, 3),
                GameDefinitionId = 2,
                GamingGroupId = 3,
                Notes = "some notes",
                GamingGroup = new GamingGroup
                {
                    Name = "some gaming group name"
                },
                GameDefinition = new GameDefinition
                {
                    Name = "some game definition name",
                    BoardGameGeekGameDefinitionId = 4
                },
                ApplicationLinkages = new List<PlayedGameApplicationLinkage>()
            };

            var playerGameResult = new PlayerGameResult
            {
                GameRank = 1,
                PlayerId = 2,
                PointsScored = 50,
                Player = new Player
                {
                    Id = 100,
                    Name = "some player name"
                },
                PlayedGame = playedGame,
                NemeStatsPointsAwarded = 1,
                GameWeightBonusPoints = 2,
                GameDurationBonusPoints = 3
            };

            var playerGameResults = new List<PlayerGameResult>
            {
               playerGameResult
            };

            playedGame.PlayerGameResults = playerGameResults;

            playedGames = new List<PlayedGame>
            {
                playedGame
            };
            autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<PlayedGame>()).Return(playedGames.AsQueryable());

            var results = autoMocker.ClassUnderTest.SearchPlayedGames(new PlayedGameFilter()).First();

            Assert.That(results.PlayedGameId, Is.EqualTo(playedGame.Id));
            Assert.That(results.GameDefinitionName, Is.EqualTo(playedGame.GameDefinition.Name));
            Assert.That(results.GameDefinitionId, Is.EqualTo(playedGame.GameDefinitionId));
            Assert.That(results.DateLastUpdated, Is.EqualTo(playedGame.DateCreated));
            Assert.That(results.DatePlayed, Is.EqualTo(playedGame.DatePlayed));
            Assert.That(results.GamingGroupId, Is.EqualTo(playedGame.GamingGroupId));
            Assert.That(results.GamingGroupName, Is.EqualTo(playedGame.GamingGroup.Name));
            Assert.That(results.Notes, Is.EqualTo(playedGame.Notes));
            var actualPlayerResult = results.PlayerGameResults[0];
            var expectedPlayerGameResult = playedGame.PlayerGameResults[0];
            Assert.That(actualPlayerResult.GameRank, Is.EqualTo(expectedPlayerGameResult.GameRank));
            Assert.That(actualPlayerResult.NemeStatsPointsAwarded, Is.EqualTo(expectedPlayerGameResult.NemeStatsPointsAwarded));
            Assert.That(actualPlayerResult.GameDurationBonusNemePoints, Is.EqualTo(expectedPlayerGameResult.GameDurationBonusPoints));
            Assert.That(actualPlayerResult.GameWeightBonusNemePoints, Is.EqualTo(expectedPlayerGameResult.GameWeightBonusPoints));
            var expectedTotalPoints = expectedPlayerGameResult.NemeStatsPointsAwarded
                                      + expectedPlayerGameResult.GameDurationBonusPoints
                                      + expectedPlayerGameResult.GameWeightBonusPoints;
            Assert.That(actualPlayerResult.TotalPoints, Is.EqualTo(expectedTotalPoints));
            Assert.That(actualPlayerResult.PlayerId, Is.EqualTo(expectedPlayerGameResult.PlayerId));
            Assert.That(actualPlayerResult.PlayerName, Is.EqualTo(expectedPlayerGameResult.Player.Name));
            Assert.That(actualPlayerResult.PlayerActive, Is.EqualTo(expectedPlayerGameResult.Player.Active));
            Assert.That(actualPlayerResult.PointsScored, Is.EqualTo(expectedPlayerGameResult.PointsScored));
            Assert.That(actualPlayerResult.PlayedGameId, Is.EqualTo(expectedPlayerGameResult.PlayedGameId));
            Assert.That(actualPlayerResult.DatePlayed, Is.EqualTo(expectedPlayerGameResult.PlayedGame.DatePlayed));
            Assert.That(actualPlayerResult.GameName, Is.EqualTo(expectedPlayerGameResult.PlayedGame.GameDefinition.Name));
            Assert.That(actualPlayerResult.GameDefinitionId, Is.EqualTo(expectedPlayerGameResult.PlayedGame.GameDefinitionId));
        }
Example #44
0
        private void CleanupPlayerResultsAndApplicationLinkages(ApplicationUser currentUser, PlayedGame playedGameWithStuff)
        {
            foreach (var playerGameResult in playedGameWithStuff.PlayerGameResults.ToList())
            {
                _dataContext.DeleteById<PlayerGameResult>(playerGameResult.Id, currentUser);
            }

            foreach (var applicationLinkage in playedGameWithStuff.ApplicationLinkages.ToList())
            {
                _dataContext.DeleteById<PlayedGameApplicationLinkage>(applicationLinkage.Id, currentUser);
            }
        }
Example #45
0
        //TODO this should be in its own class or just in AutoMapperConfiguration
        internal virtual PlayedGame TransformNewlyCompletedGameIntoPlayedGame(
            SaveableGameBase savedGame,
            int gamingGroupId,
            string applicationUserId,
            List<PlayerGameResult> playerGameResults)
        {
            var winnerType = WinnerTypes.PlayerWin;

            if (playerGameResults.All(x => x.GameRank == 1))
            {
                winnerType = WinnerTypes.TeamWin;
            }
            else if (playerGameResults.All(x => x.GameRank > 1))
            {
                winnerType = WinnerTypes.TeamLoss;
            }

            var numberOfPlayers = savedGame.PlayerRanks.Count;
            var playedGame = new PlayedGame
            {
                GameDefinitionId = savedGame.GameDefinitionId,
                NumberOfPlayers = numberOfPlayers,
                WinnerType = winnerType,
                PlayerGameResults = playerGameResults,
                DatePlayed = savedGame.DatePlayed,
                GamingGroupId = gamingGroupId,
                Notes = savedGame.Notes,
                CreatedByApplicationUserId = applicationUserId
            };
            return playedGame;
        }
Example #46
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 void ExtractDistinctListOfPlayerIds(HashSet<int> distinctPlayerIds, PlayedGame playedGame)
 {
     foreach (var playerGameResult in playedGame.PlayerGameResults)
     {
         if (!distinctPlayerIds.Contains(playerGameResult.PlayerId))
         {
             distinctPlayerIds.Add(playerGameResult.PlayerId);
         }
     }
 }
        private void SetupExpectationsForExistingPlayedGame()
        {
            _existingGamingGroupId = currentUser.CurrentGamingGroupId;

            _existingPlayedGame = new PlayedGame
            {
                Id = 1,
                GamingGroupId = _existingGamingGroupId,
                GameDefinitionId = _existingGameDefinitionId,
                GameDefinition = new GameDefinition
                {
                    BoardGameGeekGameDefinitionId = _existingBoardGameGeekGameDefinitionId
                },
                PlayerGameResults = new List<PlayerGameResult>
                {
                    new PlayerGameResult
                    {
                        Id = _existingPlayerGameResultId1
                    },
                    new PlayerGameResult
                    {
                        Id = _existingPlayerGameResultId2
                    }
                },
                ApplicationLinkages = new List<PlayedGameApplicationLinkage>
                {
                    new PlayedGameApplicationLinkage
                    {
                        Id = _existingPlayedGameApplicationLinkageId1
                    },
                    new PlayedGameApplicationLinkage
                    {
                        Id = _existingPlayedGameApplicationLinkageId2
                    }
                }
            };

            var playedGameQueryable = new List<PlayedGame>
            {
                _existingPlayedGame
            }.AsQueryable();

            autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<PlayedGame>()).Return(playedGameQueryable);

            autoMocker.Get<ISecuredEntityValidator>().Expect(mock => mock.RetrieveAndValidateAccess<GamingGroup>(Arg<int>.Is.Anything, Arg<ApplicationUser>.Is.Anything))
                .Return(new GamingGroup());
            autoMocker.Get<ISecuredEntityValidator>().Expect(mock => mock.RetrieveAndValidateAccess<PlayedGame>(Arg<int>.Is.Anything, Arg<ApplicationUser>.Is.Anything))
                .Return(new PlayedGame());
            autoMocker.Get<ISecuredEntityValidator>().Expect(mock => mock.RetrieveAndValidateAccess<GameDefinition>(Arg<int>.Is.Anything, Arg<ApplicationUser>.Is.Anything))
                .Return(new GameDefinition());

            autoMocker.ClassUnderTest.Expect(partialMock => partialMock.ValidateAccessToPlayers(
                Arg<List<PlayerRank>>.Is.Anything,
                Arg<int>.Is.Anything,
                Arg<ApplicationUser>.Is.Anything));

            _expectedNewPlayerGameResults = new List<PlayerGameResult>
            {
                new PlayerGameResult(),
                new PlayerGameResult(),
                new PlayerGameResult()
            };

            autoMocker.ClassUnderTest.Expect(
                    partialMock =>
                            partialMock.MakePlayerGameResults(Arg<SaveableGameBase>.Is.Anything, Arg<int>.Is.Anything))
                .Return(_expectedNewPlayerGameResults);

            _expectedTransformedPlayedGame = new PlayedGame
            {
                Id = _existingPlayedGameId,
                GameDefinitionId = _existingGameDefinitionId
            };
            autoMocker.ClassUnderTest.Expect(
                    partialMock =>
                        partialMock.TransformNewlyCompletedGameIntoPlayedGame(Arg<SaveableGameBase>.Is.Anything, Arg<int>.Is.Anything,
                            Arg<string>.Is.Anything, Arg<List<PlayerGameResult>>.Is.Anything))
                .Return(_expectedTransformedPlayedGame);

            autoMocker.ClassUnderTest.Expect(partialMock => partialMock.DoPostSaveStuff(
                Arg<TransactionSource>.Is.Anything, 
                Arg<ApplicationUser>.Is.Anything, 
                Arg<int>.Is.Anything, 
                Arg<int>.Is.Anything, 
                Arg<List<PlayerGameResult>>.Is.Anything));

            _expectedSavedPlayedGame = new PlayedGame();
            autoMocker.Get<IDataContext>()
                .Expect(mock => mock.Save(Arg<PlayedGame>.Is.Anything, Arg<ApplicationUser>.Is.Anything))
                .Return(_expectedSavedPlayedGame);
        }