Adds the Offerings module and retargets the CI/CD pipeline to Api.SlpSoftware
Continuous Integration / config (pull_request) Successful in 12s
Continuous Integration / changes (pull_request) Successful in 22s
Continuous Integration / backend-build (pull_request) Successful in 5m53s
Continuous Integration / vulnerability-scan (pull_request) Successful in 5m46s
Continuous Integration / frontend-prepare (pull_request) Successful in 1m54s
Continuous Integration / backend-test (pull_request) Successful in 7m37s
Continuous Integration / frontend-build (pull_request) Successful in 2m14s
Continuous Integration / frontend-test (pull_request) Successful in 4m59s
Continuous Integration / frontend-lint (pull_request) Successful in 2m2s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 7m34s
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / config (pull_request) Successful in 12s
Continuous Integration / changes (pull_request) Successful in 22s
Continuous Integration / backend-build (pull_request) Successful in 5m53s
Continuous Integration / vulnerability-scan (pull_request) Successful in 5m46s
Continuous Integration / frontend-prepare (pull_request) Successful in 1m54s
Continuous Integration / backend-test (pull_request) Successful in 7m37s
Continuous Integration / frontend-build (pull_request) Successful in 2m14s
Continuous Integration / frontend-test (pull_request) Successful in 4m59s
Continuous Integration / frontend-lint (pull_request) Successful in 2m2s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 7m34s
Continuous Integration / deploy-test (pull_request) Skipped
Implements Unit 2 "Offerings" (backend module, admin CRUD UI with drag-and-drop reordering, public GET /api/v1/offerings endpoint) and executes the feature's D-15 CI/CD cutover, switching the deploy pipeline's build/publish target from SlpModularCms.Api to SlpModularCms.Api.SlpSoftware. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FWyStNL2ZsjrS7FLd7xvvN
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
using System.Security.Claims;
|
||||
using FluentAssertions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NSubstitute;
|
||||
using SlpModularCms.Modules.Offerings.Controllers;
|
||||
using SlpModularCms.Modules.Offerings.Models;
|
||||
using SlpModularCms.Modules.Offerings.Services;
|
||||
|
||||
namespace SlpModularCms.Modules.Offerings.Tests.Controllers;
|
||||
|
||||
public class OfferingsControllerTests
|
||||
{
|
||||
private readonly IOfferingsService _service = Substitute.For<IOfferingsService>();
|
||||
|
||||
private OfferingsController CreateSut()
|
||||
{
|
||||
var httpContext = new DefaultHttpContext
|
||||
{
|
||||
User = new ClaimsPrincipal(new ClaimsIdentity(
|
||||
[new Claim(ClaimTypes.NameIdentifier, Guid.NewGuid().ToString())], "TestAuth")),
|
||||
};
|
||||
return new OfferingsController(_service) { ControllerContext = new ControllerContext { HttpContext = httpContext } };
|
||||
}
|
||||
|
||||
private static OfferingDto PublicDto() => new(
|
||||
Guid.NewGuid().ToString(), "Title", "Description", "€ 100", "per month", ["Feature 1"], "Contact", false);
|
||||
|
||||
private static OfferingAdminDto AdminDto(int displayOrder = 0) => new(
|
||||
Guid.NewGuid().ToString(), "Title", "Description", "€ 100", "per month", ["Feature 1"], "Contact", false, displayOrder);
|
||||
|
||||
private static CreateOfferingRequest CreateRequest() => new(
|
||||
"Title", "Description", "€ 100", "per month", ["Feature 1"], "Contact");
|
||||
|
||||
private static UpdateOfferingRequest UpdateRequest() => new(
|
||||
"Title", "Description", "€ 100", "per month", ["Feature 1"], "Contact");
|
||||
|
||||
// --- GetOfferings (public) ---
|
||||
|
||||
[Fact]
|
||||
public async Task GetOfferings_Returns200_WithList()
|
||||
{
|
||||
_service.GetPublicOfferingsAsync().Returns([PublicDto()]);
|
||||
|
||||
var result = await CreateSut().GetOfferings();
|
||||
|
||||
result.Should().BeOfType<OkObjectResult>().Which.StatusCode.Should().Be(200);
|
||||
}
|
||||
|
||||
// --- GetAllForAdmin ---
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllForAdmin_Returns200_WithList()
|
||||
{
|
||||
_service.GetAllForAdminAsync().Returns([AdminDto()]);
|
||||
|
||||
var result = await CreateSut().GetAllForAdmin();
|
||||
|
||||
result.Should().BeOfType<OkObjectResult>().Which.StatusCode.Should().Be(200);
|
||||
}
|
||||
|
||||
// --- Create ---
|
||||
|
||||
[Fact]
|
||||
public async Task Create_Returns201Created()
|
||||
{
|
||||
_service.CreateAsync(Arg.Any<CreateOfferingRequest>(), Arg.Any<Guid>()).Returns(AdminDto());
|
||||
|
||||
var result = await CreateSut().Create(CreateRequest());
|
||||
|
||||
result.Should().BeOfType<CreatedAtActionResult>().Which.StatusCode.Should().Be(201);
|
||||
}
|
||||
|
||||
// --- Update ---
|
||||
|
||||
[Fact]
|
||||
public async Task Update_Returns200_WhenFound()
|
||||
{
|
||||
_service.UpdateAsync(Arg.Any<Guid>(), Arg.Any<UpdateOfferingRequest>(), Arg.Any<Guid>()).Returns(AdminDto());
|
||||
|
||||
var result = await CreateSut().Update(Guid.NewGuid(), UpdateRequest());
|
||||
|
||||
result.Should().BeOfType<OkObjectResult>().Which.StatusCode.Should().Be(200);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Update_Returns404_WhenNotFound()
|
||||
{
|
||||
_service.UpdateAsync(Arg.Any<Guid>(), Arg.Any<UpdateOfferingRequest>(), Arg.Any<Guid>())
|
||||
.Returns((OfferingAdminDto?)null);
|
||||
|
||||
var result = await CreateSut().Update(Guid.NewGuid(), UpdateRequest());
|
||||
|
||||
result.Should().BeOfType<NotFoundResult>();
|
||||
}
|
||||
|
||||
// --- Delete ---
|
||||
|
||||
[Fact]
|
||||
public async Task Delete_Returns204_WhenDeleted()
|
||||
{
|
||||
_service.DeleteAsync(Arg.Any<Guid>(), Arg.Any<Guid>()).Returns(true);
|
||||
|
||||
var result = await CreateSut().Delete(Guid.NewGuid());
|
||||
|
||||
result.Should().BeOfType<NoContentResult>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Delete_Returns404_WhenNotFound()
|
||||
{
|
||||
_service.DeleteAsync(Arg.Any<Guid>(), Arg.Any<Guid>()).Returns(false);
|
||||
|
||||
var result = await CreateSut().Delete(Guid.NewGuid());
|
||||
|
||||
result.Should().BeOfType<NotFoundResult>();
|
||||
}
|
||||
|
||||
// --- Reorder / MoveUp / MoveDown ---
|
||||
|
||||
[Fact]
|
||||
public async Task Reorder_Returns204()
|
||||
{
|
||||
var result = await CreateSut().Reorder(new ReorderOfferingsRequest([Guid.NewGuid()]));
|
||||
|
||||
result.Should().BeOfType<NoContentResult>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MoveUp_Returns204()
|
||||
{
|
||||
var result = await CreateSut().MoveUp(Guid.NewGuid());
|
||||
|
||||
result.Should().BeOfType<NoContentResult>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MoveDown_Returns204()
|
||||
{
|
||||
var result = await CreateSut().MoveDown(Guid.NewGuid());
|
||||
|
||||
result.Should().BeOfType<NoContentResult>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SlpModularCms.Modules.Offerings.Data;
|
||||
using SlpModularCms.Modules.Offerings.Data.Entities;
|
||||
using SlpModularCms.Modules.Offerings.Repositories;
|
||||
|
||||
namespace SlpModularCms.Modules.Offerings.Tests.Repositories;
|
||||
|
||||
public class OfferingRepositoryTests : IDisposable
|
||||
{
|
||||
private readonly OfferingsDbContext _context;
|
||||
private readonly OfferingRepository _sut;
|
||||
|
||||
public OfferingRepositoryTests()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<OfferingsDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.Options;
|
||||
_context = new OfferingsDbContext(options);
|
||||
_sut = new OfferingRepository(_context);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllAsync_OrdersByDisplayOrder()
|
||||
{
|
||||
await _sut.AddAsync(Offering("B", displayOrder: 1));
|
||||
await _sut.AddAsync(Offering("A", displayOrder: 0));
|
||||
await _sut.SaveChangesAsync();
|
||||
|
||||
var result = await _sut.GetAllAsync();
|
||||
|
||||
result.Select(o => o.Title).Should().ContainInOrder("A", "B");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllAsync_ExcludesSoftDeleted()
|
||||
{
|
||||
var deleted = Offering("Deleted", displayOrder: 0);
|
||||
deleted.IsDeleted = true;
|
||||
await _sut.AddAsync(deleted);
|
||||
await _sut.AddAsync(Offering("Active", displayOrder: 1));
|
||||
await _sut.SaveChangesAsync();
|
||||
|
||||
var result = await _sut.GetAllAsync();
|
||||
|
||||
result.Should().ContainSingle(o => o.Title == "Active");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetByIdAsync_ReturnsNull_WhenSoftDeleted()
|
||||
{
|
||||
var offering = Offering("Deleted", displayOrder: 0);
|
||||
offering.IsDeleted = true;
|
||||
await _sut.AddAsync(offering);
|
||||
await _sut.SaveChangesAsync();
|
||||
|
||||
var result = await _sut.GetByIdAsync(offering.Id);
|
||||
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetMaxDisplayOrderAsync_ReturnsMinusOne_WhenEmpty()
|
||||
{
|
||||
var result = await _sut.GetMaxDisplayOrderAsync();
|
||||
|
||||
result.Should().Be(-1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetMaxDisplayOrderAsync_ReturnsHighestValue()
|
||||
{
|
||||
await _sut.AddAsync(Offering("A", displayOrder: 3));
|
||||
await _sut.AddAsync(Offering("B", displayOrder: 7));
|
||||
await _sut.SaveChangesAsync();
|
||||
|
||||
var result = await _sut.GetMaxDisplayOrderAsync();
|
||||
|
||||
result.Should().Be(7);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetFeaturedAsync_ReturnsFeaturedOffering()
|
||||
{
|
||||
var featured = Offering("Featured", displayOrder: 0);
|
||||
featured.Featured = true;
|
||||
await _sut.AddAsync(featured);
|
||||
await _sut.AddAsync(Offering("Other", displayOrder: 1));
|
||||
await _sut.SaveChangesAsync();
|
||||
|
||||
var result = await _sut.GetFeaturedAsync();
|
||||
|
||||
result.Should().NotBeNull();
|
||||
result!.Title.Should().Be("Featured");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetFeaturedAsync_ReturnsNull_WhenNoneFeatured()
|
||||
{
|
||||
await _sut.AddAsync(Offering("A", displayOrder: 0));
|
||||
await _sut.SaveChangesAsync();
|
||||
|
||||
var result = await _sut.GetFeaturedAsync();
|
||||
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetPreviousAsync_ReturnsClosestLowerDisplayOrder()
|
||||
{
|
||||
await _sut.AddAsync(Offering("First", displayOrder: 0));
|
||||
await _sut.AddAsync(Offering("Second", displayOrder: 1));
|
||||
await _sut.AddAsync(Offering("Third", displayOrder: 2));
|
||||
await _sut.SaveChangesAsync();
|
||||
|
||||
var result = await _sut.GetPreviousAsync(2);
|
||||
|
||||
result!.Title.Should().Be("Second");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetPreviousAsync_ReturnsNull_WhenFirst()
|
||||
{
|
||||
await _sut.AddAsync(Offering("First", displayOrder: 0));
|
||||
await _sut.SaveChangesAsync();
|
||||
|
||||
var result = await _sut.GetPreviousAsync(0);
|
||||
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetNextAsync_ReturnsClosestHigherDisplayOrder()
|
||||
{
|
||||
await _sut.AddAsync(Offering("First", displayOrder: 0));
|
||||
await _sut.AddAsync(Offering("Second", displayOrder: 1));
|
||||
await _sut.SaveChangesAsync();
|
||||
|
||||
var result = await _sut.GetNextAsync(0);
|
||||
|
||||
result!.Title.Should().Be("Second");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetNextAsync_ReturnsNull_WhenLast()
|
||||
{
|
||||
await _sut.AddAsync(Offering("Last", displayOrder: 0));
|
||||
await _sut.SaveChangesAsync();
|
||||
|
||||
var result = await _sut.GetNextAsync(0);
|
||||
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Update_PersistsChanges()
|
||||
{
|
||||
var offering = Offering("Original", displayOrder: 0);
|
||||
await _sut.AddAsync(offering);
|
||||
await _sut.SaveChangesAsync();
|
||||
|
||||
offering.Title = "Updated";
|
||||
_sut.Update(offering);
|
||||
await _sut.SaveChangesAsync();
|
||||
|
||||
var result = await _sut.GetByIdAsync(offering.Id);
|
||||
result!.Title.Should().Be("Updated");
|
||||
}
|
||||
|
||||
private static Offering Offering(string title, int displayOrder) => new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Title = title,
|
||||
Description = "Description",
|
||||
Price = "€ 100",
|
||||
PriceNote = "per month",
|
||||
Features = ["Feature 1"],
|
||||
CtaLabel = "Contact",
|
||||
DisplayOrder = displayOrder,
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
UpdatedAt = DateTimeOffset.UtcNow,
|
||||
LastModifiedByUserId = Guid.NewGuid(),
|
||||
};
|
||||
|
||||
public void Dispose() => _context.Dispose();
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using SlpModularCms.Modules.Offerings.Data.Entities;
|
||||
using SlpModularCms.Modules.Offerings.Models;
|
||||
using SlpModularCms.Modules.Offerings.Repositories;
|
||||
using SlpModularCms.Modules.Offerings.Services;
|
||||
|
||||
namespace SlpModularCms.Modules.Offerings.Tests.Services;
|
||||
|
||||
public class OfferingsServiceTests
|
||||
{
|
||||
private readonly IOfferingRepository _repo = Substitute.For<IOfferingRepository>();
|
||||
private readonly ILogger<OfferingsService> _logger = Substitute.For<ILogger<OfferingsService>>();
|
||||
|
||||
public OfferingsServiceTests()
|
||||
{
|
||||
_repo.BeginTransactionAsync().Returns(Substitute.For<IDbContextTransaction>());
|
||||
}
|
||||
|
||||
private OfferingsService CreateSut() => new(_repo, _logger);
|
||||
|
||||
private static CreateOfferingRequest CreateRequest(bool featured = false) => new(
|
||||
"Title", "Description", "€ 100", "per month", ["Feature 1"], "Contact", featured);
|
||||
|
||||
private static Offering ExistingOffering(bool featured = false, int displayOrder = 0) => new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Title = "Existing",
|
||||
Description = "Description",
|
||||
Price = "€ 100",
|
||||
PriceNote = "per month",
|
||||
Features = ["Feature 1"],
|
||||
CtaLabel = "Contact",
|
||||
Featured = featured,
|
||||
DisplayOrder = displayOrder,
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
UpdatedAt = DateTimeOffset.UtcNow,
|
||||
LastModifiedByUserId = Guid.NewGuid(),
|
||||
};
|
||||
|
||||
// --- CreateAsync / BR-OFF-01 featured exclusivity ---
|
||||
|
||||
[Fact]
|
||||
public async Task CreateAsync_AppendsToEndOfDisplayOrder()
|
||||
{
|
||||
_repo.GetMaxDisplayOrderAsync().Returns(4);
|
||||
var callerId = Guid.NewGuid();
|
||||
|
||||
var result = await CreateSut().CreateAsync(CreateRequest(), callerId);
|
||||
|
||||
result.DisplayOrder.Should().Be(5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateAsync_SetsLastModifiedByUserId()
|
||||
{
|
||||
_repo.GetMaxDisplayOrderAsync().Returns(-1);
|
||||
var callerId = Guid.NewGuid();
|
||||
|
||||
var dto = await CreateSut().CreateAsync(CreateRequest(), callerId);
|
||||
|
||||
// The DTO doesn't expose LastModifiedByUserId (never shown to any caller) —
|
||||
// verify via the entity actually persisted through the repository instead.
|
||||
await _repo.Received(1).AddAsync(Arg.Is<Offering>(o => o.LastModifiedByUserId == callerId));
|
||||
dto.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateAsync_UnfeaturesCurrentlyFeaturedOffering_WhenNewOneIsFeatured()
|
||||
{
|
||||
var current = ExistingOffering(featured: true);
|
||||
_repo.GetFeaturedAsync().Returns(current);
|
||||
_repo.GetMaxDisplayOrderAsync().Returns(-1);
|
||||
|
||||
await CreateSut().CreateAsync(CreateRequest(featured: true), Guid.NewGuid());
|
||||
|
||||
current.Featured.Should().BeFalse();
|
||||
await _repo.Received(1).BeginTransactionAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateAsync_DoesNotTouchFeatured_WhenNewOfferingNotFeatured()
|
||||
{
|
||||
_repo.GetMaxDisplayOrderAsync().Returns(-1);
|
||||
|
||||
await CreateSut().CreateAsync(CreateRequest(featured: false), Guid.NewGuid());
|
||||
|
||||
await _repo.DidNotReceive().GetFeaturedAsync();
|
||||
await _repo.DidNotReceive().BeginTransactionAsync();
|
||||
}
|
||||
|
||||
// --- UpdateAsync ---
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateAsync_ReturnsNull_WhenOfferingNotFound()
|
||||
{
|
||||
_repo.GetByIdAsync(Arg.Any<Guid>()).Returns((Offering?)null);
|
||||
|
||||
var request = new UpdateOfferingRequest("Title", "Description", "€ 100", "per month", ["Feature 1"], "Contact");
|
||||
var result = await CreateSut().UpdateAsync(Guid.NewGuid(), request, Guid.NewGuid());
|
||||
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateAsync_UnfeaturesOtherOffering_ExceptItself()
|
||||
{
|
||||
var target = ExistingOffering(featured: false);
|
||||
var other = ExistingOffering(featured: true);
|
||||
_repo.GetByIdAsync(target.Id).Returns(target);
|
||||
_repo.GetFeaturedAsync().Returns(other);
|
||||
|
||||
var request = new UpdateOfferingRequest("Title", "Description", "€ 100", "per month", ["Feature 1"], "Contact", true);
|
||||
await CreateSut().UpdateAsync(target.Id, request, Guid.NewGuid());
|
||||
|
||||
target.Featured.Should().BeTrue();
|
||||
other.Featured.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateAsync_DoesNotUnfeatureItself_WhenAlreadyFeatured()
|
||||
{
|
||||
var target = ExistingOffering(featured: true);
|
||||
_repo.GetByIdAsync(target.Id).Returns(target);
|
||||
_repo.GetFeaturedAsync().Returns(target);
|
||||
|
||||
var request = new UpdateOfferingRequest("Title", "Description", "€ 100", "per month", ["Feature 1"], "Contact", true);
|
||||
await CreateSut().UpdateAsync(target.Id, request, Guid.NewGuid());
|
||||
|
||||
target.Featured.Should().BeTrue();
|
||||
}
|
||||
|
||||
// --- DeleteAsync / BR-OFF-02 ---
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteAsync_ReturnsFalse_WhenNotFound()
|
||||
{
|
||||
_repo.GetByIdAsync(Arg.Any<Guid>()).Returns((Offering?)null);
|
||||
|
||||
var result = await CreateSut().DeleteAsync(Guid.NewGuid(), Guid.NewGuid());
|
||||
|
||||
result.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteAsync_SoftDeletes_EvenForLastRemainingOffering()
|
||||
{
|
||||
var offering = ExistingOffering();
|
||||
_repo.GetByIdAsync(offering.Id).Returns(offering);
|
||||
|
||||
var result = await CreateSut().DeleteAsync(offering.Id, Guid.NewGuid());
|
||||
|
||||
result.Should().BeTrue();
|
||||
offering.IsDeleted.Should().BeTrue();
|
||||
offering.DeletedAt.Should().NotBeNull();
|
||||
}
|
||||
|
||||
// --- ReorderAsync / BR-OFF-03 ---
|
||||
|
||||
[Fact]
|
||||
public async Task ReorderAsync_ReassignsDisplayOrderSequentially()
|
||||
{
|
||||
var first = ExistingOffering(displayOrder: 5);
|
||||
var second = ExistingOffering(displayOrder: 2);
|
||||
_repo.GetByIdAsync(first.Id).Returns(first);
|
||||
_repo.GetByIdAsync(second.Id).Returns(second);
|
||||
|
||||
await CreateSut().ReorderAsync([first.Id, second.Id], Guid.NewGuid());
|
||||
|
||||
first.DisplayOrder.Should().Be(0);
|
||||
second.DisplayOrder.Should().Be(1);
|
||||
}
|
||||
|
||||
// --- MoveUpAsync / MoveDownAsync / BR-OFF-03 boundaries ---
|
||||
|
||||
[Fact]
|
||||
public async Task MoveUpAsync_IsNoOp_WhenAlreadyFirst()
|
||||
{
|
||||
var offering = ExistingOffering(displayOrder: 0);
|
||||
_repo.GetByIdAsync(offering.Id).Returns(offering);
|
||||
_repo.GetPreviousAsync(0).Returns((Offering?)null);
|
||||
|
||||
await CreateSut().MoveUpAsync(offering.Id, Guid.NewGuid());
|
||||
|
||||
await _repo.DidNotReceive().BeginTransactionAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MoveUpAsync_SwapsDisplayOrder_WithPrevious()
|
||||
{
|
||||
var offering = ExistingOffering(displayOrder: 1);
|
||||
var previous = ExistingOffering(displayOrder: 0);
|
||||
_repo.GetByIdAsync(offering.Id).Returns(offering);
|
||||
_repo.GetPreviousAsync(1).Returns(previous);
|
||||
|
||||
await CreateSut().MoveUpAsync(offering.Id, Guid.NewGuid());
|
||||
|
||||
offering.DisplayOrder.Should().Be(0);
|
||||
previous.DisplayOrder.Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MoveDownAsync_IsNoOp_WhenAlreadyLast()
|
||||
{
|
||||
var offering = ExistingOffering(displayOrder: 0);
|
||||
_repo.GetByIdAsync(offering.Id).Returns(offering);
|
||||
_repo.GetNextAsync(0).Returns((Offering?)null);
|
||||
|
||||
await CreateSut().MoveDownAsync(offering.Id, Guid.NewGuid());
|
||||
|
||||
await _repo.DidNotReceive().BeginTransactionAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MoveDownAsync_SwapsDisplayOrder_WithNext()
|
||||
{
|
||||
var offering = ExistingOffering(displayOrder: 0);
|
||||
var next = ExistingOffering(displayOrder: 1);
|
||||
_repo.GetByIdAsync(offering.Id).Returns(offering);
|
||||
_repo.GetNextAsync(0).Returns(next);
|
||||
|
||||
await CreateSut().MoveDownAsync(offering.Id, Guid.NewGuid());
|
||||
|
||||
offering.DisplayOrder.Should().Be(1);
|
||||
next.DisplayOrder.Should().Be(0);
|
||||
}
|
||||
|
||||
// --- GetPublicOfferingsAsync / GetAllForAdminAsync ---
|
||||
|
||||
[Fact]
|
||||
public async Task GetPublicOfferingsAsync_MapsToPublicDto()
|
||||
{
|
||||
_repo.GetAllAsync().Returns([ExistingOffering()]);
|
||||
|
||||
var result = await CreateSut().GetPublicOfferingsAsync();
|
||||
|
||||
result.Should().ContainSingle();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllForAdminAsync_IncludesDisplayOrder()
|
||||
{
|
||||
var offering = ExistingOffering(displayOrder: 3);
|
||||
_repo.GetAllAsync().Returns([offering]);
|
||||
|
||||
var result = await CreateSut().GetAllForAdminAsync();
|
||||
|
||||
result[0].DisplayOrder.Should().Be(3);
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="FluentAssertions" Version="8.10.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="10.0.9" />
|
||||
<!-- Pinned above the version DataProtection pulls transitively (FR-22, OPEN-03) — see Core.csproj -->
|
||||
<PackageReference Include="System.Security.Cryptography.Xml" Version="10.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.9" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Microsoft.Extensions.Options" />
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SlpModularCms.Modules.Offerings\SlpModularCms.Modules.Offerings.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user