diff --git a/Directory.Packages.props b/Directory.Packages.props
index 3b2164c8..26bd0ea5 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -33,6 +33,7 @@
+
diff --git a/src/Yavsc.Org/Extensions/HostingExtensions.cs b/src/Yavsc.Org/Extensions/HostingExtensions.cs
index 4eedb087..1eb53c84 100644
--- a/src/Yavsc.Org/Extensions/HostingExtensions.cs
+++ b/src/Yavsc.Org/Extensions/HostingExtensions.cs
@@ -152,7 +152,7 @@ public static class HostingExtensions
if (useInMemory)
{
services.AddDbContext(options =>
- options.UseInMemoryDatabase("YavscInMemory"));
+ options.UseSqlite("Data Source=file::memory:?cache=shared"));
}
else
{
@@ -281,7 +281,7 @@ public static class HostingExtensions
var migrationsAssembly = typeof(Program).GetTypeInfo().Assembly.GetName().Name;
var connectionString = builder.Configuration.GetConnectionString(Constants.YavscConnectionStringName);
bool useInMemory = builder.Configuration.GetValue("UseInMemoryDatabase", false);
- string inMemoryDatabaseName = "YavscInMemory";
+ string sqliteInMemoryConnectionString = "Data Source=file::memory:?cache=shared";
var identityServerBuilder = builder.Services.AddIdentityServer(options =>
{
@@ -303,7 +303,7 @@ public static class HostingExtensions
{
if (useInMemory)
{
- options.ConfigureDbContext = b => b.UseInMemoryDatabase(inMemoryDatabaseName);
+ options.ConfigureDbContext = b => b.UseSqlite(sqliteInMemoryConnectionString);
}
else
{
@@ -328,7 +328,7 @@ public static class HostingExtensions
{
if (useInMemory)
{
- options.ConfigureDbContext = b => b.UseInMemoryDatabase(inMemoryDatabaseName);
+ options.ConfigureDbContext = b => b.UseSqlite(sqliteInMemoryConnectionString);
}
else
{
diff --git a/src/Yavsc.Org/Yavsc.Org.csproj b/src/Yavsc.Org/Yavsc.Org.csproj
index 790838ec..a1867d41 100644
--- a/src/Yavsc.Org/Yavsc.Org.csproj
+++ b/src/Yavsc.Org/Yavsc.Org.csproj
@@ -32,6 +32,7 @@
all
+
diff --git a/src/Yavsc.Server/Models/ApplicationDbContext.cs b/src/Yavsc.Server/Models/ApplicationDbContext.cs
index 9908fe74..0e9e717a 100644
--- a/src/Yavsc.Server/Models/ApplicationDbContext.cs
+++ b/src/Yavsc.Server/Models/ApplicationDbContext.cs
@@ -42,18 +42,30 @@ namespace Yavsc.Models
}
public ApplicationDbContext(DbContextOptions options) : base(options)
{
+ if (Database.IsRelational())
+ {
+ Database.SetCommandTimeout(180);
+ }
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
+ if (Database.IsNpgsql())
+ {
+ NOW_SQL="LOCALTIMESTAMP";
+ }
+ else
+ {
+ NOW_SQL="CURRENT_TIMESTAMP";
+ }
builder.UseIdentityByDefaultColumns();
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
builder.Entity().HasKey(x => new { x.OwnerId, x.UserId });
- builder.Entity().Property(x => x.DeclarationDate).HasDefaultValueSql("LOCALTIMESTAMP");
+ builder.Entity().Property(x => x.DeclarationDate).HasDefaultValueSql(NOW_SQL);
builder.Entity().HasKey(x => new { x.PostId, x.TagId });
builder.Entity().Property(u => u.FullName).IsRequired(false);
@@ -337,6 +349,6 @@ namespace Yavsc.Models
public DbSet DeviceFlowCodes { get; set; }
public DbSet YavscApiScopes { get; set; }
-
+ public string NOW_SQL { get; private set; }
}
}
diff --git a/test/yavscTests/WebServerFixture.cs b/test/yavscTests/WebServerFixture.cs
index 7eb5a966..1e211afb 100644
--- a/test/yavscTests/WebServerFixture.cs
+++ b/test/yavscTests/WebServerFixture.cs
@@ -1,3 +1,4 @@
+using IdentityServer8.EntityFramework.DbContexts;
using IdentityServer8.EntityFramework.Entities;
using IdentityServer8.Models;
using Microsoft.AspNetCore.Builder;
@@ -136,6 +137,12 @@ namespace isnd.tests
var builder = WebApplication.CreateBuilder();
builder.Environment.EnvironmentName = "Development";
+
+ // Set ContentRoot to the Yavsc.Org project directory so WebRootPath resolves correctly
+ var testAssemblyLocation = AppDomain.CurrentDomain.BaseDirectory;
+ var yavscOrgPath = Path.GetFullPath(Path.Combine(testAssemblyLocation, "../../src/Yavsc.Org"));
+ builder.Environment.ContentRootPath = yavscOrgPath;
+
ConfigureLogger();
builder.Configuration
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
@@ -260,8 +267,10 @@ namespace isnd.tests
private void AddAuthorizedClient(IServiceScope scope, string testClientId, string testClientSecret)
{
+ var configDb = scope.ServiceProvider.GetRequiredService();
+ if (configDb == null)
+ throw new InvalidOperationException("ConfigurationDbContext is not available for IdentityServer client seeding.");
- var db = scope.ServiceProvider.GetRequiredService();
Client testingClient = new Client
{
ClientId = testClientId,
@@ -269,57 +278,58 @@ namespace isnd.tests
AccessTokenType = 1,
BackChannelLogoutUri = SiteSettings!.Audience,
ClientName = "Testing client",
- Enabled = true
+ Enabled = true,
+ RequireClientSecret = true
};
- db.Clients.Add(testingClient);
- db.SaveChanges();
+ configDb.Clients.Add(testingClient);
+ configDb.SaveChanges();
+
ClientSecret secret = new ClientSecret
{
Value = testClientSecret.Sha256(),
+ Type = IdentityServer8.IdentityServerConstants.SecretTypes.SharedSecret,
ClientId = testingClient.Id
};
- db.ClientSecrets.Add(secret);
+ configDb.Set().Add(secret);
- var testOrigin = new ClientCorsOrigin
+ configDb.Set().Add(new ClientCorsOrigin
{
ClientId = testingClient.Id,
Origin = SiteSettings!.Audience
+ });
- };
- db.ClientCorsOrigins.Add(testOrigin);
- db.ClientGrantTypes.Add(new ClientGrantType
+ configDb.Set().Add(new ClientGrantType
{
ClientId = testingClient.Id,
GrantType = "client_credentials"
});
- db.ClientGrantTypes.Add(new ClientGrantType
+ configDb.Set().Add(new ClientGrantType
{
ClientId = testingClient.Id,
GrantType = "password"
});
- db.ClientGrantTypes.Add(new ClientGrantType
+ configDb.Set().Add(new ClientGrantType
{
ClientId = testingClient.Id,
GrantType = "code"
});
- db.ClientScopes.Add(new ClientScope
+ configDb.Set().Add(new ClientScope
{
ClientId = testingClient.Id,
Scope = "test"
});
- db.ApiScopes.Add(new IdentityServer8.EntityFramework.Entities.ApiScope
+ configDb.Set().Add(new IdentityServer8.EntityFramework.Entities.ApiScope
{
Name = "test",
Enabled = true
});
- db.ClientRedirectUris.Add(new ClientRedirectUri
+ configDb.Set().Add(new ClientRedirectUri
{
ClientId = testingClient.Id,
RedirectUri = SiteSettings!.Audience
-
});
- db.SaveChanges();
+ configDb.SaveChanges();
}
public void EnsureUser(string testingUserName, string password, string email, IServiceScope scope)