Beispiel #1
0
        public static void TestDeserializeJSONUsersDTO()
        {
            using (StreamReader stream = new StreamReader($"{_baseDirectory}/resources/user-results-example.json"))
            {
                string json = stream.ReadToEnd();
                JSONUsersDTO deserializedJSON = JsonSerializer.Deserialize<JSONUsersDTO>(json);

                Assert.Single(deserializedJSON.Users);
            }
        }
        public async Task <IEnumerable <UserDTO> > LoadDataFromJSON()
        {
            Log.Information("Retrieving data from JSON...");
            HttpResponseMessage response = await _client.GetAsync("https://storage.googleapis.com/juntossomosmais-code-challenge/input-backend.json");

            Stream stream = await response.Content.ReadAsStreamAsync();

            JSONUsersDTO results = await JsonSerializer.DeserializeAsync <JSONUsersDTO>(stream);

            Log.Information("Successfully retrieved {Count} users from JSON.", results.Users.Count());
            return(results?.Users ?? new List <UserDTO>());
        }