Skip to content

Commit 4d059bf

Browse files
committed
test(integration): add 012b negative cases for taxonomy field, extension, and extension CRUD
1 parent 1ed7ec2 commit 4d059bf

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

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

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ await _stack.Taxonomy().CreateAsync(new TaxonomyModel
592592
var fetched = (await _stack.ContentType(ctUid).FetchAsync()).OpenTResponse<ContentTypeModel>().Modelling;
593593
var taxField = fetched.Schema.OfType<TaxonomyField>().FirstOrDefault(f => f.Uid == "taxonomies");
594594
AssertLogger.IsNotNull(taxField, "taxonomy field async");
595+
AssertLogger.IsTrue(taxField.Taxonomies.Any(t => t.TaxonomyUid == taxUid), "binding uid async");
595596
}
596597
finally
597598
{
@@ -602,6 +603,158 @@ await _stack.Taxonomy().CreateAsync(new TaxonomyModel
602603

603604
#endregion
604605

606+
#region Negative paths — taxonomy field and extension
607+
608+
[TestMethod]
609+
[DoNotParallelize]
610+
public void Test025_Should_Error_Create_ContentType_TaxonomyField_NonExistentTaxonomy_Sync()
611+
{
612+
var sfx = NewSuffix();
613+
var fakeTaxUid = "non_existent_tax_ct_" + sfx;
614+
var ctUid = "ct_bad_tax_" + sfx;
615+
var modelling = BuildContentTypeWithTaxonomyField(ctUid, fakeTaxUid, sfx);
616+
try
617+
{
618+
AssertLogger.ThrowsContentstackError(
619+
() => _stack.ContentType().Create(modelling),
620+
"CreateCtTaxonomyMissing",
621+
HttpStatusCode.BadRequest,
622+
HttpStatusCode.NotFound,
623+
(HttpStatusCode)422);
624+
}
625+
finally
626+
{
627+
TryDeleteContentType(ctUid);
628+
}
629+
}
630+
631+
[TestMethod]
632+
[DoNotParallelize]
633+
public async Task Test026_Should_Error_Create_ContentType_TaxonomyField_NonExistentTaxonomy_Async()
634+
{
635+
var sfx = NewSuffix();
636+
var fakeTaxUid = "non_existent_tax_ct_" + sfx;
637+
var ctUid = "ct_bad_tax_a_" + sfx;
638+
var modelling = BuildContentTypeWithTaxonomyField(ctUid, fakeTaxUid, sfx);
639+
try
640+
{
641+
await AssertLogger.ThrowsContentstackErrorAsync(
642+
async () => await _stack.ContentType().CreateAsync(modelling),
643+
"CreateCtTaxonomyMissingAsync",
644+
HttpStatusCode.BadRequest,
645+
HttpStatusCode.NotFound,
646+
(HttpStatusCode)422);
647+
}
648+
finally
649+
{
650+
TryDeleteContentType(ctUid);
651+
}
652+
}
653+
654+
[TestMethod]
655+
[DoNotParallelize]
656+
public void Test027_Should_Error_Create_ContentType_ExtensionField_NonExistentExtension_Sync()
657+
{
658+
var sfx = NewSuffix();
659+
var model = ContentTypeFixtureLoader.LoadFromMock(_client.serializer, "contentTypeSimple.json", sfx);
660+
try
661+
{
662+
model.Schema.Add(new ExtensionField
663+
{
664+
DisplayName = "Fake Extension",
665+
Uid = "ext_bad_" + sfx,
666+
DataType = "extension",
667+
extension_uid = "non_existent_ext_" + sfx,
668+
Mandatory = false
669+
});
670+
AssertLogger.ThrowsContentstackError(
671+
() => _stack.ContentType().Create(model),
672+
"CreateCtExtensionMissing",
673+
HttpStatusCode.BadRequest,
674+
HttpStatusCode.NotFound,
675+
(HttpStatusCode)422);
676+
}
677+
finally
678+
{
679+
TryDeleteContentType(model.Uid);
680+
}
681+
}
682+
683+
[TestMethod]
684+
[DoNotParallelize]
685+
public async Task Test028_Should_Error_Create_ContentType_ExtensionField_NonExistentExtension_Async()
686+
{
687+
var sfx = NewSuffix();
688+
var model = ContentTypeFixtureLoader.LoadFromMock(_client.serializer, "contentTypeSimple.json", sfx);
689+
try
690+
{
691+
model.Schema.Add(new ExtensionField
692+
{
693+
DisplayName = "Fake Extension",
694+
Uid = "ext_bad_a_" + sfx,
695+
DataType = "extension",
696+
extension_uid = "non_existent_ext_" + sfx,
697+
Mandatory = false
698+
});
699+
await AssertLogger.ThrowsContentstackErrorAsync(
700+
async () => await _stack.ContentType().CreateAsync(model),
701+
"CreateCtExtensionMissingAsync",
702+
HttpStatusCode.BadRequest,
703+
HttpStatusCode.NotFound,
704+
(HttpStatusCode)422);
705+
}
706+
finally
707+
{
708+
TryDeleteContentType(model.Uid);
709+
}
710+
}
711+
712+
[TestMethod]
713+
[DoNotParallelize]
714+
public void Test029_Should_Error_Extension_Fetch_NonExistent_Sync()
715+
{
716+
AssertLogger.ThrowsContentstackError(
717+
() => _stack.Extension("non_existent_ext_res_" + NewSuffix()).Fetch(),
718+
"ExtensionFetchMissing",
719+
HttpStatusCode.NotFound,
720+
(HttpStatusCode)422);
721+
}
722+
723+
[TestMethod]
724+
[DoNotParallelize]
725+
public async Task Test030_Should_Error_Extension_Fetch_NonExistent_Async()
726+
{
727+
await AssertLogger.ThrowsContentstackErrorAsync(
728+
async () => await _stack.Extension("non_existent_ext_res_" + NewSuffix()).FetchAsync(),
729+
"ExtensionFetchMissingAsync",
730+
HttpStatusCode.NotFound,
731+
(HttpStatusCode)422);
732+
}
733+
734+
[TestMethod]
735+
[DoNotParallelize]
736+
public void Test031_Should_Error_Extension_Delete_NonExistent_Sync()
737+
{
738+
AssertLogger.ThrowsContentstackError(
739+
() => _stack.Extension("non_existent_ext_res_" + NewSuffix()).Delete(),
740+
"ExtensionDeleteMissing",
741+
HttpStatusCode.NotFound,
742+
(HttpStatusCode)422);
743+
}
744+
745+
[TestMethod]
746+
[DoNotParallelize]
747+
public async Task Test032_Should_Error_Extension_Delete_NonExistent_Async()
748+
{
749+
await AssertLogger.ThrowsContentstackErrorAsync(
750+
async () => await _stack.Extension("non_existent_ext_res_" + NewSuffix()).DeleteAsync(),
751+
"ExtensionDeleteMissingAsync",
752+
HttpStatusCode.NotFound,
753+
(HttpStatusCode)422);
754+
}
755+
756+
#endregion
757+
605758
private static ContentModelling BuildContentTypeWithTaxonomyField(string ctUid, string taxUid, string sfx)
606759
{
607760
return new ContentModelling

0 commit comments

Comments
 (0)