2026-04-19 14:40:40 +01:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using Yavsc;
|
|
|
|
|
using Yavsc.Abstract.Workflow;
|
|
|
|
|
using Yavsc.Helpers;
|
|
|
|
|
using Yavsc.Models;
|
|
|
|
|
using Yavsc.Models.Billing;
|
|
|
|
|
using Yavsc.Models.Haircut;
|
|
|
|
|
using Yavsc.Services;
|
|
|
|
|
|
2026-06-19 19:59:15 +01:00
|
|
|
namespace Yavsc
|
2026-04-19 14:40:40 +01:00
|
|
|
{
|
|
|
|
|
[Trait("regression", "II")]
|
|
|
|
|
public class BillingServiceTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ConfigureBillingService_CanBeCalledTwiceWithoutThrowing()
|
|
|
|
|
{
|
|
|
|
|
// First initialization should populate the billing registry.
|
|
|
|
|
WorkflowHelpers.ConfigureBillingService();
|
|
|
|
|
|
|
|
|
|
int firstBillingCount = BillingService.Billing.Count;
|
|
|
|
|
int firstSettingsCount = BillingService.UserSettings.Count;
|
|
|
|
|
int firstProfileTypesCount = Config.ProfileTypes.Count;
|
|
|
|
|
|
|
|
|
|
// Second call should be idempotent and not throw.
|
|
|
|
|
WorkflowHelpers.ConfigureBillingService();
|
|
|
|
|
|
|
|
|
|
Assert.Equal(firstBillingCount, BillingService.Billing.Count);
|
|
|
|
|
Assert.Equal(firstSettingsCount, BillingService.UserSettings.Count);
|
|
|
|
|
Assert.Equal(firstProfileTypesCount, Config.ProfileTypes.Count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RegisterBilling_DuplicateRegistrationThrowsInvalidOperationException()
|
|
|
|
|
{
|
|
|
|
|
WorkflowHelpers.ConfigureBillingService();
|
|
|
|
|
|
2026-07-04 22:35:53 +01:00
|
|
|
var firstRegistrar = new Func<ApplicationDbContext, long, IQuery>((db, id) =>
|
2026-04-19 14:40:40 +01:00
|
|
|
db.HairCutQueries.Include(q => q.Prestation).Include(q => q.Regularisation).Single(q => q.Id == id));
|
|
|
|
|
|
2026-04-19 20:36:03 +01:00
|
|
|
const string testCode = "Brush";
|
2026-07-04 22:35:53 +01:00
|
|
|
|
2026-04-19 14:40:40 +01:00
|
|
|
Assert.Throws<InvalidOperationException>(() =>
|
|
|
|
|
WorkflowHelpers.RegisterBilling<HairCutQuery>(testCode, firstRegistrar));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|