mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-06 15:52:09 +00:00
48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
|
|
using Data.SeaHavenIndustries;
|
||
|
|
using FluentAssertions;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using SeaHaven.DataServices.Implementation;
|
||
|
|
using Xunit;
|
||
|
|
|
||
|
|
namespace Api.SeaHavenIndustries.Tests;
|
||
|
|
|
||
|
|
public class CommentDataServiceTests
|
||
|
|
{
|
||
|
|
private static ApplicationDbContext NewContext()
|
||
|
|
{
|
||
|
|
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
||
|
|
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||
|
|
.Options;
|
||
|
|
return new ApplicationDbContext(options);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task DeleteAllForWorkOrderAsync_RemovesOnlyThatWorkOrdersCommentsInOneSave()
|
||
|
|
{
|
||
|
|
await using var context = NewContext();
|
||
|
|
context.Comments.AddRange(
|
||
|
|
new Comments { Id = 1, WorkerOrderId = 5, Commenttext = "a" },
|
||
|
|
new Comments { Id = 2, WorkerOrderId = 5, Commenttext = "b" },
|
||
|
|
new Comments { Id = 3, WorkerOrderId = 9, Commenttext = "c" });
|
||
|
|
await context.SaveChangesAsync();
|
||
|
|
var service = new CommentDataService(context);
|
||
|
|
|
||
|
|
await service.DeleteAllForWorkOrderAsync(5);
|
||
|
|
|
||
|
|
context.Comments.Select(c => c.Id).Should().Equal(new[] { 3 });
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task DeleteAllForWorkOrderAsync_WithNoComments_DoesNothing()
|
||
|
|
{
|
||
|
|
await using var context = NewContext();
|
||
|
|
context.Comments.Add(new Comments { Id = 1, WorkerOrderId = 9, Commenttext = "untouched" });
|
||
|
|
await context.SaveChangesAsync();
|
||
|
|
var service = new CommentDataService(context);
|
||
|
|
|
||
|
|
await service.DeleteAllForWorkOrderAsync(5);
|
||
|
|
|
||
|
|
context.Comments.Select(c => c.Id).Should().Equal(new[] { 1 });
|
||
|
|
}
|
||
|
|
}
|