|
|
@ -8,6 +8,7 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using Squidex.ClientLibrary; |
|
|
using Squidex.ClientLibrary; |
|
|
|
|
|
using Squidex.ClientLibrary.Management; |
|
|
using TestSuite.Fixtures; |
|
|
using TestSuite.Fixtures; |
|
|
using TestSuite.Model; |
|
|
using TestSuite.Model; |
|
|
using Xunit; |
|
|
using Xunit; |
|
|
@ -27,14 +28,20 @@ namespace TestSuite.ApiTests |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_return_item_published_item() |
|
|
public async Task Should_return_published_item() |
|
|
{ |
|
|
{ |
|
|
TestEntity content = null; |
|
|
TestEntity content = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
|
|
|
// STEP 1: Create the item unpublished.
|
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }); |
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Publish the item.
|
|
|
await _.Contents.ChangeStatusAsync(content.Id, Status.Published); |
|
|
await _.Contents.ChangeStatusAsync(content.Id, Status.Published); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 3: Retrieve the item.
|
|
|
await _.Contents.GetAsync(content.Id); |
|
|
await _.Contents.GetAsync(content.Id); |
|
|
} |
|
|
} |
|
|
finally |
|
|
finally |
|
|
@ -52,10 +59,15 @@ namespace TestSuite.ApiTests |
|
|
TestEntity content = null; |
|
|
TestEntity content = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
|
|
|
// STEP 1: Create the item published.
|
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }, true); |
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Archive the item.
|
|
|
await _.Contents.ChangeStatusAsync(content.Id, Status.Archived); |
|
|
await _.Contents.ChangeStatusAsync(content.Id, Status.Archived); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 3. Get a 404 for the item because it is not published anymore.
|
|
|
await Assert.ThrowsAsync<SquidexException>(() => _.Contents.GetAsync(content.Id)); |
|
|
await Assert.ThrowsAsync<SquidexException>(() => _.Contents.GetAsync(content.Id)); |
|
|
} |
|
|
} |
|
|
finally |
|
|
finally |
|
|
@ -73,11 +85,16 @@ namespace TestSuite.ApiTests |
|
|
TestEntity content = null; |
|
|
TestEntity content = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
|
|
|
// STEP 1: Create the item unpublished.
|
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }); |
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Change the status to publiushed and then to draft.
|
|
|
await _.Contents.ChangeStatusAsync(content.Id, Status.Published); |
|
|
await _.Contents.ChangeStatusAsync(content.Id, Status.Published); |
|
|
await _.Contents.ChangeStatusAsync(content.Id, Status.Draft); |
|
|
await _.Contents.ChangeStatusAsync(content.Id, Status.Draft); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 3. Get a 404 for the item because it is not published anymore.
|
|
|
await Assert.ThrowsAsync<SquidexException>(() => _.Contents.GetAsync(content.Id)); |
|
|
await Assert.ThrowsAsync<SquidexException>(() => _.Contents.GetAsync(content.Id)); |
|
|
} |
|
|
} |
|
|
finally |
|
|
finally |
|
|
@ -97,8 +114,11 @@ namespace TestSuite.ApiTests |
|
|
TestEntity content = null; |
|
|
TestEntity content = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
|
|
|
// STEP 1: Create a content item with a text that caused a bug before.
|
|
|
content = await _.Contents.CreateAsync(new TestEntityData { String = text }, true); |
|
|
content = await _.Contents.CreateAsync(new TestEntityData { String = text }, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Get the item and ensure that the text is the same.
|
|
|
var updated = await _.Contents.GetAsync(content.Id); |
|
|
var updated = await _.Contents.GetAsync(content.Id); |
|
|
|
|
|
|
|
|
Assert.Equal(text, updated.Data.String); |
|
|
Assert.Equal(text, updated.Data.String); |
|
|
@ -118,8 +138,11 @@ namespace TestSuite.ApiTests |
|
|
TestEntity content = null; |
|
|
TestEntity content = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
|
|
|
// STEP 1: Create the item unpublished.
|
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }); |
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2. Get a 404 for the item because it is not published.
|
|
|
await Assert.ThrowsAsync<SquidexException>(() => _.Contents.GetAsync(content.Id)); |
|
|
await Assert.ThrowsAsync<SquidexException>(() => _.Contents.GetAsync(content.Id)); |
|
|
} |
|
|
} |
|
|
finally |
|
|
finally |
|
|
@ -137,8 +160,11 @@ namespace TestSuite.ApiTests |
|
|
TestEntity content = null; |
|
|
TestEntity content = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
|
|
|
// STEP 1: Create the item published.
|
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }, true); |
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Get the item.
|
|
|
await _.Contents.GetAsync(content.Id); |
|
|
await _.Contents.GetAsync(content.Id); |
|
|
} |
|
|
} |
|
|
finally |
|
|
finally |
|
|
@ -153,14 +179,43 @@ namespace TestSuite.ApiTests |
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_create_item_with_custom_id() |
|
|
public async Task Should_create_item_with_custom_id() |
|
|
{ |
|
|
{ |
|
|
|
|
|
var id = Guid.NewGuid().ToString(); |
|
|
|
|
|
|
|
|
TestEntity content = null; |
|
|
TestEntity content = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
var id = Guid.NewGuid().ToString(); |
|
|
// STEP 1: Create a new item with a custom id.
|
|
|
|
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }, id, true); |
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(id, content.Id); |
|
|
|
|
|
} |
|
|
|
|
|
finally |
|
|
|
|
|
{ |
|
|
|
|
|
if (content != null) |
|
|
|
|
|
{ |
|
|
|
|
|
await _.Contents.DeleteAsync(content.Id); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public async Task Should_not_create_item_with_custom_id_twice() |
|
|
|
|
|
{ |
|
|
|
|
|
var id = Guid.NewGuid().ToString(); |
|
|
|
|
|
|
|
|
|
|
|
TestEntity content = null; |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
// STEP 1: Create a new item with a custom id.
|
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }, id, true); |
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }, id, true); |
|
|
|
|
|
|
|
|
Assert.Equal(id, content.Id); |
|
|
Assert.Equal(id, content.Id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Create a new item with a custom id.
|
|
|
|
|
|
var ex = await Assert.ThrowsAsync<SquidexException>(() => _.Contents.CreateAsync(new TestEntityData { Number = 1 }, id, true)); |
|
|
|
|
|
|
|
|
|
|
|
Assert.Contains("\"statusCode\":409", ex.Message); |
|
|
} |
|
|
} |
|
|
finally |
|
|
finally |
|
|
{ |
|
|
{ |
|
|
@ -174,14 +229,20 @@ namespace TestSuite.ApiTests |
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_create_item_with_custom_id_and_upsert() |
|
|
public async Task Should_create_item_with_custom_id_and_upsert() |
|
|
{ |
|
|
{ |
|
|
|
|
|
var id = Guid.NewGuid().ToString(); |
|
|
|
|
|
|
|
|
TestEntity content = null; |
|
|
TestEntity content = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
var id = Guid.NewGuid().ToString(); |
|
|
// STEP 1: Upsert a new item with a custom id.
|
|
|
|
|
|
|
|
|
content = await _.Contents.UpsertAsync(id, new TestEntityData { Number = 1 }, true); |
|
|
content = await _.Contents.UpsertAsync(id, new TestEntityData { Number = 1 }, true); |
|
|
|
|
|
|
|
|
Assert.Equal(id, content.Id); |
|
|
Assert.Equal(id, content.Id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
content = await _.Contents.UpsertAsync(id, new TestEntityData { Number = 2 }, true); |
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(1, content.Version); |
|
|
} |
|
|
} |
|
|
finally |
|
|
finally |
|
|
{ |
|
|
{ |
|
|
@ -195,13 +256,16 @@ namespace TestSuite.ApiTests |
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_upsert_item() |
|
|
public async Task Should_upsert_item() |
|
|
{ |
|
|
{ |
|
|
|
|
|
var id = Guid.NewGuid().ToString(); |
|
|
|
|
|
|
|
|
TestEntity content = null; |
|
|
TestEntity content = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
var id = Guid.NewGuid().ToString(); |
|
|
// STEP 1: Upsert a new item with a custom id.
|
|
|
|
|
|
|
|
|
content = await _.Contents.UpsertAsync(id, new TestEntityData { Number = 1 }, true); |
|
|
content = await _.Contents.UpsertAsync(id, new TestEntityData { Number = 1 }, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Upsert the item with a custom id and ensure that is has been updated.
|
|
|
await _.Contents.UpsertAsync(id, new TestEntityData { Number = 2 }); |
|
|
await _.Contents.UpsertAsync(id, new TestEntityData { Number = 2 }); |
|
|
|
|
|
|
|
|
var updated = await _.Contents.GetAsync(content.Id); |
|
|
var updated = await _.Contents.GetAsync(content.Id); |
|
|
@ -223,8 +287,11 @@ namespace TestSuite.ApiTests |
|
|
TestEntity content = null; |
|
|
TestEntity content = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
|
|
|
// STEP 1: Create a new item.
|
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 2 }, true); |
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 2 }, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Update the item and ensure that the data has changed.
|
|
|
await _.Contents.UpdateAsync(content.Id, new TestEntityData { Number = 2 }); |
|
|
await _.Contents.UpdateAsync(content.Id, new TestEntityData { Number = 2 }); |
|
|
|
|
|
|
|
|
var updated = await _.Contents.GetAsync(content.Id); |
|
|
var updated = await _.Contents.GetAsync(content.Id); |
|
|
@ -246,8 +313,11 @@ namespace TestSuite.ApiTests |
|
|
TestEntity content = null; |
|
|
TestEntity content = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
|
|
|
// STEP 1: Create a new item.
|
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }, true); |
|
|
content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Update the item and ensure that the data has changed.
|
|
|
await _.Contents.PatchAsync(content.Id, new TestEntityData { Number = 2 }); |
|
|
await _.Contents.PatchAsync(content.Id, new TestEntityData { Number = 2 }); |
|
|
|
|
|
|
|
|
var updated = await _.Contents.GetAsync(content.Id); |
|
|
var updated = await _.Contents.GetAsync(content.Id); |
|
|
@ -266,10 +336,15 @@ namespace TestSuite.ApiTests |
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_delete_item() |
|
|
public async Task Should_delete_item() |
|
|
{ |
|
|
{ |
|
|
|
|
|
// STEP 1: Create a new item.
|
|
|
var content = await _.Contents.CreateAsync(new TestEntityData { Number = 2 }, true); |
|
|
var content = await _.Contents.CreateAsync(new TestEntityData { Number = 2 }, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 2: Delete the item.
|
|
|
await _.Contents.DeleteAsync(content.Id); |
|
|
await _.Contents.DeleteAsync(content.Id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 3: Retrieve all items and ensure that the deleted item does not exist.
|
|
|
var updated = await _.Contents.GetAsync(); |
|
|
var updated = await _.Contents.GetAsync(); |
|
|
|
|
|
|
|
|
Assert.DoesNotContain(updated.Items, x => x.Id == content.Id); |
|
|
Assert.DoesNotContain(updated.Items, x => x.Id == content.Id); |
|
|
|