using System; using System.Linq; using System.Threading.Tasks; using LeedsBeerQuest.API.Data.Contexts; using LeedsBeerQuest.API.Data.Models; using LeedsBeerQuest.API.Data.Services; using LeedsBeerQuest.API.Data.Services.Interfaces; using Microsoft.EntityFrameworkCore; using NUnit.Framework; namespace LeedsBeerQuest.API.Tests.Data.Services; [TestFixture] public class CategoryServiceTests { private LeedsBeerQuestDbContext _context; private ICategoryService _categoryService; [SetUp] public void SetUp() { var builder = new DbContextOptionsBuilder() .UseInMemoryDatabase($"CategoryServiceTests.{Guid.NewGuid().ToString()}"); _context = new LeedsBeerQuestDbContext(builder.Options); _categoryService = new CategoryService(_context); } [Test] public async Task GetCategories_ReturnsAllCategories_WhenAllCategoriesArePresentInDatabase() { var categoryTestData = await seedCategoryTestData(); var result = await _categoryService.GetCategories(); Assert.AreEqual(categoryTestData.Length, result.Count()); } private async Task seedCategoryTestData() { var categoryTestData = TestData.CategoryTestData; _context.Categories.AddRange(categoryTestData); await _context.SaveChangesAsync(); return categoryTestData; } }