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.
 
 
 
 
 

54 lines
1.7 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 Squidex.Infrastructure;
using Xunit;
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().ShouldBeEquivalent(errors);
}
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().ShouldBeEquivalent(errors);
}
catch (Exception ex)
{
Assert.True(false, $"Excepted {typeof(ValidationException)}, but got {ex.GetType()}");
}
}
}
}