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.
64 lines
1.9 KiB
64 lines
1.9 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using FluentAssertions;
|
|
using Squidex.Infrastructure.Validation;
|
|
using Xunit;
|
|
using Xunit.Sdk;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.TestHelpers
|
|
{
|
|
public static class ValidationAssert
|
|
{
|
|
public static void Throws(Action action, params ValidationError[] errors)
|
|
{
|
|
try
|
|
{
|
|
action();
|
|
|
|
Assert.True(false, $"Expected {typeof(ValidationException)} but succeeded");
|
|
}
|
|
catch (ValidationException ex)
|
|
{
|
|
ex.Errors.ToArray().Should().BeEquivalentTo(errors);
|
|
}
|
|
catch (XunitException)
|
|
{
|
|
throw;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Assert.True(false, $"Excepted {typeof(ValidationException)}, but got {ex.GetType()}");
|
|
}
|
|
}
|
|
|
|
public static async Task ThrowsAsync(Func<Task> action, params ValidationError[] errors)
|
|
{
|
|
try
|
|
{
|
|
await action();
|
|
|
|
Assert.True(false, $"Expected {typeof(ValidationException)} but succeeded");
|
|
}
|
|
catch (ValidationException ex)
|
|
{
|
|
ex.Errors.ToArray().Should().BeEquivalentTo(errors);
|
|
}
|
|
catch (XunitException)
|
|
{
|
|
throw;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Assert.True(false, $"Excepted {typeof(ValidationException)}, but got {ex.GetType()}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|