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.
79 lines
2.4 KiB
79 lines
2.4 KiB
// ==========================================================================
|
|
// GeolocationPropertiesTests.cs
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex Group
|
|
// All rights reserved.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using FluentAssertions;
|
|
using Squidex.Infrastructure;
|
|
using Xunit;
|
|
|
|
namespace Squidex.Domain.Apps.Core.Schemas
|
|
{
|
|
public class GeolocationFieldPropertiesTests
|
|
{
|
|
private readonly List<ValidationError> errors = new List<ValidationError>();
|
|
|
|
[Fact]
|
|
public void Should_add_error_if_editor_is_not_valid()
|
|
{
|
|
var sut = new GeolocationFieldProperties { Editor = (GeolocationFieldEditor)123 };
|
|
|
|
sut.Validate(errors);
|
|
|
|
errors.ShouldBeEquivalentTo(
|
|
new List<ValidationError>
|
|
{
|
|
new ValidationError("Editor is not a valid value", "Editor")
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_set_or_freeze_sut()
|
|
{
|
|
var sut = new GeolocationFieldProperties();
|
|
|
|
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
|
|
{
|
|
var value =
|
|
property.PropertyType.GetTypeInfo().IsValueType ?
|
|
Activator.CreateInstance(property.PropertyType) :
|
|
null;
|
|
|
|
property.SetValue(sut, value);
|
|
|
|
var result = property.GetValue(sut);
|
|
|
|
Assert.Equal(value, result);
|
|
}
|
|
|
|
sut.Freeze();
|
|
|
|
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
|
|
{
|
|
var value =
|
|
property.PropertyType.GetTypeInfo().IsValueType ?
|
|
Activator.CreateInstance(property.PropertyType) :
|
|
null;
|
|
|
|
Assert.Throws<InvalidOperationException>(() =>
|
|
{
|
|
try
|
|
{
|
|
property.SetValue(sut, value);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex.InnerException;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|