Headless CMS and Content Managment Hub
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.
 
 
 
 
 

76 lines
2.2 KiB

// ==========================================================================
// BooleanFieldTests.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System.Collections.Generic;
using System.Threading.Tasks;
using FluentAssertions;
using Squidex.Infrastructure;
using Xunit;
namespace Squidex.Core.Schemas
{
public class BooleanFieldTests
{
private readonly List<string> errors = new List<string>();
[Fact]
public void Should_instantiate_field()
{
var sut = new BooleanField(1, "name", new BooleanFieldProperties());
Assert.Equal("name", sut.Name);
}
[Fact]
public void Should_clone_object()
{
var sut = new BooleanField(1, "name", new BooleanFieldProperties());
Assert.NotEqual(sut, sut.Enable());
}
[Fact]
public async Task Should_not_add_error_if_valid()
{
var sut = new BooleanField(1, "name", new BooleanFieldProperties { Label = "Name" });
await sut.ValidateAsync(CreateValue(null), errors);
Assert.Empty(errors);
}
[Fact]
public async Task Should_add_errors_if_boolean_is_required()
{
var sut = new BooleanField(1, "name", new BooleanFieldProperties { Label = "Name", IsRequired = true });
await sut.ValidateAsync(CreateValue(null), errors);
errors.ShouldBeEquivalentTo(
new[] { "Name is required" });
}
[Fact]
public async Task Should_add_errors_if_value_is_not_valid()
{
var sut = new BooleanField(1, "name", new BooleanFieldProperties { Label = "Name" });
await sut.ValidateAsync(CreateValue("Invalid"), errors);
errors.ShouldBeEquivalentTo(
new[] { "Name is not a valid value" });
}
private static PropertyValue CreateValue(object v)
{
var bag = new PropertiesBag().Set("value", v);
return bag["value"];
}
}
}