public void ConvertJsonToPlayerModelResource()
        {
            string jsonText = "{\"href\":\"https://localhost:44340/api/players/11111111-1111-1111-1111-111111111111\",\"score\":1,\"xPosition\":10,\"zPosition\":100}";

            PlayerModelResource _dut = JsonUtility.FromJson <PlayerModelResource>(jsonText);

            Assert.AreEqual(1L, _dut.score);
            Assert.AreEqual(10, _dut.xPosition);
            Assert.AreEqual(100, _dut.zPosition);
        }
Esempio n. 2
0
        public async Task <IActionResult> CreatePlayerAsync(PlayerModelResource playerModelResource, CancellationToken ct)
        {
            var player = _context.Add(new PlayerModel()
            {
                Score     = playerModelResource.Score,
                XPosition = playerModelResource.XPosition,
                ZPosition = playerModelResource.ZPosition
            });

            var created = await _context.SaveChangesAsync(ct);

            if (created < 0)
            {
                throw new InvalidOperationException("Could not create the player.");
            }

            return(Created(Url.Link(nameof(UpdatePlayerAsync), new { player.Entity.Id }), player.Entity.Id));
        }
Esempio n. 3
0
        public async Task <IActionResult> GetPlayerAsync(Guid playerId, CancellationToken ct)
        {
            var entity = await _context.PlayerModel.SingleOrDefaultAsync(r => r.Id == playerId, ct);

            if (entity == null)
            {
                return(NotFound());
            }

            var player = new PlayerModelResource()
            {
                Href      = Url.Link(nameof(GetPlayerAsync), new { playerId = entity.Id }),
                Score     = entity.Score,
                XPosition = entity.XPosition,
                ZPosition = entity.ZPosition
            };

            return(Ok(player));
        }
Esempio n. 4
0
        public async Task <IActionResult> UpdatePlayerAsync(Guid newId, PlayerModelResource playerModelResource, CancellationToken ct)
        {
            var player = await _context.PlayerModel.SingleOrDefaultAsync(r => r.Id == newId);

            if (player == null)
            {
                return(new NotFoundResult());
            }

            player.Score     = playerModelResource.Score;
            player.XPosition = playerModelResource.XPosition;
            player.ZPosition = playerModelResource.ZPosition;

            var created = await _context.SaveChangesAsync(ct);

            if (created < 0)
            {
                throw new InvalidOperationException("Could not create the player.");
            }

            return(Created(Url.Link(nameof(UpdatePlayerAsync), new { newId }), null));
        }
Esempio n. 5
0
        public async void GetPlayerAsyncReturnsPlayerData()
        {
            // arrange
            var expPlayer = new PlayerModelResource()
            {
                Href      = GET_PLAYER_URL + PLAYER_ID + 1,
                Score     = 1,
                XPosition = 10,
                ZPosition = 100
            };

            // apply
            var res = await Controller.GetPlayerAsync(Guid.Parse(PLAYER_ID + 1), new CancellationToken());

            // assert
            Assert.IsType <OkObjectResult>(res);

            PlayerModelResource player = ((OkObjectResult)res).Value as PlayerModelResource;

            Assert.Equal(expPlayer.Href, player.Href);
            Assert.Equal(expPlayer.Score, player.Score);
            Assert.Equal(expPlayer.XPosition, player.XPosition);
            Assert.Equal(expPlayer.ZPosition, player.ZPosition);
        }
Esempio n. 6
0
 /// <summary>
 /// Initialize the test suite
 /// </summary>
 public PlayerModelResourceShould()
 {
     Model = new PlayerModelResource();
 }