Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Communication] - PhoneNumberAdministrationClient - fix next page #17283

Merged
merged 15 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 1.0.0-beta.4 (Unreleased)

### Fixed
- Issue with paging results not pulling next pages
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this 👍



## 1.0.0-beta.3 (2020-11-16)

Expand Down Expand Up @@ -40,6 +43,7 @@
- Replaced `ReleasePhoneNumbersAsync` with `StartReleasePhoneNumbersAsync` which returns a poller for the long-running operation.
- Replaced `ReleasePhoneNumbers` with `StartReleasePhoneNumbers` which is a long-running operation.


## 1.0.0-beta.2 (2020-10-06)
Added phone number administration. For more information, please see the [README][read_me] and [documentation][documentation].

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ public virtual AsyncPageable<AcquiredPhoneNumber> GetAllPhoneNumbersAsync(string

try
{
return PageResponseEnumerator.CreateAsyncEnumerable(async s =>
return PageResponseEnumerator.CreateAsyncEnumerable(async nextLink =>
{
Response<AcquiredPhoneNumbers> response = await RestClient.GetAllPhoneNumbersAsync(locale, skip: null, take: null, cancellationToken).ConfigureAwait(false);
return Page.FromValues(response.Value.PhoneNumbers, continuationToken: null!, response.GetRawResponse());
Response<AcquiredPhoneNumbers> response = string.IsNullOrEmpty(nextLink)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can just do the null check instead nextLink is null

? await RestClient.GetAllPhoneNumbersAsync(locale, skip: null, take: null, cancellationToken).ConfigureAwait(false)
: await RestClient.GetAllPhoneNumbersNextPageAsync(nextLink, locale, skip: null, take: null, cancellationToken).ConfigureAwait(false);

return Page.FromValues(response.Value.PhoneNumbers, response.Value.NextLink, response.GetRawResponse());
});
}
catch (Exception ex)
Expand All @@ -89,8 +92,14 @@ public virtual Pageable<AcquiredPhoneNumber> GetAllPhoneNumbers(string? locale =

try
{
Response<AcquiredPhoneNumbers> response = RestClient.GetAllPhoneNumbers(locale, skip: null, take: null, cancellationToken);
return PageResponseEnumerator.CreateEnumerable(s => Page.FromValues(response.Value.PhoneNumbers, continuationToken: null!, response.GetRawResponse()));
return PageResponseEnumerator.CreateEnumerable(nextLink =>
{
Response<AcquiredPhoneNumbers> response = string.IsNullOrEmpty(nextLink)
? RestClient.GetAllPhoneNumbers(locale, skip: null, take: null, cancellationToken)
: RestClient.GetAllPhoneNumbersNextPage(nextLink, locale, skip: null, take: null, cancellationToken);

return Page.FromValues(response.Value.PhoneNumbers, response.Value.NextLink, response.GetRawResponse());
});
}
catch (Exception ex)
{
Expand Down Expand Up @@ -229,10 +238,13 @@ public virtual AsyncPageable<PhoneNumberCountry> GetAllSupportedCountriesAsync(s
scope.Start();
try
{
return PageResponseEnumerator.CreateAsyncEnumerable(async s =>
return PageResponseEnumerator.CreateAsyncEnumerable(async nextLink =>
{
Response<PhoneNumberCountries> response = await RestClient.GetAllSupportedCountriesAsync(locale, skip: null, take: null, cancellationToken).ConfigureAwait(false);
return Page.FromValues(response.Value.Countries, continuationToken: null!, response.GetRawResponse());
Response<PhoneNumberCountries> response = string.IsNullOrEmpty(nextLink)
? await RestClient.GetAllSupportedCountriesAsync(locale, skip: null, take: null, cancellationToken).ConfigureAwait(false)
: await RestClient.GetAllSupportedCountriesNextPageAsync(nextLink, locale, skip: null, take: null, cancellationToken).ConfigureAwait(false);

return Page.FromValues(response.Value.Countries, response.Value.NextLink, response.GetRawResponse());
});
}
catch (Exception ex)
Expand All @@ -252,8 +264,14 @@ public virtual Pageable<PhoneNumberCountry> GetAllSupportedCountries(string? loc
scope.Start();
try
{
Response<PhoneNumberCountries> response = RestClient.GetAllSupportedCountries(locale, skip: null, take: null, cancellationToken);
return PageResponseEnumerator.CreateEnumerable(s => Page.FromValues(response.Value.Countries, continuationToken: null!, response.GetRawResponse()));
return PageResponseEnumerator.CreateEnumerable(nextLink =>
{
Response<PhoneNumberCountries> response = string.IsNullOrEmpty(nextLink)
? RestClient.GetAllSupportedCountries(locale, skip: null, take: null, cancellationToken)
: RestClient.GetAllSupportedCountriesNextPage(nextLink, locale, skip: null, take: null, cancellationToken);

return Page.FromValues(response.Value.Countries, response.Value.NextLink, response.GetRawResponse());
});
}
catch (Exception ex)
{
Expand Down Expand Up @@ -390,10 +408,13 @@ public virtual AsyncPageable<PhonePlanGroup> GetPhonePlanGroupsAsync(string coun
scope.Start();
try
{
return PageResponseEnumerator.CreateAsyncEnumerable(async s =>
return PageResponseEnumerator.CreateAsyncEnumerable(async nextLink =>
{
Response<PhonePlanGroups> response = await RestClient.GetPhonePlanGroupsAsync(countryCode, locale, includeRateInformation, skip: null, take: null, cancellationToken).ConfigureAwait(false);
return Page.FromValues(response.Value.PhonePlanGroupsValue, continuationToken: null!, response.GetRawResponse());
Response<PhonePlanGroups> response = string.IsNullOrEmpty(nextLink)
? await RestClient.GetPhonePlanGroupsAsync(countryCode, locale, includeRateInformation, skip: null, take: null, cancellationToken).ConfigureAwait(false)
: await RestClient.GetPhonePlanGroupsNextPageAsync(nextLink, countryCode, locale, includeRateInformation, skip: null, take: null, cancellationToken).ConfigureAwait(false);

return Page.FromValues(response.Value.PhonePlanGroupsValue, response.Value.NextLink, response.GetRawResponse());
});
}
catch (Exception ex)
Expand All @@ -415,8 +436,14 @@ public virtual Pageable<PhonePlanGroup> GetPhonePlanGroups(string countryCode, s
scope.Start();
try
{
Response<PhonePlanGroups> response = RestClient.GetPhonePlanGroups(countryCode, locale, includeRateInformation, skip: null, take: null, cancellationToken);
return PageResponseEnumerator.CreateEnumerable(s => Page.FromValues(response.Value.PhonePlanGroupsValue, continuationToken: null!, response.GetRawResponse()));
return PageResponseEnumerator.CreateEnumerable(nextLink =>
{
Response<PhonePlanGroups> response = string.IsNullOrEmpty(nextLink)
? RestClient.GetPhonePlanGroups(countryCode, locale, includeRateInformation, skip: null, take: null, cancellationToken)
: RestClient.GetPhonePlanGroupsNextPage(nextLink, countryCode, locale, includeRateInformation, skip: null, take: null, cancellationToken);

return Page.FromValues(response.Value.PhonePlanGroupsValue, response.Value.NextLink, response.GetRawResponse());
});
}
catch (Exception ex)
{
Expand All @@ -437,10 +464,13 @@ public virtual AsyncPageable<PhonePlan> GetPhonePlansAsync(string countryCode, s
scope.Start();
try
{
return PageResponseEnumerator.CreateAsyncEnumerable(async s =>
return PageResponseEnumerator.CreateAsyncEnumerable(async nextLink =>
{
Response<PhonePlansResponse> response = await RestClient.GetPhonePlansAsync(countryCode, phonePlanGroupId, locale, skip: null, take: null, cancellationToken).ConfigureAwait(false);
return Page.FromValues(response.Value.PhonePlans, continuationToken: null!, response.GetRawResponse());
Response<PhonePlansResponse> response = string.IsNullOrEmpty(nextLink)
? await RestClient.GetPhonePlansAsync(countryCode, phonePlanGroupId, locale, skip: null, take: null, cancellationToken).ConfigureAwait(false)
: await RestClient.GetPhonePlansNextPageAsync(nextLink, countryCode, phonePlanGroupId, locale, skip: null, take: null, cancellationToken).ConfigureAwait(false);

return Page.FromValues(response.Value.PhonePlans, response.Value.NextLink, response.GetRawResponse());
});
}
catch (Exception ex)
Expand All @@ -462,8 +492,14 @@ public virtual Pageable<PhonePlan> GetPhonePlans(string countryCode, string phon
scope.Start();
try
{
Response<PhonePlansResponse> response = RestClient.GetPhonePlans(countryCode, phonePlanGroupId, locale, skip: null, take: null, cancellationToken);
return PageResponseEnumerator.CreateEnumerable(s => Page.FromValues(response.Value.PhonePlans, continuationToken: null!, response.GetRawResponse()));
return PageResponseEnumerator.CreateEnumerable(nextLink =>
{
Response<PhonePlansResponse> response = string.IsNullOrEmpty(nextLink)
? RestClient.GetPhonePlans(countryCode, phonePlanGroupId, locale, skip: null, take: null, cancellationToken)
: RestClient.GetPhonePlansNextPage(nextLink, countryCode, phonePlanGroupId, locale, skip: null, take: null, cancellationToken);

return Page.FromValues(response.Value.PhonePlans, response.Value.NextLink, response.GetRawResponse());
});
}
catch (Exception ex)
{
Expand Down Expand Up @@ -649,10 +685,12 @@ public virtual AsyncPageable<PhoneNumberEntity> GetAllReleasesAsync(Cancellation
scope.Start();
try
{
return PageResponseEnumerator.CreateAsyncEnumerable(async s =>
return PageResponseEnumerator.CreateAsyncEnumerable(async nextLink =>
{
Response<PhoneNumberEntities> response = await RestClient.GetAllReleasesAsync(skip: null, take: null, cancellationToken).ConfigureAwait(false);
return Page.FromValues(response.Value.Entities, continuationToken: null!, response.GetRawResponse());
Response<PhoneNumberEntities> response = string.IsNullOrEmpty(nextLink)
? await RestClient.GetAllReleasesAsync(skip: null, take: null, cancellationToken).ConfigureAwait(false)
: await RestClient.GetAllReleasesNextPageAsync(nextLink, skip: null, take: null, cancellationToken).ConfigureAwait(false);
return Page.FromValues(response.Value.Entities, response.Value.NextLink, response.GetRawResponse());
});
}
catch (Exception ex)
Expand All @@ -671,8 +709,14 @@ public virtual Pageable<PhoneNumberEntity> GetAllReleases(CancellationToken canc
scope.Start();
try
{
Response<PhoneNumberEntities> response = RestClient.GetAllReleases(skip: null, take: null, cancellationToken);
return PageResponseEnumerator.CreateEnumerable(s => Page.FromValues(response.Value.Entities, continuationToken: null!, response.GetRawResponse()));
return PageResponseEnumerator.CreateEnumerable(nextLink =>
{
Response<PhoneNumberEntities> response = string.IsNullOrEmpty(nextLink)
? RestClient.GetAllReleases(skip: null, take: null, cancellationToken)
: RestClient.GetAllReleasesNextPage(nextLink, skip: null, take: null, cancellationToken);

return Page.FromValues(response.Value.Entities, response.Value.NextLink, response.GetRawResponse());
});
}
catch (Exception ex)
{
Expand Down Expand Up @@ -776,10 +820,13 @@ public virtual AsyncPageable<PhoneNumberEntity> GetAllReservationsAsync(Cancella
scope.Start();
try
{
return PageResponseEnumerator.CreateAsyncEnumerable(async s =>
return PageResponseEnumerator.CreateAsyncEnumerable(async nextLink =>
{
Response<PhoneNumberEntities> response = await RestClient.GetAllSearchesAsync(skip: null, take: null, cancellationToken).ConfigureAwait(false);
return Page.FromValues(response.Value.Entities, continuationToken: null!, response.GetRawResponse());
Response<PhoneNumberEntities> response = string.IsNullOrEmpty(nextLink)
? await RestClient.GetAllSearchesAsync(skip: null, take: null, cancellationToken).ConfigureAwait(false)
: await RestClient.GetAllSearchesNextPageAsync(nextLink, skip: null, take: null, cancellationToken).ConfigureAwait(false);

return Page.FromValues(response.Value.Entities, response.Value.NextLink, response.GetRawResponse());
});
}
catch (Exception ex)
Expand All @@ -798,8 +845,14 @@ public virtual Pageable<PhoneNumberEntity> GetAllReservations(CancellationToken
scope.Start();
try
{
Response<PhoneNumberEntities> response = RestClient.GetAllSearches(skip: null, take: null, cancellationToken);
return PageResponseEnumerator.CreateEnumerable(s => Page.FromValues(response.Value.Entities, continuationToken: null!, response.GetRawResponse()));
return PageResponseEnumerator.CreateEnumerable(nextLink =>
{
Response<PhoneNumberEntities> response = string.IsNullOrEmpty(nextLink)
? RestClient.GetAllSearches(skip: null, take: null, cancellationToken)
: RestClient.GetAllSearchesNextPage(nextLink, skip: null, take: null, cancellationToken);

return Page.FromValues(response.Value.Entities, response.Value.NextLink, response.GetRawResponse());
});
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ public async Task GetAllPhoneNumbers()
Assert.IsNotNull(numbers);
}

[Test]
public async Task GetAllReservations()
{
var client = CreateClient();

var reservationsPagable = client.GetAllReservationsAsync();
var reservations = await reservationsPagable.ToEnumerableAsync();

Assert.IsNotEmpty(reservations);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we guarantee that this is not empty on a fresh created resource and where we can't guarantee the order in which the tests execute?

Consider IsNotNull if we're not sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added CreateReservation step to the test so there will be at least one reservation

}

[Test]
[TestCase(null, null)]
[TestCase("en-US", null)]
Expand Down
Loading