"Royal-Mail-shipping-integration-and-test-improvements"
This commit is contained in:
@@ -17,7 +17,7 @@ public static class JwtTokenHelper
|
||||
string audience = "LittleShop")
|
||||
{
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.ASCII.GetBytes(secretKey);
|
||||
var key = Encoding.UTF8.GetBytes(secretKey); // Use UTF8 encoding to match Program.cs
|
||||
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.EntityFrameworkCore.InMemory;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using LittleShop.Data;
|
||||
using LittleShop.Services;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Moq;
|
||||
using System.Linq;
|
||||
|
||||
namespace LittleShop.Tests.Infrastructure;
|
||||
@@ -15,19 +20,19 @@ public class TestWebApplicationFactory : WebApplicationFactory<Program>
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
// Remove the existing DbContext registration
|
||||
var descriptor = services.SingleOrDefault(
|
||||
d => d.ServiceType == typeof(DbContextOptions<LittleShopContext>));
|
||||
|
||||
var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions<LittleShopContext>));
|
||||
if (descriptor != null)
|
||||
{
|
||||
services.Remove(descriptor);
|
||||
}
|
||||
|
||||
// Add in-memory database for testing
|
||||
// Add InMemory database for testing
|
||||
services.AddDbContext<LittleShopContext>(options =>
|
||||
{
|
||||
options.UseInMemoryDatabase("InMemoryDbForTesting");
|
||||
});
|
||||
options.UseInMemoryDatabase("InMemoryDbForTesting")
|
||||
.ConfigureWarnings(warnings => warnings.Default(WarningBehavior.Ignore)));
|
||||
|
||||
// Mock external services that might cause issues in tests
|
||||
services.Replace(ServiceDescriptor.Scoped<IPushNotificationService>(_ => Mock.Of<IPushNotificationService>()));
|
||||
services.Replace(ServiceDescriptor.Scoped<IBTCPayServerService>(_ => Mock.Of<IBTCPayServerService>()));
|
||||
services.Replace(ServiceDescriptor.Scoped<ITelegramBotManagerService>(_ => Mock.Of<ITelegramBotManagerService>()));
|
||||
|
||||
// Build service provider
|
||||
var sp = services.BuildServiceProvider();
|
||||
|
||||
Reference in New Issue
Block a user