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.
82 lines
2.5 KiB
82 lines
2.5 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 FluentAssertions;
|
|
using Squidex.Domain.Apps.Core.Schemas;
|
|
using Squidex.Domain.Apps.Core.TestHelpers;
|
|
using Squidex.Infrastructure.Json.Objects;
|
|
using Xunit;
|
|
|
|
namespace Squidex.Domain.Apps.Core.Operations.ValidateContent
|
|
{
|
|
public class BooleanFieldTests : IClassFixture<TranslationsFixture>
|
|
{
|
|
private readonly List<string> errors = new List<string>();
|
|
|
|
[Fact]
|
|
public void Should_instantiate_field()
|
|
{
|
|
var sut = Field(new BooleanFieldProperties());
|
|
|
|
Assert.Equal("myBoolean", sut.Name);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_not_add_error_if_null_boolean_is_valid()
|
|
{
|
|
var sut = Field(new BooleanFieldProperties());
|
|
|
|
await sut.ValidateAsync(CreateValue(null), errors);
|
|
|
|
Assert.Empty(errors);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_not_add_error_if_boolean_is_valid()
|
|
{
|
|
var sut = Field(new BooleanFieldProperties());
|
|
|
|
await sut.ValidateAsync(CreateValue(true), errors);
|
|
|
|
Assert.Empty(errors);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_add_error_if_boolean_is_required()
|
|
{
|
|
var sut = Field(new BooleanFieldProperties { IsRequired = true });
|
|
|
|
await sut.ValidateAsync(CreateValue(null), errors);
|
|
|
|
errors.Should().BeEquivalentTo(
|
|
new[] { "Field is required." });
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_add_error_if_value_is_not_valid()
|
|
{
|
|
var sut = Field(new BooleanFieldProperties());
|
|
|
|
await sut.ValidateAsync(JsonValue.Create("Invalid"), errors);
|
|
|
|
errors.Should().BeEquivalentTo(
|
|
new[] { "Invalid json type, expected boolean." });
|
|
}
|
|
|
|
private static IJsonValue CreateValue(bool? v)
|
|
{
|
|
return JsonValue.Create(v);
|
|
}
|
|
|
|
private static RootField<BooleanFieldProperties> Field(BooleanFieldProperties properties)
|
|
{
|
|
return Fields.Boolean(1, "myBoolean", Partitioning.Invariant, properties);
|
|
}
|
|
}
|
|
}
|
|
|