public async Task GetMonsterFromDungeonById_HttpThrowsException_ThrowsException()
        {
            httpMessageHandlerMocked.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .ThrowsAsync(new Exception("Mock exception"));

            var client = new HttpClient(httpMessageHandlerMocked.Object)
            {
                BaseAddress = new Uri("http://test")
            };
            var service = new DungeonsApiService(client);

            await Assert.ThrowsAsync <Exception>(() => service.GetMonsterFromDungeonById("dungeon id", "monster id"));
        }
        public async Task GetMonsterFromDungeonById_ThrowsUnsuccessfulApiStatusCodeException()
        {
            var httpResponse = new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.BadRequest
            };

            mockHttpMessageHandler(httpResponse);

            var httpClient = new HttpClient(httpMessageHandlerMocked.Object)
            {
                BaseAddress = new Uri("http://test")
            };
            var service = new DungeonsApiService(httpClient);

            await Assert.ThrowsAsync <UnsuccessfullApiStatusCodeException>(() => service.GetMonsterFromDungeonById("dungeon id", "monster id"));
        }
        public async Task GetMonsterFromDungeonById_ReturnsWrongHttpContent_ThrowsJsonException()
        {
            string content = "different content than list<dungeonmonster>";

            var httpContent  = new StringContent(content);
            var httpResponse = new HttpResponseMessage
            {
                Content = httpContent
            };

            mockHttpMessageHandler(httpResponse);
            var client = new HttpClient(httpMessageHandlerMocked.Object)
            {
                BaseAddress = new Uri("http://test")
            };
            var service = new DungeonsApiService(client);

            await Assert.ThrowsAsync <JsonException>(() => service.GetMonsterFromDungeonById("dungeon id", "monster id"));
        }
        public async Task GetMonsterFromDungeonById_GetIds_ReturnsDungeonMonster()
        {
            var resultDungeonMonster = new DungeonMonster {
                Class = "some class", Constitution = "123", Dexterity = "444", DungeonNumber = 1, Experience = "12"
            };
            var resultListJson = JsonSerializer.Serialize(resultDungeonMonster);
            var httpContent    = new StringContent(resultListJson);
            var httpResponse   = new HttpResponseMessage()
            {
                Content = httpContent
            };

            mockHttpMessageHandler(httpResponse);
            var client = new HttpClient(httpMessageHandlerMocked.Object)
            {
                BaseAddress = new Uri("http://test")
            };

            var service = new DungeonsApiService(client);

            var result = await service.GetMonsterFromDungeonById("dungeon id", "monster id");

            Assert.True(result.Equals(resultDungeonMonster));
        }
 protected override async Task OnParametersSetAsync()
 {
     DungeonMonster = await DungeonsApiService.GetMonsterFromDungeonById(DungeonNumber, DungeonMonsterNumber);
 }