mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
3.0 KiB
84 lines
3.0 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Newtonsoft.Json;
|
|
using Squidex.ClientLibrary;
|
|
using Squidex.ClientLibrary.Management;
|
|
|
|
namespace TestSuite.Model
|
|
{
|
|
public sealed class TestEntity : Content<TestEntityData>
|
|
{
|
|
public const int ScriptTrigger = -99;
|
|
|
|
public static async Task<SchemaDetailsDto> CreateSchemaAsync(ISchemasClient schemas, string appName, string name)
|
|
{
|
|
var schema = await schemas.PostSchemaAsync(appName, new CreateSchemaDto
|
|
{
|
|
Name = name,
|
|
Fields = new List<UpsertSchemaFieldDto>
|
|
{
|
|
new UpsertSchemaFieldDto
|
|
{
|
|
Name = TestEntityData.NumberField,
|
|
Properties = new NumberFieldPropertiesDto
|
|
{
|
|
IsRequired = true
|
|
}
|
|
},
|
|
new UpsertSchemaFieldDto
|
|
{
|
|
Name = TestEntityData.StringField,
|
|
Properties = new StringFieldPropertiesDto
|
|
{
|
|
IsRequired = false
|
|
}
|
|
},
|
|
new UpsertSchemaFieldDto
|
|
{
|
|
Name = TestEntityData.GeoField,
|
|
Properties = new GeolocationFieldPropertiesDto
|
|
{
|
|
IsRequired = false
|
|
}
|
|
}
|
|
},
|
|
Scripts = new SchemaScriptsDto
|
|
{
|
|
Create = $@"
|
|
if (ctx.data.{TestEntityData.NumberField}.iv === {ScriptTrigger}) {{
|
|
ctx.data.{TestEntityData.NumberField}.iv = incrementCounter('my');
|
|
replace();
|
|
}}"
|
|
},
|
|
IsPublished = true
|
|
});
|
|
|
|
return schema;
|
|
}
|
|
}
|
|
|
|
public sealed class TestEntityData
|
|
{
|
|
public static readonly string StringField = nameof(String).ToLowerInvariant();
|
|
|
|
public static readonly string NumberField = nameof(Number).ToLowerInvariant();
|
|
|
|
public static readonly string GeoField = nameof(Geo).ToLowerInvariant();
|
|
|
|
[JsonConverter(typeof(InvariantConverter))]
|
|
public int Number { get; set; }
|
|
|
|
[JsonConverter(typeof(InvariantConverter))]
|
|
public string String { get; set; }
|
|
|
|
[JsonConverter(typeof(InvariantConverter))]
|
|
public object Geo { get; set; }
|
|
}
|
|
}
|
|
|