public async Task Should_not_unpublish_when_referenced() { // STEP 1: Create a published referenced content. var dataA = new TestEntityWithReferencesData(); var contentA_1 = await _.Contents.CreateAsync(dataA, true); // STEP 2: Create a content with a reference. var dataB = new TestEntityWithReferencesData { References = new[] { contentA_1.Id } }; await _.Contents.CreateAsync(dataB, true); // STEP 3: Try to delete with referrer check. await Assert.ThrowsAsync <SquidexException>(() => _.Contents.ChangeStatusAsync(contentA_1.Id, new ChangeStatus { Status = "Draft", CheckReferrers = true })); // STEP 4: Delete without referrer check await _.Contents.ChangeStatusAsync(contentA_1.Id, new ChangeStatus { Status = "Draft", CheckReferrers = false }); }
public async Task Should_not_deliver_unpublished_references() { // STEP 1: Create a referenced content. var dataA = new TestEntityWithReferencesData(); var contentA_1 = await _.Contents.CreateAsync(dataA); // STEP 2: Create a content with a reference. var dataB = new TestEntityWithReferencesData { References = new[] { contentA_1.Id } }; var contentB_1 = await _.Contents.CreateAsync(dataB, true); // STEP 3: Query new item var contentB_2 = await _.Contents.GetAsync(contentB_1.Id); Assert.Empty(contentB_2.Data.References); // STEP 4: Publish reference await _.Contents.ChangeStatusAsync(contentA_1.Id, "Published"); // STEP 5: Query new item again var contentB_3 = await _.Contents.GetAsync(contentB_1.Id); Assert.Equal(new string[] { contentA_1.Id }, contentB_3.Data.References); }
public async Task Should_cleanup_old_references() { var schemaName = $"schema-{DateTime.UtcNow.Ticks}"; // STEP 1: Create a schema. await TestEntityWithReferences.CreateSchemaAsync(_.Schemas, _.AppName, schemaName); var contents = _.ClientManager.GetClient <TestEntityWithReferences, TestEntityWithReferencesData>(schemaName); // STEP 2: Create a referenced content. var dataA = new TestEntityWithReferencesData(); var contentA_1 = await contents.CreateAsync(dataA); // STEP 3: Create a content with a reference. var dataB = new TestEntityWithReferencesData { References = new[] { Guid.Parse(contentA_1.Id) } }; var contentB_1 = await contents.CreateAsync(dataB); // STEP 3: Delete a reference await contents.DeleteAsync(contentA_1.Id); // STEP 4: Make any update. var contentB_2 = await contents.ChangeStatusAsync(contentB_1.Id, "Published"); // Should not return deleted field. Assert.Empty(contentB_2.Data.References); }
public async Task Should_not_delete_when_referenced() { // STEP 1: Create a referenced content. var dataA = new TestEntityWithReferencesData(); var contentA_1 = await _.Contents.CreateAsync(dataA, ContentCreateOptions.AsPublish); // STEP 2: Create a content with a reference. var dataB = new TestEntityWithReferencesData { References = new[] { contentA_1.Id } }; await _.Contents.CreateAsync(dataB, ContentCreateOptions.AsPublish); // STEP 3: Try to delete with referrer check. await Assert.ThrowsAnyAsync <SquidexException>(() => _.Contents.DeleteAsync(contentA_1.Id, new ContentDeleteOptions { CheckReferrers = true })); // STEP 4: Delete without referrer check await _.Contents.DeleteAsync(contentA_1.Id); }
public async Task Should_not_unpublish_with_bulk_when_referenced() { // STEP 1: Create a published referenced content. var dataA = new TestEntityWithReferencesData(); var contentA_1 = await _.Contents.CreateAsync(dataA, true); // STEP 2: Create a published content with a reference. var dataB = new TestEntityWithReferencesData { References = new[] { contentA_1.Id } }; await _.Contents.CreateAsync(dataB, true); // STEP 3: Try to delete with referrer check. var result1 = await _.Contents.BulkUpdateAsync(new BulkUpdate { Jobs = new List <BulkUpdateJob> { new BulkUpdateJob { Id = contentA_1.Id, Type = BulkUpdateType.ChangeStatus, Status = "Draft" } }, CheckReferrers = true }); Assert.NotNull(result1[0].Error); // STEP 4: Delete without referrer check var result2 = await _.Contents.BulkUpdateAsync(new BulkUpdate { Jobs = new List <BulkUpdateJob> { new BulkUpdateJob { Id = contentA_1.Id, Type = BulkUpdateType.ChangeStatus, Status = "Draft" } }, CheckReferrers = false }); Assert.Null(result2[0].Error); }
public async Task Should_not_unpublish_when_referenced() { // STEP 1: Create a published referenced content. var dataA = new TestEntityWithReferencesData(); var contentA_1 = await _.Contents.CreateAsync(dataA, ContentCreateOptions.AsPublish); // STEP 2: Create a content with a reference. var dataB = new TestEntityWithReferencesData { References = new[] { contentA_1.Id } }; await _.Contents.CreateAsync(dataB, ContentCreateOptions.AsPublish); // STEP 3: Try to ThrowsAnyAsync with referrer check. await Assert.ThrowsAnyAsync <SquidexException>(() => { return(_.Contents.ChangeStatusAsync(contentA_1.Id, new ChangeStatus { Status = "Draft", // Ensure that the flag is true. CheckReferrers = true })); }); // STEP 4: Delete without referrer check await _.Contents.ChangeStatusAsync(contentA_1.Id, new ChangeStatus { Status = "Draft", // It is the default anyway, just to make it more explicit. CheckReferrers = false }); }