Browse Source

Test scripting.

pull/613/head
Sebastian 5 years ago
parent
commit
7794bb061a
  1. 1
      backend/tools/TestSuite/TestSuite.ApiTests/AssetFormatTests.cs
  2. 1
      backend/tools/TestSuite/TestSuite.ApiTests/CDNTests.cs
  3. 3
      backend/tools/TestSuite/TestSuite.ApiTests/ContentQueryTests.cs
  4. 105
      backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs
  5. 1
      backend/tools/TestSuite/TestSuite.ApiTests/LanguagesTests.cs
  6. 1
      backend/tools/TestSuite/TestSuite.ApiTests/PingTests.cs
  7. 1
      backend/tools/TestSuite/TestSuite.LoadTests/ReadingBenchmarks.cs
  8. 1
      backend/tools/TestSuite/TestSuite.LoadTests/ReadingContentBenchmarks.cs
  9. 1
      backend/tools/TestSuite/TestSuite.LoadTests/WritingBenchmarks.cs
  10. 1
      backend/tools/TestSuite/TestSuite.Shared/Fixtures/ClientManagerFixture.cs
  11. 3
      backend/tools/TestSuite/TestSuite.Shared/Fixtures/ContentQueryFixture.cs
  12. 8
      backend/tools/TestSuite/TestSuite.Shared/Model/TestEntity.cs

1
backend/tools/TestSuite/TestSuite.ApiTests/AssetFormatTests.cs

@ -12,7 +12,6 @@ using TestSuite.Fixtures;
using Xunit; using Xunit;
#pragma warning disable SA1300 // Element should begin with upper-case letter #pragma warning disable SA1300 // Element should begin with upper-case letter
#pragma warning disable SA1507 // Code should not contain multiple blank lines in a row
#pragma warning disable CS0612 // Type or member is obsolete #pragma warning disable CS0612 // Type or member is obsolete
namespace TestSuite.ApiTests namespace TestSuite.ApiTests

1
backend/tools/TestSuite/TestSuite.ApiTests/CDNTests.cs

@ -12,7 +12,6 @@ using TestSuite.Model;
using Xunit; using Xunit;
#pragma warning disable SA1300 // Element should begin with upper-case letter #pragma warning disable SA1300 // Element should begin with upper-case letter
#pragma warning disable SA1507 // Code should not contain multiple blank lines in a row
namespace TestSuite.ApiTests namespace TestSuite.ApiTests
{ {

3
backend/tools/TestSuite/TestSuite.ApiTests/ContentQueryTests.cs

@ -17,7 +17,6 @@ using TestSuite.Model;
using Xunit; using Xunit;
#pragma warning disable SA1300 // Element should begin with upper-case letter #pragma warning disable SA1300 // Element should begin with upper-case letter
#pragma warning disable SA1507 // Code should not contain multiple blank lines in a row
namespace TestSuite.ApiTests namespace TestSuite.ApiTests
{ {
@ -345,7 +344,7 @@ namespace TestSuite.ApiTests
public int Number { get; set; } public int Number { get; set; }
} }
private void AssertItems(ContentsResult<TestEntity, TestEntityData> entities, int total, int[] expected) private static void AssertItems(ContentsResult<TestEntity, TestEntityData> entities, int total, int[] expected)
{ {
Assert.Equal(total, entities.Total); Assert.Equal(total, entities.Total);
Assert.Equal(expected, entities.Items.Select(x => x.Data.Number).ToArray()); Assert.Equal(expected, entities.Items.Select(x => x.Data.Number).ToArray());

105
backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs

@ -6,6 +6,8 @@
// ========================================================================== // ==========================================================================
using System; using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks; using System.Threading.Tasks;
using Squidex.ClientLibrary; using Squidex.ClientLibrary;
using Squidex.ClientLibrary.Management; using Squidex.ClientLibrary.Management;
@ -132,6 +134,109 @@ namespace TestSuite.ApiTests
} }
} }
[Fact]
public async Task Should_create_content_with_scripting()
{
TestEntity content = null;
try
{
// STEP 1: Create a content item with a value that triggers the schema.
content = await _.Contents.CreateAsync(new TestEntityData { Number = -99 }, true);
Assert.True(content.Data.Number > 0);
}
finally
{
if (content != null)
{
await _.Contents.DeleteAsync(content.Id);
}
}
}
[Fact]
public async Task Should_create_bulk_content_with_scripting()
{
TestEntity content = null;
try
{
// STEP 1: Create content with a value that triggers the schema.
var results = await _.Contents.BulkUpdateAsync(new BulkUpdate
{
DoNotScript = false,
Jobs = new List<BulkUpdateJob>
{
new BulkUpdateJob
{
Type = Squidex.ClientLibrary.BulkUpdateType.Upsert,
Data = new
{
number = new
{
iv = -99
}
}
}
},
Publish = true
});
// STEP 2: Query content.
content = await _.Contents.GetAsync(results[0].ContentId);
Assert.True(content.Data.Number > 0);
}
finally
{
if (content != null)
{
await _.Contents.DeleteAsync(content.Id);
}
}
}
[Fact]
public async Task Should_create_bulk_content_with_scripting_but_disabled()
{
TestEntity content = null;
try
{
// STEP 1: Create content with a value that triggers the schema.
var results = await _.Contents.BulkUpdateAsync(new BulkUpdate
{
Jobs = new List<BulkUpdateJob>
{
new BulkUpdateJob
{
Type = Squidex.ClientLibrary.BulkUpdateType.Upsert,
Data = new
{
number = new
{
iv = -99
}
}
}
},
Publish = true
});
// STEP 2: Query content.
content = await _.Contents.GetAsync(results[0].ContentId);
Assert.Equal(-99, content.Data.Number);
}
finally
{
if (content != null)
{
await _.Contents.DeleteAsync(content.Id);
}
}
}
[Fact] [Fact]
public async Task Should_create_non_published_item() public async Task Should_create_non_published_item()
{ {

1
backend/tools/TestSuite/TestSuite.ApiTests/LanguagesTests.cs

@ -10,7 +10,6 @@ using TestSuite.Fixtures;
using Xunit; using Xunit;
#pragma warning disable SA1300 // Element should begin with upper-case letter #pragma warning disable SA1300 // Element should begin with upper-case letter
#pragma warning disable SA1507 // Code should not contain multiple blank lines in a row
namespace TestSuite.ApiTests namespace TestSuite.ApiTests
{ {

1
backend/tools/TestSuite/TestSuite.ApiTests/PingTests.cs

@ -10,7 +10,6 @@ using TestSuite.Fixtures;
using Xunit; using Xunit;
#pragma warning disable SA1300 // Element should begin with upper-case letter #pragma warning disable SA1300 // Element should begin with upper-case letter
#pragma warning disable SA1507 // Code should not contain multiple blank lines in a row
namespace TestSuite.ApiTests namespace TestSuite.ApiTests
{ {

1
backend/tools/TestSuite/TestSuite.LoadTests/ReadingBenchmarks.cs

@ -12,7 +12,6 @@ using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
#pragma warning disable SA1300 // Element should begin with upper-case letter #pragma warning disable SA1300 // Element should begin with upper-case letter
#pragma warning disable SA1507 // Code should not contain multiple blank lines in a row
namespace TestSuite.LoadTests namespace TestSuite.LoadTests
{ {

1
backend/tools/TestSuite/TestSuite.LoadTests/ReadingContentBenchmarks.cs

@ -11,7 +11,6 @@ using Squidex.ClientLibrary;
using Xunit; using Xunit;
#pragma warning disable SA1300 // Element should begin with upper-case letter #pragma warning disable SA1300 // Element should begin with upper-case letter
#pragma warning disable SA1507 // Code should not contain multiple blank lines in a row
namespace TestSuite.LoadTests namespace TestSuite.LoadTests
{ {

1
backend/tools/TestSuite/TestSuite.LoadTests/WritingBenchmarks.cs

@ -12,7 +12,6 @@ using TestSuite.Model;
using Xunit; using Xunit;
#pragma warning disable SA1300 // Element should begin with upper-case letter #pragma warning disable SA1300 // Element should begin with upper-case letter
#pragma warning disable SA1507 // Code should not contain multiple blank lines in a row
namespace TestSuite.LoadTests namespace TestSuite.LoadTests
{ {

1
backend/tools/TestSuite/TestSuite.Shared/Fixtures/ClientManagerFixture.cs

@ -31,6 +31,7 @@ namespace TestSuite.Fixtures
public virtual void Dispose() public virtual void Dispose()
{ {
GC.SuppressFinalize(this);
} }
} }
} }

3
backend/tools/TestSuite/TestSuite.Shared/Fixtures/ContentQueryFixture.cs

@ -5,6 +5,7 @@
// All rights reserved. Licensed under the MIT license. // All rights reserved. Licensed under the MIT license.
// ========================================================================== // ==========================================================================
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using TestSuite.Model; using TestSuite.Model;
@ -42,6 +43,8 @@ namespace TestSuite.Fixtures
await Contents.DeleteAsync(content); await Contents.DeleteAsync(content);
} }
}).Wait(); }).Wait();
GC.SuppressFinalize(this);
} }
} }
} }

8
backend/tools/TestSuite/TestSuite.Shared/Model/TestEntity.cs

@ -39,6 +39,14 @@ namespace TestSuite.Model
} }
} }
}, },
Scripts = new SchemaScriptsDto
{
Create = $@"
if (ctx.data.{TestEntityData.NumberField}.iv === -99) {{
ctx.data.{TestEntityData.NumberField}.iv = incrementCounter('my');
replace();
}}"
},
IsPublished = true IsPublished = true
}); });

Loading…
Cancel
Save