47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
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<LeedsBeerQuestDbContext>()
|
|
.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<Category[]> seedCategoryTestData()
|
|
{
|
|
var categoryTestData = TestData.CategoryTestData;
|
|
_context.Categories.AddRange(categoryTestData);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return categoryTestData;
|
|
}
|
|
} |