From 115623ec4daa8c6fd7325479e727309a470b5aa3 Mon Sep 17 00:00:00 2001 From: Stedoss <29103029+Stedoss@users.noreply.github.com> Date: Sun, 30 Oct 2022 15:13:39 +0000 Subject: [PATCH] Add test helper for controller result values --- .../TestHelpers/ControllerTestHelper.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/backend/LeedsBeerQuest.API/LeedsBeerQuest.API.Tests/TestHelpers/ControllerTestHelper.cs b/backend/LeedsBeerQuest.API/LeedsBeerQuest.API.Tests/TestHelpers/ControllerTestHelper.cs index 738b87e..c667776 100644 --- a/backend/LeedsBeerQuest.API/LeedsBeerQuest.API.Tests/TestHelpers/ControllerTestHelper.cs +++ b/backend/LeedsBeerQuest.API/LeedsBeerQuest.API.Tests/TestHelpers/ControllerTestHelper.cs @@ -1,6 +1,18 @@ +using Microsoft.AspNetCore.Mvc; +using NUnit.Framework; + namespace LeedsBeerQuest.API.Tests.TestHelpers; -public class ControllerTestHelper +public static class ControllerTestHelper { - + public static T ActionResultToOkResultValue(IActionResult actionResult) where T : class + { + var okResult = actionResult as OkObjectResult; + Assert.NotNull(okResult); + + var resultValue = okResult!.Value as T; + Assert.NotNull(resultValue); + + return resultValue!; + } } \ No newline at end of file