Skip to content

feat: Add full Taxonomy and Terms API to .NET CMA SDK#138

Open
OMpawar-21 wants to merge 2 commits intofix/test-casesfrom
enhc/DX-4914
Open

feat: Add full Taxonomy and Terms API to .NET CMA SDK#138
OMpawar-21 wants to merge 2 commits intofix/test-casesfrom
enhc/DX-4914

Conversation

@OMpawar-21
Copy link

Summary

Implements the full Taxonomy and Terms API in the .NET Contentstack Management SDK to align with the JavaScript CMA SDK. Supports managing taxonomies and their terms (CRUD, export, locales, localize, import; term hierarchy, move, search).


Changes

New Models

File Description
TaxonomyModel.cs Taxonomy payload/response (Uid, Name, Description, Locale, counts, CreatedAt, UpdatedAt, Uuid) with snake_case JSON properties
TermModel.cs Term payload/response; includes TermAncestorDescendant and TermMoveModel (ParentUid, Order) for hierarchy and move
TaxonomyImportModel.cs Implements IUploadInterface for taxonomy import (multipart form key "taxonomy"; file path or Stream + filename)

Taxonomy API (Taxonomy.cs)

  • Extends BaseModel<TaxonomyModel> with resourcePath /taxonomies or /taxonomies/{uid}, fieldName "taxonomy".
  • CRUD: Create, CreateAsync, Update, UpdateAsync, Fetch, FetchAsync, Delete, DeleteAsync (optional ParameterCollection).
  • Query: Query() returns Query for listing taxonomies.
  • Export: GET {resourcePath}/export (sync/async).
  • Locales: GET {resourcePath}/locales (sync/async).
  • Localize: POST with body { taxonomy: model } and query params (sync/async).
  • Import: POST /taxonomies/import via UploadService with TaxonomyImportModel (sync/async).
  • Terms: Terms(termUid = null) returns Term (requires taxonomy Uid; used for single term or term collection).

Term API (Term.cs)

  • Extends BaseModel<TermModel> with resourcePath /taxonomies/{taxonomyUid}/terms or .../terms/{termUid}, fieldName "term".
  • CRUD: Create, CreateAsync, Update, UpdateAsync, Fetch, FetchAsync, Delete, DeleteAsync.
  • Query: Query() for listing terms (when no term Uid).
  • Ancestors / Descendants: GET .../ancestors and .../descendants (sync/async).
  • Move: PUT .../move with TermMoveModel (sync/async).
  • Locales: GET .../locales (sync/async).
  • Localize: POST with body { term: model } and query params (sync/async).
  • Search: GET /taxonomies/$all/terms with typeahead query param (sync/async; only when no term Uid).

Stack Entry Point

  • Stack.cs: public Taxonomy Taxonomy(string uid = null) with ThrowIfNotLoggedIn and ThrowIfAPIKeyEmpty; XML docs and example.

Services

  • UploadService.cs: Optional ParameterCollection for query string on upload (used by Taxonomy Import).
  • All other operations use existing CreateUpdateService, FetchDeleteService, QueryService.

Unit Tests

  • TaxonomyTest.cs – Init (no uid / with uid), Create, Query, Fetch, Get Terms collection, Get single Term (10 tests).
  • TermTest.cs – Init collection / with uid, Create, Query, Fetch, Search (10 tests).
  • Uses _stack.Taxonomy() / _stack.Taxonomy(uid) and _stack.Taxonomy(taxonomyUid).Terms() / .Terms(termUid); mock client and MockResponse.txt.

Integration Tests

  • Contentstack017_TaxonomyTest.cs – Create, Fetch, Query, Update, FetchAsync, Delete (6 tests, [DoNotParallelize]).
  • Models.cs (Tests): TaxonomyResponseModel and TaxonomiesResponseModel for API response parsing.
  • Fix: Use static taxonomy UID so the same taxonomy created in Test001 is used by Fetch/Update/Delete tests (avoids ContentstackErrorException from operating on non-existent UIDs).

Testing

  • Unit: 20 Taxonomy/Term tests passing.
  • Integration: Contentstack017_TaxonomyTest runs against live API when credentials are configured (create → fetch → query → update → fetch async → delete).

Files Changed

Action Path
Add Contentstack.Management.Core/Models/TaxonomyModel.cs
Add Contentstack.Management.Core/Models/TermModel.cs
Add Contentstack.Management.Core/Models/TaxonomyImportModel.cs
Add Contentstack.Management.Core/Models/Taxonomy.cs
Add Contentstack.Management.Core/Models/Term.cs
Modify Contentstack.Management.Core/Models/Stack.cs
Modify Contentstack.Management.Core/Services/Models/UploadService.cs
Add Contentstack.Management.Core.Unit.Tests/Models/TaxonomyTest.cs
Add Contentstack.Management.Core.Unit.Tests/Models/TermTest.cs
Add Contentstack.Management.Core.Tests/IntegrationTest/Contentstack017_TaxonomyTest.cs
Modify Contentstack.Management.Core.Tests/Model/Models.cs

- Add Taxonomy and Term support to match the JavaScript CMA SDK.

Models:
- TaxonomyModel, TermModel (with TermAncestorDescendant, TermMoveModel), TaxonomyImportModel (IUploadInterface for multipart import).

Taxonomy:
- CRUD, Query(), Export(), Locales(), Localize(), Import(), Terms(termUid).
- Stack.Taxonomy(uid) entry point.

Term:
- CRUD, Query(), Ancestors(), Descendants(), Move(), Locales(), Localize(), Search(typeahead).
- Accessed via Stack.Taxonomy(taxonomyUid).Terms() / .Terms(termUid).

Services:
- Reuse CreateUpdateService, FetchDeleteService, QueryService; extend UploadService with optional query params for Import.

Tests:
- Unit: TaxonomyTest, TermTest (20 tests). Integration: Contentstack017_TaxonomyTest (create, fetch, query, update, delete). Use static taxonomy UID in integration test so all steps use the same created taxonomy.
@OMpawar-21 OMpawar-21 requested a review from a team as a code owner March 10, 2026 09:58
@OMpawar-21 OMpawar-21 requested a review from cs-raj March 10, 2026 09:58
@OMpawar-21 OMpawar-21 changed the base branch from development to fix/test-cases March 10, 2026 10:02
Comment on lines +111 to +124
public void Test007_Should_Throw_When_Fetch_NonExistent_Taxonomy()
{
Assert.ThrowsException<ContentstackErrorException>(() =>
_stack.Taxonomy("non_existent_taxonomy_uid_12345").Fetch());
}

[TestMethod]
[DoNotParallelize]
public void Test008_Should_Throw_When_Delete_NonExistent_Taxonomy()
{
Assert.ThrowsException<ContentstackErrorException>(() =>
_stack.Taxonomy("non_existent_taxonomy_uid_12345").Delete());
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests for the create, update, query should be added that should throw error should be added.
Same tests we have to cover for the locales and localize.
Along with sync methods we should also cover the async methods as well
cc: @netrajpatel

namespace Contentstack.Management.Core.Tests.IntegrationTest
{
[TestClass]
public class Contentstack017_TaxonomyTest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the tests for the terms are not added. Make sure to cover all the methods for the terms as well.
Cleanup functions should also be added once the tests are cleared to cleanup the test data.
cc: @netrajpatel

@sunil-lakshman sunil-lakshman self-requested a review March 10, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants