public bool Wins(Choices.Choice choice) { if (Choices.IsGreatest(choice)) { return(_choice < choice); } return(_choice > choice); }
public async void ChallengerShouldCooseInGame(string challengerName, Choices.Choice choice) { var ctx = Fixture.GameContext; var svc = new GameService(ctx); svc.Challenge(GameId, challengerName); bool chosen = svc.Choose(GameId, challengerName, choice); Assert.True(chosen); var actual = await ctx.Games.SingleAsync(g => g.Id.Equals(GameId)); Assert.True(Convert.ToInt32(choice) == actual.ChallengerChoice); }
public bool Choose(string id, string playerName, Choices.Choice choice) { var game = GetGame(id); if (!string.IsNullOrEmpty(game.Player) && game.Player.Equals(playerName, StringComparison.OrdinalIgnoreCase)) { game.PlayerChoice = Convert.ToInt32(choice); } else { game.ChallengerChoice = Convert.ToInt32(choice); } _context.Games.Update(game); _context.SaveChanges(); return(true); }
public void NoneSouldWinWhenDraw(Choices.Choice player, Choices.Choice challenger) { Assert.False(new PlayerChoice(player).Wins(challenger)); Assert.False(new PlayerChoice(challenger).Wins(player)); }
public void PlayerShouldLoseChallenger(Choices.Choice player, Choices.Choice challenger) { var challengerChoice = new PlayerChoice(challenger); Assert.True(challengerChoice.Wins(player)); }
public PlayerChoice(Choices.Choice choice) { _choice = choice; }
public IActionResult Challenge([FromRoute] string id, [FromRoute] Choices.Choice choice, [FromForm] string playerName) { _service.Choose(id, playerName, choice); return(new OkResult()); }