Fix SubscriptionServiceTests: add IPlatformSettingsService stub

Tests broke when SubscriptionService gained the platformSettings
constructor parameter in the previous session. Add NullPlatformSettingsService
stub and pass it to all 13 test instantiations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-05 21:15:03 -04:00
parent 03d3f57f7b
commit 4c070e7487
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using PowderCoating.Application.Interfaces;
using PowderCoating.Core.Entities;
using PowderCoating.Core.Enums;
using PowderCoating.Infrastructure.Data;
@@ -23,7 +24,7 @@ public class SubscriptionServiceTests
new ApplicationUser { Id = "u2", CompanyId = 7, UserName = "u2", Email = "u2@example.com", FirstName = "B", LastName = "Two", IsActive = true });
await context.SaveChangesAsync();
var service = new SubscriptionService(new UnitOfWork(context), context);
var service = new SubscriptionService(new UnitOfWork(context), context, new NullPlatformSettingsService());
var (used, max) = await service.GetUserCountAsync(7);
@@ -43,7 +44,7 @@ public class SubscriptionServiceTests
new Job { Id = 3, CompanyId = 8, JobNumber = "JOB-3", CustomerId = 1, Description = "Delivered", JobStatusId = 3, JobPriorityId = 1 });
await context.SaveChangesAsync();
var service = new SubscriptionService(new UnitOfWork(context), context);
var service = new SubscriptionService(new UnitOfWork(context), context, new NullPlatformSettingsService());
var (used, max) = await service.GetJobCountAsync(8);
@@ -76,7 +77,7 @@ public class SubscriptionServiceTests
oldQuote.CreatedAt = DateTime.UtcNow.AddMonths(-1);
await context.SaveChangesAsync();
var service = new SubscriptionService(new UnitOfWork(context), context);
var service = new SubscriptionService(new UnitOfWork(context), context, new NullPlatformSettingsService());
var (used, max) = await service.GetQuoteCountAsync(9);
@@ -94,7 +95,7 @@ public class SubscriptionServiceTests
context.Customers.Add(new Customer { Id = 1, CompanyId = 10, CompanyName = "Customer A" });
await context.SaveChangesAsync();
var service = new SubscriptionService(new UnitOfWork(context), context);
var service = new SubscriptionService(new UnitOfWork(context), context, new NullPlatformSettingsService());
var allowed = await service.CanAddCustomerAsync(10);
@@ -109,7 +110,7 @@ public class SubscriptionServiceTests
context.AiItemPredictions.Add(new AiItemPrediction { Id = 1, CompanyId = 11, CreatedAt = DateTime.UtcNow.AddDays(-1) });
await context.SaveChangesAsync();
var service = new SubscriptionService(new UnitOfWork(context), context);
var service = new SubscriptionService(new UnitOfWork(context), context, new NullPlatformSettingsService());
var allowed = await service.CanUseAiPhotoQuoteAsync(11);
@@ -123,7 +124,7 @@ public class SubscriptionServiceTests
SeedCompanyAndPlan(context, companyId: 12, plan: 6, maxAiPhotoQuotesPerMonth: 10, allowAiPhotoQuotes: false);
await context.SaveChangesAsync();
var service = new SubscriptionService(new UnitOfWork(context), context);
var service = new SubscriptionService(new UnitOfWork(context), context, new NullPlatformSettingsService());
var allowed = await service.CanUseAiPhotoQuoteAsync(12);
@@ -147,7 +148,7 @@ public class SubscriptionServiceTests
});
await context.SaveChangesAsync();
var service = new SubscriptionService(new UnitOfWork(context), context);
var service = new SubscriptionService(new UnitOfWork(context), context, new NullPlatformSettingsService());
var status = await service.GetStatusAsync(20);
@@ -171,7 +172,7 @@ public class SubscriptionServiceTests
});
await context.SaveChangesAsync();
var service = new SubscriptionService(new UnitOfWork(context), context);
var service = new SubscriptionService(new UnitOfWork(context), context, new NullPlatformSettingsService());
var status = await service.GetStatusAsync(21);
@@ -196,7 +197,7 @@ public class SubscriptionServiceTests
});
await context.SaveChangesAsync();
var service = new SubscriptionService(new UnitOfWork(context), context);
var service = new SubscriptionService(new UnitOfWork(context), context, new NullPlatformSettingsService());
var status = await service.GetStatusAsync(22);
@@ -212,7 +213,7 @@ public class SubscriptionServiceTests
company!.AiInventoryAssistEnabled = false;
await context.SaveChangesAsync();
var service = new SubscriptionService(new UnitOfWork(context), context);
var service = new SubscriptionService(new UnitOfWork(context), context, new NullPlatformSettingsService());
var enabled = await service.IsAiInventoryAssistEnabledAsync(13);
@@ -250,7 +251,7 @@ public class SubscriptionServiceTests
});
await context.SaveChangesAsync();
var service = new SubscriptionService(new UnitOfWork(context), context);
var service = new SubscriptionService(new UnitOfWork(context), context, new NullPlatformSettingsService());
var (used, max) = await service.GetJobPhotoCountAsync(14, 100);
@@ -290,7 +291,7 @@ public class SubscriptionServiceTests
});
await context.SaveChangesAsync();
var service = new SubscriptionService(new UnitOfWork(context), context);
var service = new SubscriptionService(new UnitOfWork(context), context, new NullPlatformSettingsService());
var (used, max) = await service.GetQuotePhotoCountAsync(15, 200);
@@ -308,7 +309,7 @@ public class SubscriptionServiceTests
new AiItemPrediction { Id = 2, CompanyId = 16, CreatedAt = DateTime.UtcNow.AddDays(-2) });
await context.SaveChangesAsync();
var service = new SubscriptionService(new UnitOfWork(context), context);
var service = new SubscriptionService(new UnitOfWork(context), context, new NullPlatformSettingsService());
var allowed = await service.CanUseAiPhotoQuoteAsync(16);
@@ -410,3 +411,13 @@ public class SubscriptionServiceTests
});
}
}
/// <summary>No-op stub for IPlatformSettingsService — returns defaults for all queries.</summary>
file sealed class NullPlatformSettingsService : IPlatformSettingsService
{
public Task<string?> GetAsync(string key) => Task.FromResult<string?>(null);
public Task<bool> GetBoolAsync(string key, bool defaultValue = false) => Task.FromResult(defaultValue);
public Task<int> GetIntAsync(string key, int defaultValue) => Task.FromResult(defaultValue);
public Task SetAsync(string key, string? value, string? updatedBy = null) => Task.CompletedTask;
public Task<IReadOnlyList<PlatformSetting>> GetAllAsync() => Task.FromResult<IReadOnlyList<PlatformSetting>>(Array.Empty<PlatformSetting>().ToList());
}