mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-31 09:02:41 +01:00
- API and client to version 5.0.0 - Added a bunch more model validations - Added error codes - Added limits to database strings - Redid client exceptions to be more sane - Added configurable instance and user limits - Always clamp rights to their valid ranges - Add an error if the minimum password length is more than the string limit - Fixed chat bot name contraints crossing instances - Enforce that SIDs be unique globally - Normalize instance paths to forward slashes on windows. Added to sanitizer - Added migrations - Added ApiAssert for testing error codes
38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Tgstation.Server.Api.Models;
|
|
using Tgstation.Server.Client;
|
|
|
|
namespace Tgstation.Server.Tests
|
|
{
|
|
/// <summary>
|
|
/// Extension methods for the <see cref="Assert"/> <see langword="ckass"/>.
|
|
/// </summary>
|
|
static class ApiAssert
|
|
{
|
|
/// <summary>
|
|
/// Test a given <typeparamref name="TApiException"/> is thrown when a given <paramref name="action"/> is called.
|
|
/// </summary>
|
|
/// <typeparam name="TApiException">The type of the expected <see cref="ApiException"/>.</typeparam>
|
|
/// <param name="action">A <see cref="Func{TResult}"/> resulting in a <see cref="Task"/>.</param>
|
|
/// <param name="expectedErrorCode">The expected <see cref="ApiException.ErrorCode"/>.</param>
|
|
/// <returns>A <see cref="Task"/> representing the running operation,</returns>
|
|
public static async Task ThrowsException<TApiException>(Func<Task> action, ErrorCode? expectedErrorCode)
|
|
where TApiException : ApiException
|
|
{
|
|
try
|
|
{
|
|
await action().ConfigureAwait(false);
|
|
}
|
|
catch (TApiException ex)
|
|
{
|
|
Assert.AreEqual(expectedErrorCode, ex.ErrorCode, "Wrong error code for expected API exception!");
|
|
return;
|
|
}
|
|
|
|
Assert.Fail($"Expected exception {typeof(TApiException)}!");
|
|
}
|
|
}
|
|
}
|