Пример #1
0
        public void TestDtoMappingWithNull()
        {
            var dto = new StoryDto()
            {
                By = "test", Id = 122, Score = 1, Time = 1570887781, Descendants = 123, Title = "test", Type = "Post", Url = "test url", Kids = null
            };
            var story = StoryDto.ConvertToStory(dto);

            Assert.AreEqual(story.CommentCount, 0);
        }
Пример #2
0
        public void TestDtoMapping()
        {
            var kids = new List <int>()
            {
                2, 3, 7
            };
            var dto = new StoryDto()
            {
                By = "test", Id = 122, Score = 1, Time = 1570887781, Descendants = 123, Title = "test", Type = "Post", Url = "test url", Kids = kids
            };
            var story = StoryDto.ConvertToStory(dto);

            Assert.AreEqual(story.PostedBy, dto.By);
        }
Пример #3
0
        public async Task <Story> GetSingleStorie(int id)
        {
            var url = $"https://hacker-news.firebaseio.com/v0/item/{id}.json";
            HttpResponseMessage response = await _client.GetAsync(url);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var dto   = JsonConvert.DeserializeObject <StoryDto>(json);
                var story = StoryDto.ConvertToStory(dto);
                return(story);
            }
            return(new Story());
        }