Add test helper for controller result values

This commit is contained in:
Stedoss 2022-10-30 15:13:39 +00:00
parent d82d1b0dab
commit 115623ec4d

View File

@ -1,6 +1,18 @@
using Microsoft.AspNetCore.Mvc;
using NUnit.Framework;
namespace LeedsBeerQuest.API.Tests.TestHelpers; namespace LeedsBeerQuest.API.Tests.TestHelpers;
public class ControllerTestHelper public static class ControllerTestHelper
{ {
public static T ActionResultToOkResultValue<T>(IActionResult actionResult) where T : class
{
var okResult = actionResult as OkObjectResult;
Assert.NotNull(okResult);
var resultValue = okResult!.Value as T;
Assert.NotNull(resultValue);
return resultValue!;
}
} }