Suite: Fix failing test generations when ShowOnCreateModal/ShowOnEditModal is unchecked #21765

Back

Description

Resolves #21764

Generated test code produces invalid C# syntax (spurious/leading commas) when any property has "Show on create modal" unchecked, set as readonly on edit modal, or excluded from edit modal.

Root causes fixed in UnitTestCommandCommand.cs:

  • AddNewLineIfLastItem checked the wrong list — compared against _options.Entity.Properties.Last() (full list) while iterating a filtered subset. When the overall last property was excluded by the filter, every filtered item — including the last — got a trailing comma appended.

    • Fix: pass the filtered List<PropertyModel> properties into the method and compare against its .Last().
  • Leading comma in PopulateDtoCtorElements — when all properties are excluded from the create/edit modal but required navigation properties exist, AddNewLine(valueAssignments, ",") prepended , to an empty StringBuilder, producing { , NavProp = id }.

    • Fix: guard with if (valueAssignments.Length > 0) before appending the separator.
  • Leading comma in PopulateDataSeederCtorElements — same pattern for non-Guid PKs: navigation property loop unconditionally prepended ,\n before the first nav argument when no ShowOnCreateModal properties existed.

    • Fix: guard with if (propertiesWithValues.Length > 0) before appending newLine.

Checklist

  • I fully tested it as developer / designer and created unit / integration tests
  • I documented it (or no need to document or I will create a separate documentation issue)
  • I worked with the design team to get their idea for UI/UX design (or no need to design for this PR)
  • I've assigned reviewer, related labels and set a milestone for this PR

How to test it?

  1. Create an entity in ABP Suite with at least two properties. Uncheck Show on the create modal for one property (especially the last one in the list).
  2. Generate code and verify *DataSeedContributor.cs and *AppServiceTests.cs compile without errors.
  3. Repeat with Show on edit modal unchecked, and with Readonly on edit modal checked — confirm UpdateAsync test also compiles cleanly.
Original prompt

This section details on the original issue you should resolve

<issue_title>Suite: Fix failing test generations (occurs when on create modal option is unchecked)</issue_title>
<issue_description>Reported at https://abp.io/support/questions/10473/BUG-ABP-Suite-tests-break-when-Show-on-the-create-modal-is-false


The customer's error description:

When using ABP Studio, it seems like the generated code for tests breaks when you do not have the "Show on the create modal" selected for a property. If you select that option and regenerate, it will work

![image.png](https://abp.io/QA/files/3a1fa7acd627494d5c10c164d7ca6192.png)

![image.png](https://abp.io/QA/files/3a1fa7ad19d7958ef34017920d57cad1.png)

![image.png](https://abp.io/QA/files/3a1fa7ae342e1fc85e7e956aded45cf6.png)

![image.png](https://abp.io/QA/files/3a1fa7aec97663cf020e464ce611cd56.png)

Same problem seem to happen if you select the "Show on the create modal" but also that it should be read only.
```</issue_description>

<agent_instructions>Check the test command classes (and all generated codes regarding tests) on ABP Suite, and also check ABP Suite code templates (under /licensing/ folder) -only for test templates-.

After you check that, in the code, you should be able to understand, when the relevant property is not added or added, and this creates build problem on the generated codes. (As clearly can be seen from the image link in the issue description, property name/parameter written as empty, but trailing ',' added anyway. The relevant place should always same with the entity constructor or for the relevant input class's constructor to overcome this problem!</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

  • Fixes volosoft/volo#21764

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Version
10.1.1
Release Date
03 March, 2026
Labels
abp-suite
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.