From b9532af366614a60b49cea2e28a0d9c0574a7f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0ev=C4=8D=C3=ADk?= Date: Thu, 14 Apr 2022 10:59:17 +0200 Subject: [PATCH] 145 fix custom partial generation --- .../Common/ClassCodeGeneratorFactory.cs | 8 +++--- .../Common/ClassCodeGeneratorFactoryTests.cs | 25 ++++--------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/Kentico.Kontent.ModelGenerator.Core/Common/ClassCodeGeneratorFactory.cs b/src/Kentico.Kontent.ModelGenerator.Core/Common/ClassCodeGeneratorFactory.cs index a83c0ba3..8302a80b 100644 --- a/src/Kentico.Kontent.ModelGenerator.Core/Common/ClassCodeGeneratorFactory.cs +++ b/src/Kentico.Kontent.ModelGenerator.Core/Common/ClassCodeGeneratorFactory.cs @@ -23,13 +23,13 @@ public static ClassCodeGenerator CreateClassCodeGenerator(CodeGeneratorOptions o throw new ArgumentNullException(nameof(classFilename)); } - if (options.ManagementApi) + if (customPartial) { - return new ManagementClassCodeGenerator(classDefinition, classFilename, options.Namespace); + return new PartialClassCodeGenerator(classDefinition, classFilename, options.Namespace); } - return customPartial - ? new PartialClassCodeGenerator(classDefinition, classFilename, options.Namespace) + return options.ManagementApi + ? new ManagementClassCodeGenerator(classDefinition, classFilename, options.Namespace) : new DeliveryClassCodeGenerator(classDefinition, classFilename, options.Namespace); } } diff --git a/test/Kentico.Kontent.ModelGenerator.Tests/Common/ClassCodeGeneratorFactoryTests.cs b/test/Kentico.Kontent.ModelGenerator.Tests/Common/ClassCodeGeneratorFactoryTests.cs index 2e727ee7..bc9664b1 100644 --- a/test/Kentico.Kontent.ModelGenerator.Tests/Common/ClassCodeGeneratorFactoryTests.cs +++ b/test/Kentico.Kontent.ModelGenerator.Tests/Common/ClassCodeGeneratorFactoryTests.cs @@ -59,14 +59,16 @@ public void CreateClassCodeGenerator_DeliveryClassCodeGenerator_NoCustomPartialP AssertClassCodeGenerator(result, classDefinitionCodename, classFileName, ClassCodeGenerator.DefaultNamespace); } - [Fact] - public void CreateClassCodeGenerator_PartialClassCodeGenerator_Returns() + [Theory] + [InlineData(false)] + [InlineData(true)] + public void CreateClassCodeGenerator_PartialClassCodeGenerator_Returns(bool managementApi) { var classDefinitionCodename = "codename"; var classFileName = "classFileName"; var codeGeneratorOptions = new CodeGeneratorOptions { - ManagementApi = false + ManagementApi = managementApi }; var result = ClassCodeGeneratorFactory.CreateClassCodeGenerator(codeGeneratorOptions, new ClassDefinition(classDefinitionCodename), classFileName, true); @@ -108,23 +110,6 @@ public void CreateClassCodeGenerator_DeliveryClassCodeGenerator_CustomNamespace_ AssertClassCodeGenerator(result, classDefinitionCodename, classFileName, customNamespace); } - [Theory] - [InlineData(false)] - [InlineData(true)] - public void CreateClassCodeGenerator_ManagementClassCodeGenerator_WithCustomPartialProperty_Returns(bool customPartial) - { - var classDefinitionCodename = "codename"; - var classFileName = "classFileName"; - var codeGeneratorOptions = new CodeGeneratorOptions - { - ManagementApi = true - }; - - var result = ClassCodeGeneratorFactory.CreateClassCodeGenerator(codeGeneratorOptions, new ClassDefinition(classDefinitionCodename), classFileName, customPartial); - - AssertClassCodeGenerator(result, classDefinitionCodename, classFileName, ClassCodeGenerator.DefaultNamespace); - } - [Fact] public void CreateClassCodeGenerator_ManagementClassCodeGenerator_NoCustomPartialProperty_Returns() {