Browse Source

Better default value handling.

pull/664/head
Sebastian 5 years ago
parent
commit
626c2ce066
  1. 57
      backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs
  2. 13
      backend/tools/TestSuite/TestSuite.Shared/Model/TestEntity.cs

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

@ -132,6 +132,63 @@ namespace TestSuite.ApiTests
}
}
[Fact]
public async Task Should_create_null_text()
{
TestEntity content = null;
try
{
// STEP 1: Create a content item with a text that caused a bug before.
content = await _.Contents.CreateAsync(new TestEntityData
{
Localized = new Dictionary<string, string>
{
["en"] = null
}
}, true);
// STEP 2: Get the item and ensure that the text is the same.
var updated = await _.Contents.GetAsync(content.Id);
Assert.Null(updated.Data.Localized["en"]);
}
finally
{
if (content != null)
{
await _.Contents.DeleteAsync(content.Id);
}
}
}
[Fact]
public async Task Should_create_default_text()
{
TestEntity content = null;
try
{
// STEP 1: Create a content item with a text that caused a bug before.
content = await _.Contents.CreateAsync(new TestEntityData
{
Localized = new Dictionary<string, string>()
}, true);
// STEP 2: Get the item and ensure that the text is the same.
var updated = await _.Contents.GetAsync(content.Id);
Assert.Equal("default", updated.Data.Localized["en"]);
}
finally
{
if (content != null)
{
await _.Contents.DeleteAsync(content.Id);
}
}
}
[Fact]
public async Task Should_create_content_with_scripting()
{

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

@ -47,6 +47,15 @@ namespace TestSuite.Model
{
IsRequired = false
}
},
new UpsertSchemaFieldDto
{
Name = TestEntityData.LocalizedField,
Partitioning = "language",
Properties = new StringFieldPropertiesDto
{
DefaultValue = "default"
}
}
},
Scripts = new SchemaScriptsDto
@ -66,12 +75,16 @@ namespace TestSuite.Model
public sealed class TestEntityData
{
public static readonly string LocalizedField = nameof(Localized).ToLowerInvariant();
public static readonly string StringField = nameof(String).ToLowerInvariant();
public static readonly string NumberField = nameof(Number).ToLowerInvariant();
public static readonly string GeoField = nameof(Geo).ToLowerInvariant();
public Dictionary<string, string> Localized { get; set; }
[JsonConverter(typeof(InvariantConverter))]
public int Number { get; set; }

Loading…
Cancel
Save