-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix stalling on PagedCollection, when value is empty but nextLink is …
…valid (#999) * fix stalling when values is empty but nextLink is valid * comments
- Loading branch information
1 parent
d44b63d
commit 53fd15e
Showing
2 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using Microsoft.Azure.KeyVault.Models; | ||
using Microsoft.Azure.Management.ResourceManager.Fluent.Core; | ||
using Microsoft.Rest.Azure; | ||
using Newtonsoft.Json; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Fluent.Tests | ||
{ | ||
// For serialzation to Page<T> | ||
[JsonObject] | ||
public class MockPage<T> | ||
{ | ||
[JsonProperty("nextLink")] | ||
public string NextPageLink { get; set; } | ||
|
||
[JsonProperty("value")] | ||
public IList<T> Items { get; set; } | ||
} | ||
|
||
public class PagedCollection | ||
{ | ||
[Fact] | ||
public void CanLoadEmptyPageWithNextLink() | ||
{ | ||
var taskLoadPage = PagedCollection<string, string>.LoadPage( | ||
// first page, valid nextLink | ||
(cancellation) => Task.FromResult(ConvertToPage(new MockPage<string> { Items = new List<string> { "1", "2" }, NextPageLink = "2" })), | ||
(nextLink, cancellation) => | ||
{ | ||
if (nextLink == "2") | ||
{ | ||
// empty values, valid nextLink | ||
return Task.FromResult(ConvertToPage(new MockPage<string> { Items = new List<string>(), NextPageLink = "3" })); | ||
} | ||
else if (nextLink == "3") | ||
{ | ||
// non-empty values, null nextLink | ||
return Task.FromResult(ConvertToPage(new MockPage<string> { Items = new List<string> { "3", "4", "5" }, NextPageLink = null })); | ||
} | ||
else | ||
{ | ||
Assert.False(true); | ||
return Task.FromResult(ConvertToPage(new MockPage<string> { Items = new List<string> (), NextPageLink = null })); | ||
} | ||
}, | ||
(str) => str, true, CancellationToken.None); | ||
|
||
Assert.Equal(new List<string> { "1", "2", "3", "4", "5" }, taskLoadPage.Result); | ||
} | ||
|
||
private static IPage<T> ConvertToPage<T>(MockPage<T> mockPage) | ||
{ | ||
return Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<T>>(Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(mockPage)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters