x-lab-lbq-technical-test/backend/LeedsBeerQuest.API/LeedsBeerQuest.API.Tests/Controllers/CategoryControllerTests.cs

37 lines
1.1 KiB
C#
Raw Normal View History

2022-10-30 17:46:52 +00:00
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LeedsBeerQuest.API.Controllers;
using LeedsBeerQuest.API.Data.Models;
using LeedsBeerQuest.API.Data.Services.Interfaces;
using LeedsBeerQuest.API.Tests.Data.Services;
using LeedsBeerQuest.API.Tests.TestHelpers;
using NSubstitute;
using NUnit.Framework;
namespace LeedsBeerQuest.API.Tests.Controllers;
[TestFixture]
public class CategoryControllerTests
{
private ICategoryService _categoryService;
private CategoryController _categoryController;
[SetUp]
public void SetUp()
{
_categoryService = Substitute.For<ICategoryService>();
_categoryController = new CategoryController(_categoryService);
}
[Test]
2022-10-30 20:23:48 +00:00
public async Task GetCategories_ReturnsOk_WithAllCategories()
2022-10-30 17:46:52 +00:00
{
_categoryService.GetCategories().Returns(TestData.CategoryTestData);
var result = await _categoryController.GetCategories();
var resultObject = ControllerTestHelper.ActionResultToOkResultValue<IEnumerable<Category>>(result);
Assert.AreEqual(TestData.CategoryTestData.Length, resultObject.Count());
}
}