Add venue service and tests for it

This commit is contained in:
Stedoss
2022-10-30 02:57:37 +00:00
parent 036c18a075
commit a84e0ac03c
9 changed files with 152 additions and 21 deletions

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using LeedsBeerQuest.API.Data.Models;
namespace LeedsBeerQuest.API.Tests.Data.Services;
public static class TestData
{
public static IEnumerable<Venue> VenueTestData = new[]
{
new Venue
{
Id = 1,
Name = "Venue 1",
CategoryId = 1,
Category = new Category
{
Id = 1,
Name = "Category 1"
},
Url = "Venue URL",
DateAttended = new DateTime(),
Excerpt = "Venue Excerpt",
Thumbnail = "Venue Thumbnail",
Latitude = 1.23456m,
Longitude = -4.27384m,
Address = "Venue 1 Address",
Phone = "07777777777",
Twitter = "Venue Twitter",
StarsBeer = 1.5m,
StarsAtmosphere = 3,
StarsAmenities = 4.5m,
StarsValue = 4,
Tags = new List<Tag>()
}
};
}

View File

@@ -0,0 +1,50 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using LeedsBeerQuest.API.Data.Contexts;
using LeedsBeerQuest.API.Data.Services;
using Microsoft.EntityFrameworkCore;
using NUnit.Framework;
namespace LeedsBeerQuest.API.Tests.Data.Services;
[TestFixture]
public class VenueServiceTests
{
private LeedsBeerQuestDbContext _context;
private VenueService _venueService;
[SetUp]
public void Setup()
{
var builder = new DbContextOptionsBuilder<LeedsBeerQuestDbContext>()
.UseInMemoryDatabase($"VenueServiceTests.{Guid.NewGuid().ToString()}");
_context = new LeedsBeerQuestDbContext(builder.Options);
_venueService = new VenueService(_context);
}
[Test]
public async Task GetAllVenues_ReturnsAllVenues_WhenAllVenuesArePresentInDatabase()
{
var venueTestData = TestData.VenueTestData.ToArray();
_context.Venues.AddRange(venueTestData);
await _context.SaveChangesAsync();
var result = await _venueService.GetAllVenues();
var resultArray = result.ToArray();
Assert.AreEqual(1, resultArray.Length);
Assert.AreEqual(venueTestData[0].Id, resultArray[0].Id);
Assert.AreEqual(venueTestData[0].Name, resultArray[0].Name);
}
[Test]
public async Task GetAllVenues_ReturnsNoVenues_WhenNoVenuesArePresentInDatabase()
{
var result = await _venueService.GetAllVenues();
Assert.AreEqual(0, result.Count());
}
}