Skip to content

Commit

Permalink
use GetAllAsync extension method
Browse files Browse the repository at this point in the history
  • Loading branch information
Sevitas committed Mar 10, 2022
1 parent 56a5502 commit 4bdbbdb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
27 changes: 3 additions & 24 deletions src/Kentico.Kontent.ModelGenerator.Core/ManagementCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Threading.Tasks;
using Kentico.Kontent.Management;
using Kentico.Kontent.Management.Models.Shared;
using Kentico.Kontent.Management.Extenstions;
using Kentico.Kontent.Management.Models.Types;
using Kentico.Kontent.Management.Models.Types.Elements;
using Kentico.Kontent.Management.Models.TypeSnippets;
Expand Down Expand Up @@ -32,8 +32,8 @@ public ManagementCodeGenerator(IOptions<CodeGeneratorOptions> options, IOutputPr

protected override async Task<ICollection<ClassCodeGenerator>> GetClassCodeGenerators()
{
var managementTypes = await GetAllContentModelsAsync(await _managementClient.ListContentTypesAsync());
var managementSnippets = await GetAllContentModelsAsync(await _managementClient.ListContentTypeSnippetsAsync());
var managementTypes = await _managementClient.ListContentTypesAsync().GetAllAsync();
var managementSnippets = await _managementClient.ListContentTypeSnippetsAsync().GetAllAsync();

var codeGenerators = new List<ClassCodeGenerator>();
if (managementTypes == null || !managementTypes.Any())
Expand Down Expand Up @@ -92,26 +92,5 @@ internal ClassCodeGenerator GetClassCodeGenerator(ContentTypeModel contentType,

return ClassCodeGeneratorFactory.CreateClassCodeGenerator(Options, classDefinition, classFilename);
}

private static async Task<IEnumerable<T>> GetAllContentModelsAsync<T>(IListingResponseModel<T> response)
{
var contentModels = new List<T>();
while (true)
{
foreach (var model in response)
{
contentModels.Add(model);
}

if (!response.HasNextPage())
{
break;
}

response = await response.GetNextPage();
}

return contentModels.ToList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ private static IManagementClient CreateManagementClient()
var managementClientMock = new Mock<IManagementClient>();

var contentTypeListingResponseModel = new Mock<IListingResponseModel<ContentTypeModel>>();
contentTypeListingResponseModel
contentTypeListingResponseModel.As<IEnumerable<ContentTypeModel>>()
.Setup(c => c.GetEnumerator())
.Returns(managementModelsProvider.ManagementContentTypeModels);
.Returns(() => managementModelsProvider.ManagementContentTypeModels);

var contentTypeSnippetListingResponseModel = new Mock<IListingResponseModel<ContentTypeSnippetModel>>();
contentTypeSnippetListingResponseModel
contentTypeSnippetListingResponseModel.As<IEnumerable<ContentTypeSnippetModel>>()
.Setup(c => c.GetEnumerator())
.Returns(managementModelsProvider.ManagementContentTypeSnippetModels);
.Returns(() => managementModelsProvider.ManagementContentTypeSnippetModels);

managementClientMock.Setup(client => client.ListContentTypeSnippetsAsync())
.Returns(Task.FromResult(contentTypeSnippetListingResponseModel.Object));
Expand Down

0 comments on commit 4bdbbdb

Please sign in to comment.