示例#1
0
 public bool Wins(Choices.Choice choice)
 {
     if (Choices.IsGreatest(choice))
     {
         return(_choice < choice);
     }
     return(_choice > choice);
 }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
 public void NoneSouldWinWhenDraw(Choices.Choice player, Choices.Choice challenger)
 {
     Assert.False(new PlayerChoice(player).Wins(challenger));
     Assert.False(new PlayerChoice(challenger).Wins(player));
 }
示例#5
0
        public void PlayerShouldLoseChallenger(Choices.Choice player, Choices.Choice challenger)
        {
            var challengerChoice = new PlayerChoice(challenger);

            Assert.True(challengerChoice.Wins(player));
        }
示例#6
0
 public PlayerChoice(Choices.Choice choice)
 {
     _choice = choice;
 }
示例#7
0
 public IActionResult Challenge([FromRoute] string id, [FromRoute] Choices.Choice choice, [FromForm] string playerName)
 {
     _service.Choose(id, playerName, choice);
     return(new OkResult());
 }