|
|
@ -21,17 +21,20 @@ public class ContentReferencesTests(ContentReferencesFixture fixture) : IClassFi |
|
|
public async Task Should_not_deliver_unpublished_references() |
|
|
public async Task Should_not_deliver_unpublished_references() |
|
|
{ |
|
|
{ |
|
|
// STEP 1: Create a referenced content.
|
|
|
// STEP 1: Create a referenced content.
|
|
|
var contentA_1 = await _.Contents.CreateAsync(new TestEntityWithReferencesData |
|
|
var contentA_1 = await _.Contents.CreateAsync( |
|
|
{ |
|
|
new TestEntityWithReferencesData |
|
|
References = null |
|
|
{ |
|
|
}); |
|
|
References = null |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Create a content with a reference.
|
|
|
// STEP 2: Create a content with a reference.
|
|
|
var contentB_1 = await _.Contents.CreateAsync(new TestEntityWithReferencesData |
|
|
var contentB_1 = await _.Contents.CreateAsync( |
|
|
{ |
|
|
new TestEntityWithReferencesData |
|
|
References = [contentA_1.Id] |
|
|
{ |
|
|
}, ContentCreateOptions.AsPublish); |
|
|
References = [contentA_1.Id] |
|
|
|
|
|
}, |
|
|
|
|
|
ContentCreateOptions.AsPublish); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 3: Query new item.
|
|
|
// STEP 3: Query new item.
|
|
|
@ -41,10 +44,12 @@ public class ContentReferencesTests(ContentReferencesFixture fixture) : IClassFi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 4: Publish reference.
|
|
|
// STEP 4: Publish reference.
|
|
|
await _.Contents.ChangeStatusAsync(contentA_1.Id, new ChangeStatus |
|
|
await _.Contents.ChangeStatusAsync( |
|
|
{ |
|
|
contentA_1.Id, |
|
|
Status = "Published" |
|
|
new ChangeStatus |
|
|
}); |
|
|
{ |
|
|
|
|
|
Status = "Published" |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 5: Query new item again.
|
|
|
// STEP 5: Query new item again.
|
|
|
@ -57,17 +62,21 @@ public class ContentReferencesTests(ContentReferencesFixture fixture) : IClassFi |
|
|
public async Task Should_not_delete_when_referenced() |
|
|
public async Task Should_not_delete_when_referenced() |
|
|
{ |
|
|
{ |
|
|
// STEP 1: Create a referenced content.
|
|
|
// STEP 1: Create a referenced content.
|
|
|
var contentA_1 = await _.Contents.CreateAsync(new TestEntityWithReferencesData |
|
|
var contentA_1 = await _.Contents.CreateAsync( |
|
|
{ |
|
|
new TestEntityWithReferencesData |
|
|
References = null |
|
|
{ |
|
|
}, ContentCreateOptions.AsPublish); |
|
|
References = null |
|
|
|
|
|
}, |
|
|
|
|
|
ContentCreateOptions.AsPublish); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Create a content with a reference.
|
|
|
// STEP 2: Create a content with a reference.
|
|
|
await _.Contents.CreateAsync(new TestEntityWithReferencesData |
|
|
await _.Contents.CreateAsync( |
|
|
{ |
|
|
new TestEntityWithReferencesData |
|
|
References = [contentA_1.Id] |
|
|
{ |
|
|
}, ContentCreateOptions.AsPublish); |
|
|
References = [contentA_1.Id] |
|
|
|
|
|
}, |
|
|
|
|
|
ContentCreateOptions.AsPublish); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 3: Try to delete with referrer check.
|
|
|
// STEP 3: Try to delete with referrer check.
|
|
|
@ -87,89 +96,103 @@ public class ContentReferencesTests(ContentReferencesFixture fixture) : IClassFi |
|
|
public async Task Should_not_unpublish_when_referenced() |
|
|
public async Task Should_not_unpublish_when_referenced() |
|
|
{ |
|
|
{ |
|
|
// STEP 1: Create a published referenced content.
|
|
|
// STEP 1: Create a published referenced content.
|
|
|
var contentA_1 = await _.Contents.CreateAsync(new TestEntityWithReferencesData |
|
|
var contentA_1 = await _.Contents.CreateAsync( |
|
|
{ |
|
|
new TestEntityWithReferencesData |
|
|
References = null |
|
|
{ |
|
|
}, ContentCreateOptions.AsPublish); |
|
|
References = null |
|
|
|
|
|
}, |
|
|
|
|
|
ContentCreateOptions.AsPublish); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Create a content with a reference.
|
|
|
// STEP 2: Create a content with a reference.
|
|
|
await _.Contents.CreateAsync(new TestEntityWithReferencesData |
|
|
await _.Contents.CreateAsync( |
|
|
{ |
|
|
new TestEntityWithReferencesData |
|
|
References = [contentA_1.Id] |
|
|
{ |
|
|
}, ContentCreateOptions.AsPublish); |
|
|
References = [contentA_1.Id] |
|
|
|
|
|
}, |
|
|
|
|
|
ContentCreateOptions.AsPublish); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 3: Try to ThrowsAnyAsync with referrer check.
|
|
|
// STEP 3: Try to ThrowsAnyAsync with referrer check.
|
|
|
await Assert.ThrowsAnyAsync<SquidexException>(() => |
|
|
await Assert.ThrowsAnyAsync<SquidexException>(() => |
|
|
{ |
|
|
{ |
|
|
return _.Contents.ChangeStatusAsync(contentA_1.Id, new ChangeStatus |
|
|
return _.Contents.ChangeStatusAsync( |
|
|
{ |
|
|
contentA_1.Id, |
|
|
Status = "Draft", |
|
|
new ChangeStatus |
|
|
// Ensure that the flag is true.
|
|
|
{ |
|
|
CheckReferrers = true |
|
|
Status = "Draft", |
|
|
}); |
|
|
// Ensure that the flag is true.
|
|
|
|
|
|
CheckReferrers = true |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 4: Delete without referrer check.
|
|
|
// STEP 4: Delete without referrer check.
|
|
|
await _.Contents.ChangeStatusAsync(contentA_1.Id, new ChangeStatus |
|
|
await _.Contents.ChangeStatusAsync( |
|
|
{ |
|
|
contentA_1.Id, |
|
|
Status = "Draft", |
|
|
new ChangeStatus |
|
|
// It is the default anyway, just to make it more explicit.
|
|
|
{ |
|
|
CheckReferrers = false |
|
|
Status = "Draft", |
|
|
}); |
|
|
// It is the default anyway, just to make it more explicit.
|
|
|
|
|
|
CheckReferrers = false |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_not_delete_with_bulk_when_referenced() |
|
|
public async Task Should_not_delete_with_bulk_when_referenced() |
|
|
{ |
|
|
{ |
|
|
// STEP 1: Create a referenced content.
|
|
|
// STEP 1: Create a referenced content.
|
|
|
var contentA_1 = await _.Contents.CreateAsync(new TestEntityWithReferencesData |
|
|
var contentA_1 = await _.Contents.CreateAsync( |
|
|
{ |
|
|
new TestEntityWithReferencesData |
|
|
References = null |
|
|
{ |
|
|
}, ContentCreateOptions.AsPublish); |
|
|
References = null |
|
|
|
|
|
}, |
|
|
|
|
|
ContentCreateOptions.AsPublish); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Create a content with a reference.
|
|
|
// STEP 2: Create a content with a reference.
|
|
|
await _.Contents.CreateAsync(new TestEntityWithReferencesData |
|
|
await _.Contents.CreateAsync( |
|
|
{ |
|
|
new TestEntityWithReferencesData |
|
|
References = [contentA_1.Id] |
|
|
{ |
|
|
}, ContentCreateOptions.AsPublish); |
|
|
References = [contentA_1.Id] |
|
|
|
|
|
}, |
|
|
|
|
|
ContentCreateOptions.AsPublish); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 3: Try to delete with referrer check.
|
|
|
// STEP 3: Try to delete with referrer check.
|
|
|
var result1 = await _.Contents.BulkUpdateAsync(new BulkUpdate |
|
|
var result1 = await _.Contents.BulkUpdateAsync( |
|
|
{ |
|
|
new BulkUpdate |
|
|
Jobs = |
|
|
{ |
|
|
[ |
|
|
Jobs = |
|
|
new BulkUpdateJob |
|
|
[ |
|
|
{ |
|
|
new BulkUpdateJob |
|
|
Id = contentA_1.Id, |
|
|
{ |
|
|
Type = BulkUpdateType.Delete, |
|
|
Id = contentA_1.Id, |
|
|
Status = "Draft" |
|
|
Type = BulkUpdateType.Delete, |
|
|
}, |
|
|
Status = "Draft" |
|
|
], |
|
|
}, |
|
|
CheckReferrers = true |
|
|
], |
|
|
}); |
|
|
CheckReferrers = true |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
Assert.NotNull(result1[0].Error); |
|
|
Assert.NotNull(result1[0].Error); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 4: Delete without referrer check.
|
|
|
// STEP 4: Delete without referrer check.
|
|
|
var result2 = await _.Contents.BulkUpdateAsync(new BulkUpdate |
|
|
var result2 = await _.Contents.BulkUpdateAsync( |
|
|
{ |
|
|
new BulkUpdate |
|
|
Jobs = |
|
|
{ |
|
|
[ |
|
|
Jobs = |
|
|
new BulkUpdateJob |
|
|
[ |
|
|
{ |
|
|
new BulkUpdateJob |
|
|
Id = contentA_1.Id, |
|
|
{ |
|
|
Type = BulkUpdateType.Delete, |
|
|
Id = contentA_1.Id, |
|
|
Status = "Draft" |
|
|
Type = BulkUpdateType.Delete, |
|
|
}, |
|
|
Status = "Draft" |
|
|
], |
|
|
}, |
|
|
CheckReferrers = false |
|
|
], |
|
|
}); |
|
|
CheckReferrers = false |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
Assert.Null(result2[0].Error); |
|
|
Assert.Null(result2[0].Error); |
|
|
} |
|
|
} |
|
|
@ -178,51 +201,57 @@ public class ContentReferencesTests(ContentReferencesFixture fixture) : IClassFi |
|
|
public async Task Should_not_unpublish_with_bulk_when_referenced() |
|
|
public async Task Should_not_unpublish_with_bulk_when_referenced() |
|
|
{ |
|
|
{ |
|
|
// STEP 1: Create a published referenced content.
|
|
|
// STEP 1: Create a published referenced content.
|
|
|
var contentA_1 = await _.Contents.CreateAsync(new TestEntityWithReferencesData |
|
|
var contentA_1 = await _.Contents.CreateAsync( |
|
|
{ |
|
|
new TestEntityWithReferencesData |
|
|
References = null |
|
|
{ |
|
|
}, ContentCreateOptions.AsPublish); |
|
|
References = null |
|
|
|
|
|
}, |
|
|
|
|
|
ContentCreateOptions.AsPublish); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Create a published content with a reference.
|
|
|
// STEP 2: Create a published content with a reference.
|
|
|
await _.Contents.CreateAsync(new TestEntityWithReferencesData |
|
|
await _.Contents.CreateAsync( |
|
|
{ |
|
|
new TestEntityWithReferencesData |
|
|
References = [contentA_1.Id] |
|
|
{ |
|
|
}, ContentCreateOptions.AsPublish); |
|
|
References = [contentA_1.Id] |
|
|
|
|
|
}, |
|
|
|
|
|
ContentCreateOptions.AsPublish); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 3: Try to delete with referrer check.
|
|
|
// STEP 3: Try to delete with referrer check.
|
|
|
var result1 = await _.Contents.BulkUpdateAsync(new BulkUpdate |
|
|
var result1 = await _.Contents.BulkUpdateAsync( |
|
|
{ |
|
|
new BulkUpdate |
|
|
Jobs = |
|
|
{ |
|
|
[ |
|
|
Jobs = |
|
|
new BulkUpdateJob |
|
|
[ |
|
|
{ |
|
|
new BulkUpdateJob |
|
|
Id = contentA_1.Id, |
|
|
{ |
|
|
Type = BulkUpdateType.ChangeStatus, |
|
|
Id = contentA_1.Id, |
|
|
Status = "Draft" |
|
|
Type = BulkUpdateType.ChangeStatus, |
|
|
}, |
|
|
Status = "Draft" |
|
|
], |
|
|
}, |
|
|
CheckReferrers = true |
|
|
], |
|
|
}); |
|
|
CheckReferrers = true |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
Assert.NotNull(result1[0].Error); |
|
|
Assert.NotNull(result1[0].Error); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 4: Delete without referrer check.
|
|
|
// STEP 4: Delete without referrer check.
|
|
|
var result2 = await _.Contents.BulkUpdateAsync(new BulkUpdate |
|
|
var result2 = await _.Contents.BulkUpdateAsync( |
|
|
{ |
|
|
new BulkUpdate |
|
|
Jobs = |
|
|
{ |
|
|
[ |
|
|
Jobs = |
|
|
new BulkUpdateJob |
|
|
[ |
|
|
{ |
|
|
new BulkUpdateJob |
|
|
Id = contentA_1.Id, |
|
|
{ |
|
|
Type = BulkUpdateType.ChangeStatus, |
|
|
Id = contentA_1.Id, |
|
|
Status = "Draft" |
|
|
Type = BulkUpdateType.ChangeStatus, |
|
|
}, |
|
|
Status = "Draft" |
|
|
], |
|
|
}, |
|
|
CheckReferrers = false |
|
|
], |
|
|
}); |
|
|
CheckReferrers = false |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
Assert.Null(result2[0].Error); |
|
|
Assert.Null(result2[0].Error); |
|
|
} |
|
|
} |
|
|
|