- Add in-memory database support for test isolation in WebServerFixture - Implement TestMailSender fake SMTP provider for email test support - Add thread synchronization to billing service registration to prevent race conditions - Make RegisterBilling<T> idempotent to safely handle reconfiguration - Configure test environment via in-memory settings (UseTestEmailSender, UseInMemoryDatabase) - Add regression tests for billing module idempotency and duplicate registration detection - Fix tests: EMaillingTests.SendEMailSynchrone, BillingServiceTests (2 tests), HaveConfigurationRoot (3 tests) All core test infrastructure tests now passing.
48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
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;
|
|
|
|
namespace yavscTests
|
|
{
|
|
[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();
|
|
|
|
var firstRegistrar = new Func<ApplicationDbContext, long, IDecidableQuery>((db, id) =>
|
|
db.HairCutQueries.Include(q => q.Prestation).Include(q => q.Regularisation).Single(q => q.Id == id));
|
|
|
|
const string testCode = "TestBrush";
|
|
|
|
Assert.Throws<InvalidOperationException>(() =>
|
|
WorkflowHelpers.RegisterBilling<HairCutQuery>(testCode, firstRegistrar));
|
|
}
|
|
}
|
|
}
|