Skip to content

Commit 7cee175

Browse files
committed
feat: Added Negative Path related test cases in terms support.
1 parent fe30677 commit 7cee175

File tree

1 file changed

+214
-0
lines changed

1 file changed

+214
-0
lines changed

Contentstack.Management.Core.Tests/IntegrationTest/Contentstack017_TaxonomyTest.cs

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,220 @@ public void Test042_Should_Throw_When_Delete_NonExistent_Term()
801801
_stack.Taxonomy(_taxonomyUid).Terms("non_existent_term_uid_12345").Delete(), "DeleteNonExistentTerm");
802802
}
803803

804+
[TestMethod]
805+
[DoNotParallelize]
806+
public void Test043_Should_Throw_When_Ancestors_NonExistent_Term()
807+
{
808+
TestOutputLogger.LogContext("TestScenario", "Test043_Should_Throw_When_Ancestors_NonExistent_Term");
809+
TestOutputLogger.LogContext("TaxonomyUid", _taxonomyUid ?? "");
810+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
811+
_stack.Taxonomy(_taxonomyUid).Terms("non_existent_term_uid_12345").Ancestors(), "AncestorsNonExistentTerm");
812+
}
813+
814+
[TestMethod]
815+
[DoNotParallelize]
816+
public void Test044_Should_Throw_When_Descendants_NonExistent_Term()
817+
{
818+
TestOutputLogger.LogContext("TestScenario", "Test044_Should_Throw_When_Descendants_NonExistent_Term");
819+
TestOutputLogger.LogContext("TaxonomyUid", _taxonomyUid ?? "");
820+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
821+
_stack.Taxonomy(_taxonomyUid).Terms("non_existent_term_uid_12345").Descendants(), "DescendantsNonExistentTerm");
822+
}
823+
824+
[TestMethod]
825+
[DoNotParallelize]
826+
public void Test045_Should_Throw_When_Locales_NonExistent_Term()
827+
{
828+
TestOutputLogger.LogContext("TestScenario", "Test045_Should_Throw_When_Locales_NonExistent_Term");
829+
TestOutputLogger.LogContext("TaxonomyUid", _taxonomyUid ?? "");
830+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
831+
_stack.Taxonomy(_taxonomyUid).Terms("non_existent_term_uid_12345").Locales(), "LocalesNonExistentTerm");
832+
}
833+
834+
[TestMethod]
835+
[DoNotParallelize]
836+
public void Test046_Should_Throw_When_Move_NonExistent_Term()
837+
{
838+
TestOutputLogger.LogContext("TestScenario", "Test047_Should_Throw_When_Move_NonExistent_Term");
839+
TestOutputLogger.LogContext("TaxonomyUid", _taxonomyUid ?? "");
840+
TestOutputLogger.LogContext("RootTermUid", _rootTermUid ?? "");
841+
if (string.IsNullOrEmpty(_rootTermUid))
842+
{
843+
AssertLogger.Inconclusive("Root term not available, skipping move non-existent term test.");
844+
return;
845+
}
846+
var moveModel = new TermMoveModel
847+
{
848+
ParentUid = _rootTermUid,
849+
Order = 1
850+
};
851+
var coll = new ParameterCollection();
852+
coll.Add("force", true);
853+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
854+
_stack.Taxonomy(_taxonomyUid).Terms("non_existent_term_uid_12345").Move(moveModel, coll), "MoveNonExistentTerm");
855+
}
856+
857+
[TestMethod]
858+
[DoNotParallelize]
859+
public void Test047_Should_Throw_When_Create_Term_NonExistent_Taxonomy()
860+
{
861+
TestOutputLogger.LogContext("TestScenario", "Test048_Should_Throw_When_Create_Term_NonExistent_Taxonomy");
862+
var termModel = new TermModel
863+
{
864+
Uid = "some_term_uid",
865+
Name = "No"
866+
};
867+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
868+
_stack.Taxonomy("non_existent_taxonomy_uid_12345").Terms().Create(termModel), "CreateTermNonExistentTaxonomy");
869+
}
870+
871+
[TestMethod]
872+
[DoNotParallelize]
873+
public void Test048_Should_Throw_When_Fetch_Term_NonExistent_Taxonomy()
874+
{
875+
TestOutputLogger.LogContext("TestScenario", "Test049_Should_Throw_When_Fetch_Term_NonExistent_Taxonomy");
876+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
877+
_stack.Taxonomy("non_existent_taxonomy_uid_12345").Terms("non_existent_term_uid_12345").Fetch(), "FetchTermNonExistentTaxonomy");
878+
}
879+
880+
[TestMethod]
881+
[DoNotParallelize]
882+
public void Test049_Should_Throw_When_Query_Terms_NonExistent_Taxonomy()
883+
{
884+
TestOutputLogger.LogContext("TestScenario", "Test050_Should_Throw_When_Query_Terms_NonExistent_Taxonomy");
885+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
886+
_stack.Taxonomy("non_existent_taxonomy_uid_12345").Terms().Query().Find(), "QueryTermsNonExistentTaxonomy");
887+
}
888+
889+
[TestMethod]
890+
[DoNotParallelize]
891+
public void Test050_Should_Throw_When_Update_Term_NonExistent_Taxonomy()
892+
{
893+
TestOutputLogger.LogContext("TestScenario", "Test051_Should_Throw_When_Update_Term_NonExistent_Taxonomy");
894+
var updateModel = new TermModel { Name = "No" };
895+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
896+
_stack.Taxonomy("non_existent_taxonomy_uid_12345").Terms("non_existent_term_uid_12345").Update(updateModel), "UpdateTermNonExistentTaxonomy");
897+
}
898+
899+
[TestMethod]
900+
[DoNotParallelize]
901+
public void Test051_Should_Throw_When_Delete_Term_NonExistent_Taxonomy()
902+
{
903+
TestOutputLogger.LogContext("TestScenario", "Test052_Should_Throw_When_Delete_Term_NonExistent_Taxonomy");
904+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
905+
_stack.Taxonomy("non_existent_taxonomy_uid_12345").Terms("non_existent_term_uid_12345").Delete(), "DeleteTermNonExistentTaxonomy");
906+
}
907+
908+
[TestMethod]
909+
[DoNotParallelize]
910+
public void Test052_Should_Throw_When_Ancestors_Term_NonExistent_Taxonomy()
911+
{
912+
TestOutputLogger.LogContext("TestScenario", "Test053_Should_Throw_When_Ancestors_Term_NonExistent_Taxonomy");
913+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
914+
_stack.Taxonomy("non_existent_taxonomy_uid_12345").Terms("non_existent_term_uid_12345").Ancestors(), "AncestorsTermNonExistentTaxonomy");
915+
}
916+
917+
[TestMethod]
918+
[DoNotParallelize]
919+
public void Test053_Should_Throw_When_Descendants_Term_NonExistent_Taxonomy()
920+
{
921+
TestOutputLogger.LogContext("TestScenario", "Test054_Should_Throw_When_Descendants_Term_NonExistent_Taxonomy");
922+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
923+
_stack.Taxonomy("non_existent_taxonomy_uid_12345").Terms("non_existent_term_uid_12345").Descendants(), "DescendantsTermNonExistentTaxonomy");
924+
}
925+
926+
[TestMethod]
927+
[DoNotParallelize]
928+
public void Test054_Should_Throw_When_Locales_Term_NonExistent_Taxonomy()
929+
{
930+
TestOutputLogger.LogContext("TestScenario", "Test055_Should_Throw_When_Locales_Term_NonExistent_Taxonomy");
931+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
932+
_stack.Taxonomy("non_existent_taxonomy_uid_12345").Terms("non_existent_term_uid_12345").Locales(), "LocalesTermNonExistentTaxonomy");
933+
}
934+
935+
[TestMethod]
936+
[DoNotParallelize]
937+
public void Test055_Should_Throw_When_Localize_Term_NonExistent_Taxonomy()
938+
{
939+
TestOutputLogger.LogContext("TestScenario", "Test056_Should_Throw_When_Localize_Term_NonExistent_Taxonomy");
940+
var localizeModel = new TermModel { Name = "No" };
941+
var coll = new ParameterCollection();
942+
coll.Add("locale", "en-us");
943+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
944+
_stack.Taxonomy("non_existent_taxonomy_uid_12345").Terms("non_existent_term_uid_12345").Localize(localizeModel, coll), "LocalizeTermNonExistentTaxonomy");
945+
}
946+
947+
[TestMethod]
948+
[DoNotParallelize]
949+
public void Test056_Should_Throw_When_Move_Term_NonExistent_Taxonomy()
950+
{
951+
TestOutputLogger.LogContext("TestScenario", "Test057_Should_Throw_When_Move_Term_NonExistent_Taxonomy");
952+
var moveModel = new TermMoveModel
953+
{
954+
ParentUid = "x",
955+
Order = 1
956+
};
957+
var coll = new ParameterCollection();
958+
coll.Add("force", true);
959+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
960+
_stack.Taxonomy("non_existent_taxonomy_uid_12345").Terms("non_existent_term_uid_12345").Move(moveModel, coll), "MoveTermNonExistentTaxonomy");
961+
}
962+
963+
[TestMethod]
964+
[DoNotParallelize]
965+
public void Test057_Should_Throw_When_Create_Term_Duplicate_Uid()
966+
{
967+
TestOutputLogger.LogContext("TestScenario", "Test058_Should_Throw_When_Create_Term_Duplicate_Uid");
968+
TestOutputLogger.LogContext("TaxonomyUid", _taxonomyUid ?? "");
969+
TestOutputLogger.LogContext("RootTermUid", _rootTermUid ?? "");
970+
var termModel = new TermModel
971+
{
972+
Uid = _rootTermUid,
973+
Name = "Duplicate"
974+
};
975+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
976+
_stack.Taxonomy(_taxonomyUid).Terms().Create(termModel), "CreateTermDuplicateUid");
977+
}
978+
979+
[TestMethod]
980+
[DoNotParallelize]
981+
public void Test058_Should_Throw_When_Create_Term_Invalid_ParentUid()
982+
{
983+
TestOutputLogger.LogContext("TestScenario", "Test059_Should_Throw_When_Create_Term_Invalid_ParentUid");
984+
TestOutputLogger.LogContext("TaxonomyUid", _taxonomyUid ?? "");
985+
var termModel = new TermModel
986+
{
987+
Uid = "term_bad_parent_12345",
988+
Name = "Bad Parent",
989+
ParentUid = "non_existent_parent_uid_12345"
990+
};
991+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
992+
_stack.Taxonomy(_taxonomyUid).Terms().Create(termModel), "CreateTermInvalidParentUid");
993+
}
994+
995+
[TestMethod]
996+
[DoNotParallelize]
997+
public void Test059_Should_Throw_When_Move_Term_To_Itself()
998+
{
999+
TestOutputLogger.LogContext("TestScenario", "Test060_Should_Throw_When_Move_Term_To_Itself");
1000+
TestOutputLogger.LogContext("TaxonomyUid", _taxonomyUid ?? "");
1001+
TestOutputLogger.LogContext("RootTermUid", _rootTermUid ?? "");
1002+
if (string.IsNullOrEmpty(_rootTermUid))
1003+
{
1004+
AssertLogger.Inconclusive("Root term not available, skipping self-referential move test.");
1005+
return;
1006+
}
1007+
var moveModel = new TermMoveModel
1008+
{
1009+
ParentUid = _rootTermUid,
1010+
Order = 1
1011+
};
1012+
var coll = new ParameterCollection();
1013+
coll.Add("force", true);
1014+
AssertLogger.ThrowsException<ContentstackErrorException>(() =>
1015+
_stack.Taxonomy(_taxonomyUid).Terms(_rootTermUid).Move(moveModel, coll), "MoveTermToItself");
1016+
}
1017+
8041018
private static Stack GetStack()
8051019
{
8061020
StackResponse response = StackResponse.getStack(_client.serializer);

0 commit comments

Comments
 (0)