Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -6492,6 +6492,249 @@ public void Test279_Should_Handle_Extreme_Boundary_Combinations()
}
}

[TestMethod]
public void Test280_Should_Publish_Taxonomy()
{
TestOutputLogger.LogContext("TestScenario", "Test280_Should_Publish_Taxonomy");
if (string.IsNullOrEmpty(_testLocaleCode))
{
AssertLogger.Inconclusive("No non-master locale available; skipping publish test.");
return;
}

// Look up an environment from the stack to use as a publish target.
ContentstackResponse envResp = _stack.Environments().Query().Find();
if (!envResp.IsSuccessStatusCode)
{
AssertLogger.Inconclusive("Could not fetch environments; skipping publish test.");
return;
}
var envJson = envResp.OpenJsonObjectResponse();
var envArray = envJson["environments"] as System.Text.Json.Nodes.JsonArray;
if (envArray == null || envArray.Count == 0)
{
AssertLogger.Inconclusive("No environments on stack; skipping publish test.");
return;
}
string envName = envArray[0]?["name"]?.ToString();
if (string.IsNullOrEmpty(envName))
{
AssertLogger.Inconclusive("Could not read environment name; skipping publish test.");
return;
}

var model = new TaxonomyPublishModel
{
Locales = new List<string> { _testLocaleCode },
Environments = new List<string> { envName },
Items = new List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = _taxonomyUid } }
};
ContentstackResponse response = _stack.Taxonomy().Publish(model);
// 403 = taxonomy_publish feature not enabled on this stack — treat as inconclusive.
if (response.StatusCode == System.Net.HttpStatusCode.Forbidden)
{
AssertLogger.Inconclusive("taxonomy_publish feature not enabled on this stack; skipping.");
return;
}
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Publish failed: {response.OpenResponse()}", "PublishTaxonomySuccess");
}

[TestMethod]
public async Task Test281_Should_Publish_Taxonomy_Async()
{
TestOutputLogger.LogContext("TestScenario", "Test281_Should_Publish_Taxonomy_Async");
if (string.IsNullOrEmpty(_testLocaleCode))
{
AssertLogger.Inconclusive("No non-master locale available; skipping async publish test.");
return;
}

ContentstackResponse envResp = _stack.Environments().Query().Find();
if (!envResp.IsSuccessStatusCode) { AssertLogger.Inconclusive("Could not fetch environments."); return; }
var envArray = envResp.OpenJsonObjectResponse()["environments"] as System.Text.Json.Nodes.JsonArray;
if (envArray == null || envArray.Count == 0) { AssertLogger.Inconclusive("No environments on stack."); return; }
string envName = envArray[0]?["name"]?.ToString();
if (string.IsNullOrEmpty(envName)) { AssertLogger.Inconclusive("Could not read environment name."); return; }

var model = new TaxonomyPublishModel
{
Locales = new List<string> { _testLocaleCode },
Environments = new List<string> { envName },
Items = new List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = _taxonomyUid } }
};
ContentstackResponse response = await _stack.Taxonomy().PublishAsync(model);
if (response.StatusCode == System.Net.HttpStatusCode.Forbidden)
{
AssertLogger.Inconclusive("taxonomy_publish feature not enabled on this stack; skipping.");
return;
}
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"PublishAsync failed: {response.OpenResponse()}", "PublishTaxonomyAsyncSuccess");
}

[TestMethod]
public void Test282_Should_Unpublish_Taxonomy()
{
TestOutputLogger.LogContext("TestScenario", "Test282_Should_Unpublish_Taxonomy");
if (string.IsNullOrEmpty(_testLocaleCode))
{
AssertLogger.Inconclusive("No non-master locale available; skipping unpublish test.");
return;
}

ContentstackResponse envResp = _stack.Environments().Query().Find();
if (!envResp.IsSuccessStatusCode) { AssertLogger.Inconclusive("Could not fetch environments."); return; }
var envArray = envResp.OpenJsonObjectResponse()["environments"] as System.Text.Json.Nodes.JsonArray;
if (envArray == null || envArray.Count == 0) { AssertLogger.Inconclusive("No environments on stack."); return; }
string envName = envArray[0]?["name"]?.ToString();
if (string.IsNullOrEmpty(envName)) { AssertLogger.Inconclusive("Could not read environment name."); return; }

var model = new TaxonomyPublishModel
{
Locales = new List<string> { _testLocaleCode },
Environments = new List<string> { envName },
Items = new List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = _taxonomyUid } }
};
ContentstackResponse response = _stack.Taxonomy().Unpublish(model);
if (response.StatusCode == System.Net.HttpStatusCode.Forbidden)
{
AssertLogger.Inconclusive("taxonomy_publish feature not enabled on this stack; skipping.");
return;
}
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Unpublish failed: {response.OpenResponse()}", "UnpublishTaxonomySuccess");
}

[TestMethod]
public async Task Test283_Should_Unpublish_Taxonomy_Async()
{
TestOutputLogger.LogContext("TestScenario", "Test283_Should_Unpublish_Taxonomy_Async");
if (string.IsNullOrEmpty(_testLocaleCode))
{
AssertLogger.Inconclusive("No non-master locale available; skipping async unpublish test.");
return;
}

ContentstackResponse envResp = _stack.Environments().Query().Find();
if (!envResp.IsSuccessStatusCode) { AssertLogger.Inconclusive("Could not fetch environments."); return; }
var envArray = envResp.OpenJsonObjectResponse()["environments"] as System.Text.Json.Nodes.JsonArray;
if (envArray == null || envArray.Count == 0) { AssertLogger.Inconclusive("No environments on stack."); return; }
string envName = envArray[0]?["name"]?.ToString();
if (string.IsNullOrEmpty(envName)) { AssertLogger.Inconclusive("Could not read environment name."); return; }

var model = new TaxonomyPublishModel
{
Locales = new List<string> { _testLocaleCode },
Environments = new List<string> { envName },
Items = new List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = _taxonomyUid } }
};
ContentstackResponse response = await _stack.Taxonomy().UnpublishAsync(model);
if (response.StatusCode == System.Net.HttpStatusCode.Forbidden)
{
AssertLogger.Inconclusive("taxonomy_publish feature not enabled on this stack; skipping.");
return;
}
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"UnpublishAsync failed: {response.OpenResponse()}", "UnpublishTaxonomyAsyncSuccess");
}

[TestMethod]
public void Test284_Should_Unlocalize_Taxonomy()
{
TestOutputLogger.LogContext("TestScenario", "Test284_Should_Unlocalize_Taxonomy");
if (string.IsNullOrEmpty(_testLocaleCode))
{
AssertLogger.Inconclusive("No non-master locale available; skipping taxonomy unlocalize test.");
return;
}

// Ensure the taxonomy is localized first so unlocalize has something to remove.
var localizeModel = new TaxonomyModel { Name = "Taxonomy For Unlocalize" };
var localizeColl = new ParameterCollection();
localizeColl.Add("locale", _testLocaleCode);
_stack.Taxonomy(_taxonomyUid).Localize(localizeModel, localizeColl);

ContentstackResponse response = _stack.Taxonomy(_taxonomyUid).Unlocalize(_testLocaleCode);
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Unlocalize failed: {response.OpenResponse()}", "UnlocalizeTaxonomySuccess");
}

[TestMethod]
public async Task Test285_Should_Unlocalize_Taxonomy_Async()
{
TestOutputLogger.LogContext("TestScenario", "Test285_Should_Unlocalize_Taxonomy_Async");
if (string.IsNullOrEmpty(_asyncTestLocaleCode))
{
AssertLogger.Inconclusive("No second non-master locale available; skipping async unlocalize test.");
return;
}

var localizeModel = new TaxonomyModel { Name = "Taxonomy For Unlocalize Async" };
var localizeColl = new ParameterCollection();
localizeColl.Add("locale", _asyncTestLocaleCode);
await _stack.Taxonomy(_taxonomyUid).LocalizeAsync(localizeModel, localizeColl);

ContentstackResponse response = await _stack.Taxonomy(_taxonomyUid).UnlocalizeAsync(_asyncTestLocaleCode);
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"UnlocalizeAsync failed: {response.OpenResponse()}", "UnlocalizeTaxonomyAsyncSuccess");
}

[TestMethod]
public void Test286_Should_Unlocalize_Term()
{
TestOutputLogger.LogContext("TestScenario", "Test286_Should_Unlocalize_Term");
if (string.IsNullOrEmpty(_testLocaleCode) || string.IsNullOrEmpty(_rootTermUid))
{
AssertLogger.Inconclusive("No non-master locale or root term available; skipping term unlocalize test.");
return;
}

// Localize the term first so unlocalize has something to remove.
var localizeModel = new TermModel { Name = "Root Term For Unlocalize" };
var localizeColl = new ParameterCollection();
localizeColl.Add("locale", _testLocaleCode);
_stack.Taxonomy(_taxonomyUid).Terms(_rootTermUid).Localize(localizeModel, localizeColl);

ContentstackResponse response = _stack.Taxonomy(_taxonomyUid).Terms(_rootTermUid).Unlocalize(_testLocaleCode);
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Term Unlocalize failed: {response.OpenResponse()}", "UnlocalizeTermSuccess");
}

[TestMethod]
public async Task Test287_Should_Unlocalize_Term_Async()
{
TestOutputLogger.LogContext("TestScenario", "Test287_Should_Unlocalize_Term_Async");
if (string.IsNullOrEmpty(_asyncTestLocaleCode) || string.IsNullOrEmpty(_rootTermUid))
{
AssertLogger.Inconclusive("No second non-master locale or root term available; skipping async term unlocalize test.");
return;
}

var localizeModel = new TermModel { Name = "Root Term For Unlocalize Async" };
var localizeColl = new ParameterCollection();
localizeColl.Add("locale", _asyncTestLocaleCode);
await _stack.Taxonomy(_taxonomyUid).Terms(_rootTermUid).LocalizeAsync(localizeModel, localizeColl);

ContentstackResponse response = await _stack.Taxonomy(_taxonomyUid).Terms(_rootTermUid).UnlocalizeAsync(_asyncTestLocaleCode);
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Term UnlocalizeAsync failed: {response.OpenResponse()}", "UnlocalizeTermAsyncSuccess");
}

[TestMethod]
public void Test288_Should_Throw_When_Publish_With_Uid_Set()
{
TestOutputLogger.LogContext("TestScenario", "Test288_Should_Throw_When_Publish_With_Uid_Set");
var model = new TaxonomyPublishModel
{
Locales = new List<string> { "en-us" },
Environments = new List<string> { "development" },
Items = new List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = _taxonomyUid } }
};
AssertLogger.ThrowsException<InvalidOperationException>(
() => _stack.Taxonomy(_taxonomyUid).Publish(model), "PublishWithUidSet");
}

[TestMethod]
public void Test289_Should_Throw_When_Unlocalize_Without_Uid()
{
TestOutputLogger.LogContext("TestScenario", "Test289_Should_Throw_When_Unlocalize_Without_Uid");
AssertLogger.ThrowsException<ArgumentException>(
() => _stack.Taxonomy().Unlocalize("en-us"), "UnlocalizeWithoutUid");
}

private static Stack GetStack()
{
StackResponse response = StackResponse.getStack(_client.serializer);
Expand Down
89 changes: 89 additions & 0 deletions Contentstack.Management.Core.Unit.Tests/Models/TaxonomyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,94 @@ public void Localize_When_Api_Returns_400_Returns_Unsuccessful_Response()
Assert.IsFalse(response.IsSuccessStatusCode);
Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
}

[TestMethod]
public void Publish_Throws_When_Uid_Is_Set()
{
var model = new TaxonomyPublishModel { Locales = new System.Collections.Generic.List<string> { "en-us" } };
Assert.ThrowsException<InvalidOperationException>(() => _stack.Taxonomy(_fixture.Create<string>()).Publish(model));
Assert.ThrowsExceptionAsync<InvalidOperationException>(() => _stack.Taxonomy(_fixture.Create<string>()).PublishAsync(model));
}

[TestMethod]
public void Unpublish_Throws_When_Uid_Is_Set()
{
var model = new TaxonomyPublishModel { Locales = new System.Collections.Generic.List<string> { "en-us" } };
Assert.ThrowsException<InvalidOperationException>(() => _stack.Taxonomy(_fixture.Create<string>()).Unpublish(model));
Assert.ThrowsExceptionAsync<InvalidOperationException>(() => _stack.Taxonomy(_fixture.Create<string>()).UnpublishAsync(model));
}

[TestMethod]
public void Unlocalize_Throws_When_Uid_Is_Empty()
{
Assert.ThrowsException<ArgumentException>(() => _stack.Taxonomy().Unlocalize("hi-in"));
Assert.ThrowsExceptionAsync<ArgumentException>(() => _stack.Taxonomy().UnlocalizeAsync("hi-in"));
}

[TestMethod]
public void Should_Publish_Taxonomy()
{
var model = new TaxonomyPublishModel
{
Locales = new System.Collections.Generic.List<string> { "en-us" },
Environments = new System.Collections.Generic.List<string> { "production" },
Items = new System.Collections.Generic.List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = "taxonomy_1" } }
};
ContentstackResponse response = _stack.Taxonomy().Publish(model);
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
}

[TestMethod]
public async System.Threading.Tasks.Task Should_Publish_Taxonomy_Async()
{
var model = new TaxonomyPublishModel
{
Locales = new System.Collections.Generic.List<string> { "en-us" },
Environments = new System.Collections.Generic.List<string> { "production" },
Items = new System.Collections.Generic.List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = "taxonomy_1" } }
};
ContentstackResponse response = await _stack.Taxonomy().PublishAsync(model);
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
}

[TestMethod]
public void Should_Unpublish_Taxonomy()
{
var model = new TaxonomyPublishModel
{
Locales = new System.Collections.Generic.List<string> { "en-us" },
Environments = new System.Collections.Generic.List<string> { "production" },
Items = new System.Collections.Generic.List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = "taxonomy_1" } }
};
ContentstackResponse response = _stack.Taxonomy().Unpublish(model);
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
}

[TestMethod]
public async System.Threading.Tasks.Task Should_Unpublish_Taxonomy_Async()
{
var model = new TaxonomyPublishModel
{
Locales = new System.Collections.Generic.List<string> { "en-us" },
Environments = new System.Collections.Generic.List<string> { "production" },
Items = new System.Collections.Generic.List<TaxonomyPublishItem> { new TaxonomyPublishItem { Uid = "taxonomy_1" } }
};
ContentstackResponse response = await _stack.Taxonomy().UnpublishAsync(model);
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
}

[TestMethod]
public void Should_Unlocalize_Taxonomy()
{
ContentstackResponse response = _stack.Taxonomy(_fixture.Create<string>()).Unlocalize("hi-in");
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
}

[TestMethod]
public async System.Threading.Tasks.Task Should_Unlocalize_Taxonomy_Async()
{
ContentstackResponse response = await _stack.Taxonomy(_fixture.Create<string>()).UnlocalizeAsync("hi-in");
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
}
}
}
26 changes: 26 additions & 0 deletions Contentstack.Management.Core.Unit.Tests/Models/TermTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,31 @@ public void Localize_Throws_When_Term_Uid_Is_Empty()
Assert.ThrowsException<ArgumentException>(() => _stack.Taxonomy(taxonomyUid).Terms().Localize(_fixture.Create<TermModel>()));
Assert.ThrowsExceptionAsync<ArgumentException>(() => _stack.Taxonomy(taxonomyUid).Terms().LocalizeAsync(_fixture.Create<TermModel>()));
}

[TestMethod]
public void Unlocalize_Throws_When_Term_Uid_Is_Empty()
{
string taxonomyUid = _fixture.Create<string>();
Assert.ThrowsException<ArgumentException>(() => _stack.Taxonomy(taxonomyUid).Terms().Unlocalize("hi-in"));
Assert.ThrowsExceptionAsync<ArgumentException>(() => _stack.Taxonomy(taxonomyUid).Terms().UnlocalizeAsync("hi-in"));
}

[TestMethod]
public void Should_Unlocalize_Term()
{
string taxonomyUid = _fixture.Create<string>();
string termUid = _fixture.Create<string>();
ContentstackResponse response = _stack.Taxonomy(taxonomyUid).Terms(termUid).Unlocalize("hi-in");
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
}

[TestMethod]
public async System.Threading.Tasks.Task Should_Unlocalize_Term_Async()
{
string taxonomyUid = _fixture.Create<string>();
string termUid = _fixture.Create<string>();
ContentstackResponse response = await _stack.Taxonomy(taxonomyUid).Terms(termUid).UnlocalizeAsync("hi-in");
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
}
}
}
Loading
Loading