private static void ValidateGameDefinitionIsNotNull(PlayerGameResult playerGameResult) { if (playerGameResult.PlayedGame.GameDefinition == null) { throw new ArgumentException(EXCEPTION_GAME_DEFINITION_CANNOT_BE_NULL); } }
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); }
private static void Validate(PlayerGameResult playerGameResult) { ValidatePlayerGameResultIsNotNull(playerGameResult); ValidatePlayerIsNotNull(playerGameResult); ValidatePlayedGameIsNotNull(playerGameResult); ValidateGameDefinitionIsNotNull(playerGameResult); }
public GameResultViewModel Build(PlayerGameResult playerGameResult, bool showPointsScored = false) { Validate(playerGameResult); GameResultViewModel result = new GameResultViewModel { PlayerId = playerGameResult.PlayerId, PlayerName = PlayerNameBuilder.BuildPlayerName(playerGameResult.Player.Name, playerGameResult.Player.Active), PointsScored = playerGameResult.PointsScored, GameRank = playerGameResult.GameRank, NemePointsSummary = new NemePointsSummaryViewModel(playerGameResult.NemeStatsPointsAwarded, playerGameResult.GameDurationBonusPoints, playerGameResult.GameWeightBonusPoints), GameDefinitionId = playerGameResult.PlayedGame.GameDefinition.Id, GameDefinitionName = playerGameResult.PlayedGame.GameDefinition.Name, PlayedGameId = playerGameResult.PlayedGameId, DatePlayed = playerGameResult.PlayedGame.DatePlayed, BoardGameGeekUri = BoardGameGeekUriBuilder.BuildBoardGameGeekGameUri(playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinitionId), WinnerType = playerGameResult.PlayedGame.WinnerType, ShowPointsScored = showPointsScored }; if (playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinition != null) { result.ThumbnailImageUrl = playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinition.Thumbnail; result.ImageUrl = playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinition.Image; } return(result); }
private static void ValidatePlayerGameResultIsNotNull(PlayerGameResult playerGameResult) { if (playerGameResult == null) { throw new ArgumentNullException("playerGameResult"); } }
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); }
private static void ValidatePlayedGameIsNotNull(PlayerGameResult playerGameResult) { if (playerGameResult.PlayedGame == null) { throw new ArgumentException(EXCEPTION_PLAYED_GAME_CANNOT_BE_NULL); } }
public GameResultViewModel Build(PlayerGameResult playerGameResult, bool showPointsScored = false) { Validate(playerGameResult); GameResultViewModel result = new GameResultViewModel { PlayerId = playerGameResult.PlayerId, PlayerName = PlayerNameBuilder.BuildPlayerName(playerGameResult.Player.Name, playerGameResult.Player.Active), PointsScored = playerGameResult.PointsScored, GameRank = playerGameResult.GameRank, NemePointsSummary = new NemePointsSummaryViewModel(playerGameResult.NemeStatsPointsAwarded, playerGameResult.GameDurationBonusPoints, playerGameResult.GameWeightBonusPoints), GameDefinitionId = playerGameResult.PlayedGame.GameDefinition.Id, GameDefinitionName = playerGameResult.PlayedGame.GameDefinition.Name, PlayedGameId = playerGameResult.PlayedGameId, DatePlayed = playerGameResult.PlayedGame.DatePlayed, BoardGameGeekUri = BoardGameGeekUriBuilder.BuildBoardGameGeekGameUri(playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinitionId), WinnerType = playerGameResult.PlayedGame.WinnerType, ShowPointsScored = showPointsScored }; if(playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinition != null) { result.ThumbnailImageUrl = playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinition.Thumbnail; result.ImageUrl = playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinition.Image; } return result; }
public void ItRequiresAPlayerOnThePlayedGameResult() { PlayerGameResult playerGameResultWithNoPlayer = new PlayerGameResult(); var exception = Assert.Throws <ArgumentException>(() => builder.Build(playerGameResultWithNoPlayer) ); Assert.AreEqual(GameResultViewModelBuilder.EXCEPTION_PLAYER_CANNOT_BE_NULL, exception.Message); }
public void ItRequiresAPlayerOnThePlayedGameResult() { PlayerGameResult playerGameResultWithNoPlayer = new PlayerGameResult(); var exception = Assert.Throws<ArgumentException>(() => builder.Build(playerGameResultWithNoPlayer) ); Assert.AreEqual(GameResultViewModelBuilder.EXCEPTION_PLAYER_CANNOT_BE_NULL, exception.Message); }
public void ItRequiresAGameDefinitionOnThePlayedGameResult() { PlayerGameResult playerGameResultWithNoGameDefinition = new PlayerGameResult() { Player = new Player(), PlayedGame = new PlayedGame() }; var exception = Assert.Throws <ArgumentException>(() => builder.Build(playerGameResultWithNoGameDefinition) ); Assert.AreEqual(GameResultViewModelBuilder.EXCEPTION_GAME_DEFINITION_CANNOT_BE_NULL, exception.Message); }
public GameResultViewModel Build(PlayerGameResult playerGameResult) { Validate(playerGameResult); GameResultViewModel result = new GameResultViewModel(); result.PlayerId = playerGameResult.PlayerId; result.PlayerName = playerGameResult.Player.Name; result.GameRank = playerGameResult.GameRank; result.NemeStatsPointsAwarded = playerGameResult.NemeStatsPointsAwarded; result.GameDefinitionId = playerGameResult.PlayedGame.GameDefinition.Id; result.GameDefinitionName = playerGameResult.PlayedGame.GameDefinition.Name; result.PlayedGameId = playerGameResult.PlayedGameId; result.DatePlayed = playerGameResult.PlayedGame.DatePlayed; result.BoardGameGeekUri = BoardGameGeekUriBuilder.BuildBoardGameGeekGameUri( playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinitionId); if (playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinition != null) { result.ThumbnailImageUrl = playerGameResult.PlayedGame.GameDefinition.BoardGameGeekGameDefinition.Thumbnail; } return(result); }
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)); }
public void SetUp() { //--reset the base one because it has crappy expectations autoMocker = new RhinoAutoMocker <PlayerRetriever>(); var playedGame = new PlayedGame { GamingGroupId = _gamingGroupId, }; _firstExpectedPlayerGameResult = new PlayerGameResult { PlayedGameId = _playedGameId, PlayerId = 1, Player = new Player { Name = "aaa - player 1 name" }, GameRank = 2, PlayedGame = playedGame }; _secondExpectedPlayerGameResult = new PlayerGameResult { PlayedGameId = _playedGameId, PlayerId = 2, Player = new Player { Name = "bbb - player 2 name", //--inactive players are allowed to get pulled Active = false }, GameRank = 1, PlayedGame = playedGame }; var playerGameResults = new List <PlayerGameResult> { _secondExpectedPlayerGameResult, _firstExpectedPlayerGameResult, //--result that will be excluded due to playedGameId new PlayerGameResult { PlayedGameId = -1, } }; autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <PlayerGameResult>()) .Return(playerGameResults.AsQueryable()); _firstExpectedPlayer = new Player { Id = 10, Name = "aaa - player 1", GamingGroupId = _gamingGroupId, Active = true }; _secondExpectedPlayer = new Player { Id = 20, Name = "bbb - player 2", GamingGroupId = _gamingGroupId, Active = true }; var players = new List <Player> { _secondExpectedPlayer, _firstExpectedPlayer, //--exclude because of bad gaming group id new Player { GamingGroupId = -1 }, //--exclude because of inactive new Player { GamingGroupId = _gamingGroupId, Active = false }, //--exclude because player was already in "recent players" new Player { GamingGroupId = _gamingGroupId, Id = _firstExpectedPlayerGameResult.PlayerId }, }; autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Player>()).Return(players.AsQueryable()); }
public void SetUp() { _autoMocker = new RhinoAutoMocker <PlayedGameRetriever>(); _currentUser = new ApplicationUser(); _expectedPlayerGameResult1 = new PlayerGameResult { GameRank = 1, PlayerId = 5, PointsScored = 6, Player = new Player { Name = "player 1" } }; _expectedPlayerGameResult2 = new PlayerGameResult { GameRank = 2, PlayerId = 7, PointsScored = 3, Player = new Player { Name = "player 2" } }; _expectedPlayedGame = new PlayedGame { Id = _playedGameId, DatePlayed = DateTime.Now, Notes = "some notes", GameDefinitionId = 2, GameDefinition = new GameDefinition { Name = "some game definition name", BoardGameGeekGameDefinitionId = 4 }, PlayerGameResults = new List <PlayerGameResult> { _expectedPlayerGameResult2, _expectedPlayerGameResult1 } }; var playedGamesQueryable = new List <PlayedGame> { _expectedPlayedGame }.AsQueryable(); _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <PlayedGame>()) .Return(playedGamesQueryable); _expectedHomePagePlayerSummary = new HomePagePlayerSummary(); _autoMocker.Get <IHomePagePlayerSummaryRetriever>().Expect(mock => mock.GetHomePagePlayerSummaryForUser(Arg <string> .Is.Anything, Arg <int> .Is.Anything)) .Return(_expectedHomePagePlayerSummary); _expectedPlayersToCreateModel = new PlayersToCreateModel { UserPlayer = new PlayerInfoForUser(), RecentPlayers = new List <PlayerInfoForUser>(), OtherPlayers = new List <PlayerInfoForUser>() }; _autoMocker.Get <IPlayerRetriever>().Expect(mock => mock.GetPlayersForEditingPlayedGame(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything)) .Return(_expectedPlayersToCreateModel); }
private void white_OnGameOver(PlayerGameResult result) { RepaintBoard(); //System.Threading.Thread.Sleep(100); this.Refresh(); //MessageBox.Show(result ? "Player 1 Win!" : "Player 2 Win!"); }
private void black_OnGameOver(PlayerGameResult result) { RepaintBoard(); //System.Threading.Thread.Sleep(100); this.Refresh(); if (result == PlayerGameResult.Draw) MessageBox.Show("Draw"); else MessageBox.Show(result == PlayerGameResult.Win ? "Player 2 Win!" : "Player 1 Win!"); }
public void GameOver(PlayerGameResult result) { if (OnGameOver!=null) OnGameOver(result); }
public static PlayerGameResult ConvertPlayerGameResult(int i) { return(PlayerGameResult.GetPlayerGameResult(i)); }
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 } }; var playerGameResult = new PlayerGameResult { GameRank = 1, PlayerId = 2, PointsScored = 50, Player = new Player { Id = 100, Name = "some player name" }, PlayedGame = playedGame }; 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.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)); }
public void ItRequiresAGameDefinitionOnThePlayedGameResult() { PlayerGameResult playerGameResultWithNoGameDefinition = new PlayerGameResult() { Player = new Player(), PlayedGame = new PlayedGame() }; var exception = Assert.Throws<ArgumentException>(() => builder.Build(playerGameResultWithNoGameDefinition) ); Assert.AreEqual(GameResultViewModelBuilder.EXCEPTION_GAME_DEFINITION_CANNOT_BE_NULL, exception.Message); }