Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [v1.3.0](https://github.com/contentstack/contentstack-management-dotnet/tree/v1.3.0)(2026-12-04)

- **New**
- **Taxonomy publish, localize and unlocalize**: `Taxonomy.Publish` / `PublishAsync` (collection-level; a 2xx means accepted, not completed), and `Unlocalize` / `UnlocalizeAsync` (required locale, 204 empty body). (DX-10479)

## [v1.2.0](https://github.com/contentstack/contentstack-management-dotnet/tree/v1.2.0)(2026-11-12)

- **New**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6492,6 +6492,274 @@ public void Test279_Should_Handle_Extreme_Boundary_Combinations()
}
}

// Taxonomy publish / unlocalize. Every named resource (locale, environment,
// branch) is looked up first; locales and environments are created here when the stack
// has too few, and those are deleted in the test's finally block. Branches are never created.

private JsonArray QueryArrayOrEmpty(ContentstackResponse response, string key, string queryName)
{
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Query {queryName} failed: {response.OpenResponse()}", "Query" + queryName + "Success");
var jobj = response.OpenJsonObjectResponse();
return (jobj?[key] ?? jobj?["items"]) as JsonArray ?? new JsonArray();
}

private List<string> ResolveLocaleCodes(int count, List<string> createdLocales)
{
var codes = new List<string>();
var array = QueryArrayOrEmpty(_stack.Locale().Query().Find(), "locales", "Locales");
foreach (var item in array)
{
var code = item?["code"]?.ToString();
if (string.IsNullOrEmpty(code) || string.Equals(code, "en-us", StringComparison.OrdinalIgnoreCase)) continue;
if (codes.Count < count) codes.Add(code);
}
string[] candidates = { "hi-in", "mr-in" };
string[] candidateNames = { "Hindi (India)", "Marathi (India)" };
for (int i = 0; codes.Count < count && i < candidates.Length; i++)
{
if (codes.Contains(candidates[i])) continue;
ContentstackResponse createResponse = _stack.Locale().Create(new LocaleModel
{
Code = candidates[i],
Name = candidateNames[i]
});
AssertLogger.IsTrue(createResponse.IsSuccessStatusCode, $"Create locale {candidates[i]} failed: {createResponse.OpenResponse()}", "CreateLocaleSuccess");
createdLocales.Add(candidates[i]);
codes.Add(candidates[i]);
}
AssertLogger.IsTrue(codes.Count == count, $"Expected {count} non-master locale(s), resolved {codes.Count}", "ResolvedLocaleCount");
return codes;
}

private List<string> ResolveEnvironmentNames(int count, List<string> createdEnvironments)
{
var names = new List<string>();
var array = QueryArrayOrEmpty(_stack.Environment().Query().Find(), "environments", "Environments");
foreach (var item in array)
{
var name = item?["name"]?.ToString();
if (string.IsNullOrEmpty(name)) continue;
if (names.Count < count) names.Add(name);
}
while (names.Count < count)
{
string name = "tax_pub_env_" + Guid.NewGuid().ToString("N").Substring(0, 8);
ContentstackResponse createResponse = _stack.Environment().Create(new EnvironmentModel
{
Name = name,
Urls = new List<LocalesUrl>
{
new LocalesUrl { Locale = "en-us", Url = "https://example.com" }
}
});
AssertLogger.IsTrue(createResponse.IsSuccessStatusCode, $"Create environment failed: {createResponse.OpenResponse()}", "CreateEnvironmentSuccess");
createdEnvironments.Add(name);
names.Add(name);
}
return names;
}

// The taxonomy, locale and environment fixtures live on the stack's own configured branch, so the
// publish must name that branch (or "main" when none is configured); it is looked up, never created.
private string ResolvePublishBranchUid()
{
string branchUid = string.IsNullOrWhiteSpace(_stack.BranchUid) ? "main" : _stack.BranchUid;
ContentstackResponse response = _stack.Branch(branchUid).Fetch();
if (!response.IsSuccessStatusCode)
{
AssertLogger.Inconclusive($"Branch '{branchUid}' not found on the stack; skipping taxonomy publish-with-branch test.");
}
return branchUid;
}

private string CreatePublishFixtureTaxonomy(List<string> createdTaxonomies)
{
string taxonomyUid = "tax_pub_taxonomy_" + Guid.NewGuid().ToString("N").Substring(0, 8);
ContentstackResponse createResponse = _stack.Taxonomy().Create(new TaxonomyModel
{
Uid = taxonomyUid,
Name = "Publish Fixture Taxonomy",
Description = "Fixture for publish and unlocalize tests"
});
AssertLogger.IsTrue(createResponse.IsSuccessStatusCode, $"Create taxonomy failed: {createResponse.OpenResponse()}", "CreateFixtureTaxonomySuccess");
createdTaxonomies.Add(taxonomyUid);
return taxonomyUid;
}

private void DeleteTaxonomyPublishFixtures(List<string> taxonomies, List<string> environments, List<string> locales)
{
foreach (var uid in taxonomies)
{
try { _stack.Taxonomy(uid).Delete(); }
catch (Exception ex) { Console.WriteLine($"[Cleanup] Failed to delete taxonomy {uid}: {ex.Message}"); }
}
foreach (var name in environments)
{
try { _stack.Environment(name).Delete(); }
catch (Exception ex) { Console.WriteLine($"[Cleanup] Failed to delete environment {name}: {ex.Message}"); }
}
foreach (var code in locales)
{
try { _stack.Locale(code).Delete(); }
catch (Exception ex) { Console.WriteLine($"[Cleanup] Failed to delete locale {code}: {ex.Message}"); }
}
}

private static void AssertPublishAcknowledged(ContentstackResponse response, string name)
{
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Publish failed: {response.OpenResponse()}", name + "Success");
var jobj = response.OpenJsonObjectResponse();
AssertLogger.IsNotNull(jobj?["notice"], "Publish acknowledgement notice", name + "Notice");
AssertLogger.IsNotNull(jobj?["job_id"], "Publish acknowledgement job id", name + "JobId");
}

// Localizes the fixture into each locale first: publishing to a locale the taxonomy is not localized to fails
// with NOT_LOCALIZED, and unlocalizing needs a localized taxonomy to remove.
private void LocalizeFixtureToLocales(string taxonomyUid, List<string> localeCodes)
{
foreach (string localeCode in localeCodes)
{
var localizeParams = new ParameterCollection();
localizeParams.Add("locale", localeCode);
var localizeModel = new TaxonomyModel { Uid = taxonomyUid, Name = "Publish Localized", Description = "Localized for publish test" };
ContentstackResponse localizeResponse = _stack.Taxonomy(taxonomyUid).Localize(localizeModel, localizeParams);
AssertLogger.IsTrue(localizeResponse.IsSuccessStatusCode, $"Localize failed: {localizeResponse.OpenResponse()}", "LocalizeFixtureSuccess");
}
}

private async Task PublishToLocalesAndEnvironmentsAsync(string scenario, string assertName, int count, Func<TaxonomyPublishModel, Task<ContentstackResponse>> publish)
{
TestOutputLogger.LogContext("TestScenario", scenario);
var taxonomies = new List<string>();
var environments = new List<string>();
var locales = new List<string>();
try
{
string taxonomyUid = CreatePublishFixtureTaxonomy(taxonomies);
var localeCodes = ResolveLocaleCodes(count, locales);
LocalizeFixtureToLocales(taxonomyUid, localeCodes);
var environmentNames = ResolveEnvironmentNames(count, environments);
TestOutputLogger.LogContext("TaxonomyUid", taxonomyUid);
var model = new TaxonomyPublishModel
{
Locales = localeCodes,
Environments = environmentNames,
Items = new List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = taxonomyUid } }
};
ContentstackResponse response = await publish(model);
AssertPublishAcknowledged(response, assertName);
}
finally
{
DeleteTaxonomyPublishFixtures(taxonomies, environments, locales);
}
}

[TestMethod]
[DoNotParallelize]
public void Test280_Should_Publish_Taxonomy_To_One_Environment_And_Locale()
{
PublishToLocalesAndEnvironmentsAsync("Test280_Should_Publish_Taxonomy_To_One_Environment_And_Locale", "PublishOneEnvLocale", 1,
model => Task.FromResult(_stack.Taxonomy().Publish(model))).GetAwaiter().GetResult();
}

[TestMethod]
[DoNotParallelize]
public async Task Test281_Should_Publish_Taxonomy_To_One_Environment_And_Locale_Async()
{
await PublishToLocalesAndEnvironmentsAsync("Test281_Should_Publish_Taxonomy_To_One_Environment_And_Locale_Async", "PublishOneEnvLocaleAsync", 1,
model => _stack.Taxonomy().PublishAsync(model));
}

[TestMethod]
[DoNotParallelize]
public void Test282_Should_Publish_Taxonomy_To_Multiple_Locales_And_Environments()
{
PublishToLocalesAndEnvironmentsAsync("Test282_Should_Publish_Taxonomy_To_Multiple_Locales_And_Environments", "PublishMultiLocaleEnv", 2,
model => Task.FromResult(_stack.Taxonomy().Publish(model))).GetAwaiter().GetResult();
}

[TestMethod]
[DoNotParallelize]
public void Test283_Should_Publish_Taxonomy_With_Branch()
{
TestOutputLogger.LogContext("TestScenario", "Test283_Should_Publish_Taxonomy_With_Branch");
string branchUid = ResolvePublishBranchUid();
var taxonomies = new List<string>();
var environments = new List<string>();
var locales = new List<string>();
try
{
string taxonomyUid = CreatePublishFixtureTaxonomy(taxonomies);
var localeCodes = ResolveLocaleCodes(1, locales);
LocalizeFixtureToLocales(taxonomyUid, localeCodes);
var environmentNames = ResolveEnvironmentNames(1, environments);
TestOutputLogger.LogContext("TaxonomyUid", taxonomyUid);
TestOutputLogger.LogContext("BranchUid", branchUid);
var model = new TaxonomyPublishModel
{
Locales = localeCodes,
Environments = environmentNames,
Items = new List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = taxonomyUid } },
Branch = branchUid
};
ContentstackResponse response = _stack.Taxonomy().Publish(model);
AssertPublishAcknowledged(response, "PublishWithBranch");
}
finally
{
DeleteTaxonomyPublishFixtures(taxonomies, environments, locales);
}
}

[TestMethod]
[DoNotParallelize]
public void Test284_Should_Unlocalize_Taxonomy()
{
TestOutputLogger.LogContext("TestScenario", "Test284_Should_Unlocalize_Taxonomy");
var taxonomies = new List<string>();
var locales = new List<string>();
try
{
string taxonomyUid = CreatePublishFixtureTaxonomy(taxonomies);
var localeCodes = ResolveLocaleCodes(1, locales);
TestOutputLogger.LogContext("TaxonomyUid", taxonomyUid);
LocalizeFixtureToLocales(taxonomyUid, localeCodes);

ContentstackResponse response = _stack.Taxonomy(taxonomyUid).Unlocalize(localeCodes[0]);
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Unlocalize failed: {response.OpenResponse()}", "UnlocalizeSuccess");
AssertLogger.IsTrue(string.IsNullOrWhiteSpace(response.OpenResponse()), "Unlocalize response body is empty", "UnlocalizeEmptyBody");
}
finally
{
DeleteTaxonomyPublishFixtures(taxonomies, new List<string>(), locales);
}
}

[TestMethod]
[DoNotParallelize]
public async Task Test285_Should_Unlocalize_Taxonomy_Async()
{
TestOutputLogger.LogContext("TestScenario", "Test285_Should_Unlocalize_Taxonomy_Async");
var taxonomies = new List<string>();
var locales = new List<string>();
try
{
string taxonomyUid = CreatePublishFixtureTaxonomy(taxonomies);
var localeCodes = ResolveLocaleCodes(1, locales);
TestOutputLogger.LogContext("TaxonomyUid", taxonomyUid);
LocalizeFixtureToLocales(taxonomyUid, localeCodes);

ContentstackResponse response = await _stack.Taxonomy(taxonomyUid).UnlocalizeAsync(localeCodes[0]);
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"UnlocalizeAsync failed: {response.OpenResponse()}", "UnlocalizeAsyncSuccess");
AssertLogger.IsTrue(string.IsNullOrWhiteSpace(response.OpenResponse()), "UnlocalizeAsync response body is empty", "UnlocalizeAsyncEmptyBody");
}
finally
{
DeleteTaxonomyPublishFixtures(taxonomies, new List<string>(), locales);
}
}

private static Stack GetStack()
{
StackResponse response = StackResponse.getStack(_client.serializer);
Expand Down
Loading
Loading