public void getUsersTest() { var responseString = ApiUtils.getAllRequest(apiEndPoint + "/users"); IList <Data> dataList = JsonConvert.DeserializeObject <IList <Data> >(responseString); Console.WriteLine("----------------------dataList " + dataList); Assert.NotNull(dataList); Assert.That(dataList, Is.InstanceOf <IList <Data> >()); IList <int> idList = new List <int>(); Dictionary <int, Data> apiUserDictionary = new Dictionary <int, Data>(); foreach (Data data in dataList) { // add the ids tothe idList to query the users from the database idList.Add(data.id); // add an id and the corresponding data object to the dictionary // This dictionary is useful when we want to compare the objects returned from the database // and the objects returned from the API based on the id. By using the TryGetValue method, a particular // object can be extracted from the apiUserDictionary apiUserDictionary.Add(data.id, data); } IList <Data> userList = DatabaseUtils.getUsers(idList); foreach (Data dbUser in userList) { //For the given dbUser find out the corresponding apiUser Data apiUser = apiUserDictionary[dbUser.id]; Assert.NotNull(apiUser); Assert.That(apiUser.id, Is.EqualTo(dbUser.id), "api id and database id are not same"); Assert.That(apiUser.email, Is.EqualTo(dbUser.email), "api email and database email are not same"); Assert.That(apiUser.first_name, Is.EqualTo(dbUser.first_name), "api first_name and database first_name are not same"); Assert.That(apiUser.last_name, Is.EqualTo(dbUser.last_name), "api last_name and database last_name are not same"); Assert.That(apiUser.avatar, Is.EqualTo(dbUser.avatar), "api avatar and database avatar are not same"); } }