private async Task TestPlayerGetById() { var client = _factory.CreateClient(); var response = await client.GetAsync($"v1/Player/{SeedPlayerId.ToString()}"); Should.NotThrow(() => { response.EnsureSuccessStatusCode(); }); PlayerModelResponse player = null; Should.NotThrow(async() => { player = JsonSerializer.Deserialize <PlayerModelResponse>(await response.Content.ReadAsStringAsync(), _jsonSerializerOptions); }); player.ShouldNotBeNull(); player.Id.ShouldBe(SeedPlayerId); }
private async Task TestPlayerAdd() { var newPlayerGuid = Guid.NewGuid(); var json = JsonSerializer .Serialize(new PlayerAddRequest { TransactionId = newPlayerGuid, BirthDate = DateTime.Now.AddYears(-25), PlayerName = $"NewPlayer{new Random().Next(1000,9999)}" }); var requestModel = new StringContent(json, Encoding.UTF8, "application/json"); var client = _factory.CreateClient(); var response = await client.PostAsync("v1/Player/Add", requestModel); Should.NotThrow(() => { response.EnsureSuccessStatusCode(); }); response.StatusCode.ShouldBe(HttpStatusCode.Created); PlayerModelResponse player = null; Should.NotThrow(async() => { player = JsonSerializer.Deserialize <PlayerModelResponse>(await response.Content.ReadAsStringAsync(), _jsonSerializerOptions); }); player.ShouldNotBeNull(); player.Id.ShouldBe(newPlayerGuid); player.Repeated.ShouldBeFalse(); // repeated request var client2 = _factory.CreateClient(); var response2 = await client2.PostAsync("v1/Player/Add", requestModel); Should.NotThrow(() => { response2.EnsureSuccessStatusCode(); }); response2.StatusCode.ShouldBe(HttpStatusCode.OK); PlayerModelResponse player2 = null; Should.NotThrow(async() => { player2 = JsonSerializer.Deserialize <PlayerModelResponse>(await response2.Content.ReadAsStringAsync(), _jsonSerializerOptions); }); player2.ShouldNotBeNull(); player2.Id.ShouldBe(newPlayerGuid); player2.Repeated.ShouldBeTrue(); }