Skip to content

Commit

Permalink
[Communication] - PhoneNumberAdministrationClient - fix next page (Az…
Browse files Browse the repository at this point in the history
…ure#17283)

Fix communication admin Pageable results issue not pulling next page
  • Loading branch information
pavelprystinka authored and annelo-msft committed Feb 17, 2021
1 parent facb30b commit 7057368
Show file tree
Hide file tree
Showing 6 changed files with 3,168 additions and 428 deletions.
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


## 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 = 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 = nextLink is null
? 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 = nextLink is null
? 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 = nextLink is null
? 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 = nextLink is null
? 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 = nextLink is null
? 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 = nextLink is null
? 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 = nextLink is null
? 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 = nextLink is null
? 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 = nextLink is null
? 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 = nextLink is null
? 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 = nextLink is null
? 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,36 @@ public async Task GetAllPhoneNumbers()
Assert.IsNotNull(numbers);
}

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

const string locale = "en-US";
const string countryCode = "US";

var pageablePhonePlanGroups = client.GetPhonePlanGroupsAsync(countryCode, locale);
var phonePlanGroups = await pageablePhonePlanGroups.ToEnumerableAsync().ConfigureAwait(false);

string phonePlanGroupId = phonePlanGroups.First(group => group.PhoneNumberType == PhoneNumberType.TollFree).PhonePlanGroupId;
var pageablePhonePlans = client.GetPhonePlansAsync(countryCode, phonePlanGroupId, locale);
var phonePlan = (await pageablePhonePlans.ToEnumerableAsync()).First();
var areaCode = phonePlan.AreaCodes.First();

var reservationOptions = new CreateReservationOptions("My reservation", "my description", new[] { phonePlan.PhonePlanId }, areaCode);
reservationOptions.Quantity = 1;
var reservationOperation = await client.StartReservationAsync(reservationOptions);

await reservationOperation.WaitForCompletionAsync().ConfigureAwait(false);

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

Assert.IsNotEmpty(reservations);
}

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

0 comments on commit 7057368

Please sign in to comment.