diff --git a/test/Directory.Packages.props b/test/Directory.Packages.props index fb8145376d0..a8de0f51fad 100644 --- a/test/Directory.Packages.props +++ b/test/Directory.Packages.props @@ -15,16 +15,10 @@ - - - - - - diff --git a/test/EFCore.AspNet.InMemory.FunctionalTests/AppServiceProviderFactoryTest.cs b/test/EFCore.AspNet.InMemory.FunctionalTests/AppServiceProviderFactoryTest.cs index 880c511adaa..0aef69742ae 100644 --- a/test/EFCore.AspNet.InMemory.FunctionalTests/AppServiceProviderFactoryTest.cs +++ b/test/EFCore.AspNet.InMemory.FunctionalTests/AppServiceProviderFactoryTest.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore.Design.Internal; using Microsoft.EntityFrameworkCore.Internal; +using Microsoft.EntityFrameworkCore.TestUtilities.Xunit; namespace Microsoft.EntityFrameworkCore; @@ -57,6 +58,7 @@ public static TestWebHostBuilder CreateHostBuilder(string[] args) } [ConditionalFact] + [PlatformSkipCondition(TestUtilities.Xunit.TestPlatform.Mac)] public void Create_with_no_builder_method() { var factory = new TestAppServiceProviderFactory( diff --git a/test/EFCore.AspNet.InMemory.FunctionalTests/ConfigurationDbContextInMemoryTest.cs b/test/EFCore.AspNet.InMemory.FunctionalTests/ConfigurationDbContextInMemoryTest.cs deleted file mode 100644 index 1d57f75d63e..00000000000 --- a/test/EFCore.AspNet.InMemory.FunctionalTests/ConfigurationDbContextInMemoryTest.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using IdentityServer4.EntityFramework.DbContexts; - -namespace Microsoft.EntityFrameworkCore; - -public class ConfigurationDbContextInMemoryTest(ConfigurationDbContextInMemoryTest.ConfigurationDbContextInMemoryFixture fixture) - : ConfigurationDbContextTestBase(fixture) -{ - protected override bool HasForeignKeyIndexes - => false; - - protected override void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction) - { - } - - protected override async Task ExecuteWithStrategyInTransactionAsync( - Func testOperation, - Func nestedTestOperation1 = null, - Func nestedTestOperation2 = null, - Func nestedTestOperation3 = null) - { - await base.ExecuteWithStrategyInTransactionAsync( - testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3); - await Fixture.ReseedAsync(); - } - - public class ConfigurationDbContextInMemoryFixture : ConfigurationDbContextFixtureBase - { - public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder) - => base.AddOptions(builder).ConfigureWarnings(e => e.Ignore(InMemoryEventId.TransactionIgnoredWarning)); - - protected override ITestStoreFactory TestStoreFactory - => InMemoryTestStoreFactory.Instance; - - protected override string StoreName - => "ConfigurationDbContext"; - } -} diff --git a/test/EFCore.AspNet.InMemory.FunctionalTests/EFCore.AspNet.InMemory.FunctionalTests.csproj b/test/EFCore.AspNet.InMemory.FunctionalTests/EFCore.AspNet.InMemory.FunctionalTests.csproj index abffdd03822..3774b870241 100644 --- a/test/EFCore.AspNet.InMemory.FunctionalTests/EFCore.AspNet.InMemory.FunctionalTests.csproj +++ b/test/EFCore.AspNet.InMemory.FunctionalTests/EFCore.AspNet.InMemory.FunctionalTests.csproj @@ -45,8 +45,6 @@ - - diff --git a/test/EFCore.AspNet.InMemory.FunctionalTests/PersistedGrantDbContextInMemoryTest.cs b/test/EFCore.AspNet.InMemory.FunctionalTests/PersistedGrantDbContextInMemoryTest.cs deleted file mode 100644 index d7920e7cba0..00000000000 --- a/test/EFCore.AspNet.InMemory.FunctionalTests/PersistedGrantDbContextInMemoryTest.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using IdentityServer4.EntityFramework.DbContexts; - -namespace Microsoft.EntityFrameworkCore; - -public class PersistedGrantDbContextInMemoryTest(PersistedGrantDbContextInMemoryTest.PersistedGrantDbContextInMemoryFixture fixture) - : PersistedGrantDbContextTestBase(fixture) -{ - protected override void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction) - { - } - - protected override async Task ExecuteWithStrategyInTransactionAsync( - Func testOperation, - Func nestedTestOperation1 = null, - Func nestedTestOperation2 = null, - Func nestedTestOperation3 = null) - { - await base.ExecuteWithStrategyInTransactionAsync( - testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3); - await Fixture.ReseedAsync(); - } - - public class PersistedGrantDbContextInMemoryFixture : PersistedGrantDbContextFixtureBase - { - public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder) - => base.AddOptions(builder).ConfigureWarnings(e => e.Ignore(InMemoryEventId.TransactionIgnoredWarning)); - - protected override ITestStoreFactory TestStoreFactory - => InMemoryTestStoreFactory.Instance; - - protected override string StoreName - => "PersistedGrantDbContext"; - } -} diff --git a/test/EFCore.AspNet.Specification.Tests/ConfigurationDbContextTestBase.cs b/test/EFCore.AspNet.Specification.Tests/ConfigurationDbContextTestBase.cs deleted file mode 100644 index e25deaba484..00000000000 --- a/test/EFCore.AspNet.Specification.Tests/ConfigurationDbContextTestBase.cs +++ /dev/null @@ -1,767 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using IdentityServer4.EntityFramework.DbContexts; -using IdentityServer4.EntityFramework.Entities; -using IdentityServer4.EntityFramework.Options; -using IdentityServer4.EntityFramework.Stores; - -namespace Microsoft.EntityFrameworkCore; - -public abstract class ConfigurationDbContextTestBase( - ConfigurationDbContextTestBase.ConfigurationDbContextFixtureBase fixture) - : IClassFixture - where TFixture : ConfigurationDbContextTestBase.ConfigurationDbContextFixtureBase -{ - protected ConfigurationDbContextFixtureBase Fixture { get; } = fixture; - - protected virtual bool HasForeignKeyIndexes - => true; - - [ConditionalFact( - Skip = - "VerificationException : Method System.Linq.Enumerable.MaxFloat: type argument 'System.Char' violates the constraint of type parameter 'T'.")] - public async Task Can_call_ResourceStore_FindApiScopesByNameAsync() - => await ExecuteWithStrategyInTransactionAsync( - async context => - { - await SaveApiScopes(context); - }, - async context => - { - var store = new ResourceStore(context, new FakeLogger()); - - Assert.Equal(2, (await store.FindApiScopesByNameAsync(["ApiScope2", "ApiScope1"])).Count()); - } - ); - - private static async Task SaveApiScopes(ConfigurationDbContext context) - { - context.AddRange( - new ApiScope - { - Name = "ApiScope1", - DisplayName = "ApiScope 1", - Description = "ApiScope 1", - Required = true, - Emphasize = true, - UserClaims = [], - Properties = [], - }, - new ApiScope - { - Name = "ApiScope2", - DisplayName = "ApiScope 2", - Description = "ApiScope 2", - Required = true, - Emphasize = true, - UserClaims = [], - Properties = [], - }, - new ApiScope - { - Name = "ApiScope3", - DisplayName = "ApiScope 3", - Description = "ApiScope 3", - Required = true, - Emphasize = true, - UserClaims = [], - Properties = [], - }); - - await context.SaveChangesAsync(); - } - - [ConditionalFact( - Skip = - "VerificationException : Method System.Linq.Enumerable.MaxFloat: type argument 'System.Char' violates the constraint of type parameter 'T'.")] - public async Task Can_call_ClientStore_FindClientByIdAsync() - => await ExecuteWithStrategyInTransactionAsync( - async context => - { - context.AddRange( - new Client - { - ClientId = "C1", Description = "D1", - }, - new Client - { - ClientId = "C2", Description = "D2", - }, - new Client - { - ClientId = "C3", Description = "D3", - }); - - await context.SaveChangesAsync(); - }, - async context => - { - var store = new ClientStore(context, new FakeLogger()); - - Assert.Equal("D2", (await store.FindClientByIdAsync("C2")).Description); - } - ); - - [ConditionalFact( - Skip = - "VerificationException : Method System.Linq.Enumerable.MaxFloat: type argument 'System.Char' violates the constraint of type parameter 'T'.")] - public async Task Can_call_ResourceStore_FindIdentityResourcesByScopeNameAsync() - => await ExecuteWithStrategyInTransactionAsync( - async context => - { - await SaveIdentityResources(context); - }, - async context => - { - var store = new ResourceStore(context, new FakeLogger()); - - Assert.Equal( - 2, (await store.FindIdentityResourcesByScopeNameAsync(["IdentityResource2", "IdentityResource1"])).Count()); - } - ); - - [ConditionalFact( - Skip = - "VerificationException : Method System.Linq.Enumerable.MaxFloat: type argument 'System.Char' violates the constraint of type parameter 'T'.")] - public async Task Can_call_ResourceStore_FindApiResourcesByScopeNameAsync() - => await ExecuteWithStrategyInTransactionAsync( - async context => - { - await SaveApiResources(context); - }, - async context => - { - var store = new ResourceStore(context, new FakeLogger()); - - Assert.Equal(2, (await store.FindApiResourcesByScopeNameAsync(["S1", "S4"])).Count()); - } - ); - - [ConditionalFact( - Skip = - "VerificationException : Method System.Linq.Enumerable.MaxFloat: type argument 'System.Char' violates the constraint of type parameter 'T'.")] - public async Task Can_call_ResourceStore_GetAllResourcesAsync() - => await ExecuteWithStrategyInTransactionAsync( - async context => - { - await SaveIdentityResources(context); - await SaveApiScopes(context); - await SaveApiResources(context); - }, - async context => - { - var store = new ResourceStore(context, new FakeLogger()); - - var resources = await store.GetAllResourcesAsync(); - - Assert.Equal(3, resources.ApiResources.Count); - Assert.Equal(3, resources.ApiScopes.Count); - Assert.Equal(3, resources.IdentityResources.Count); - } - ); - - private static async Task SaveIdentityResources(ConfigurationDbContext context) - { - context.AddRange( - new IdentityResource - { - Name = "IdentityResource1", - DisplayName = "IdentityResource 1", - Description = "IdentityResource 1", - Required = true, - Emphasize = true, - }, - new IdentityResource - { - Name = "IdentityResource2", - DisplayName = "IdentityResource 2", - Description = "IdentityResource 2", - Required = true, - Emphasize = true - }, - new IdentityResource - { - Name = "IdentityResource3", - DisplayName = "IdentityResource 3", - Description = "IdentityResource 3", - Required = true, - Emphasize = true - }); - - await context.SaveChangesAsync(); - } - - private static async Task SaveApiResources(ConfigurationDbContext context) - { - context.AddRange( - new ApiResource - { - Name = "ApiResource1", - DisplayName = "ApiResource 1", - Description = "ApiResource 1", - Scopes = [new ApiResourceScope { Scope = "S1" }, new ApiResourceScope { Scope = "S2" }] - }, - new ApiResource - { - Name = "ApiResource2", - DisplayName = "ApiResource 2", - Description = "ApiResource 2", - Scopes = [new ApiResourceScope { Scope = "S4" }, new ApiResourceScope { Scope = "S5" }] - }, - new ApiResource - { - Name = "ApiResource3", - DisplayName = "ApiResource 3", - Description = "ApiResource 3" - }); - - await context.SaveChangesAsync(); - } - - [ConditionalFact( - Skip = - "VerificationException : Method System.Linq.Enumerable.MaxFloat: type argument 'System.Char' violates the constraint of type parameter 'T'.")] - public async Task Can_call_ResourceStore_FindApiResourcesByNameAsync() - => await ExecuteWithStrategyInTransactionAsync( - SaveApiResources, - async context => - { - var store = new ResourceStore(context, new FakeLogger()); - - Assert.Equal(2, (await store.FindApiResourcesByNameAsync(["ApiResource2", "ApiResource1"])).Count()); - } - ); - - [ConditionalFact] - public void Can_build_ConfigurationDbContext_model() - { - using (var context = CreateContext()) - { - var entityTypeMappings = context.Model.GetEntityTypes().Select(e => new EntityTypeMapping(e)).ToList(); - - EntityTypeMapping.AssertEqual(ExpectedMappings, entityTypeMappings); - } - } - - protected virtual List ExpectedMappings - => - [ - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ApiResource", - TableName = "ApiResources", - PrimaryKey = "Key: ApiResource.Id PK", - Properties = - { - "Property: ApiResource.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - "Property: ApiResource.AllowedAccessTokenSigningAlgorithms (string) MaxLength(100)", - "Property: ApiResource.Created (DateTime) Required", - "Property: ApiResource.Description (string) MaxLength(1000)", - "Property: ApiResource.DisplayName (string) MaxLength(200)", - "Property: ApiResource.Enabled (bool) Required", - "Property: ApiResource.LastAccessed (DateTime?)", - "Property: ApiResource.Name (string) Required Index MaxLength(200)", - "Property: ApiResource.NonEditable (bool) Required", - "Property: ApiResource.ShowInDiscoveryDocument (bool) Required", - "Property: ApiResource.Updated (DateTime?)", - }, - Indexes = { "{'Name'} Unique", }, - Navigations = - { - "Navigation: ApiResource.Properties (List) Collection ToDependent ApiResourceProperty Inverse: ApiResource", - "Navigation: ApiResource.Scopes (List) Collection ToDependent ApiResourceScope Inverse: ApiResource", - "Navigation: ApiResource.Secrets (List) Collection ToDependent ApiResourceSecret Inverse: ApiResource", - "Navigation: ApiResource.UserClaims (List) Collection ToDependent ApiResourceClaim Inverse: ApiResource", - }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ApiResourceClaim", - TableName = "ApiResourceClaims", - PrimaryKey = "Key: ApiResourceClaim.Id PK", - Properties = - { - "Property: ApiResourceClaim.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: ApiResourceClaim.ApiResourceId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ApiResourceClaim.Type (string) Required MaxLength(200)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ApiResourceId'} "] : [], - FKs = - { - "ForeignKey: ApiResourceClaim {'ApiResourceId'} -> ApiResource {'Id'} Required Cascade ToDependent: UserClaims ToPrincipal: ApiResource", - }, - Navigations = - { - "Navigation: ApiResourceClaim.ApiResource (ApiResource) Required ToPrincipal ApiResource Inverse: UserClaims", - }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ApiResourceProperty", - TableName = "ApiResourceProperties", - PrimaryKey = "Key: ApiResourceProperty.Id PK", - Properties = - { - "Property: ApiResourceProperty.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: ApiResourceProperty.ApiResourceId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ApiResourceProperty.Key (string) Required MaxLength(250)", - "Property: ApiResourceProperty.Value (string) Required MaxLength(2000)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ApiResourceId'} "] : [], - FKs = - { - "ForeignKey: ApiResourceProperty {'ApiResourceId'} -> ApiResource {'Id'} Required Cascade ToDependent: Properties ToPrincipal: ApiResource", - }, - Navigations = - { - "Navigation: ApiResourceProperty.ApiResource (ApiResource) Required ToPrincipal ApiResource Inverse: Properties", - }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ApiResourceScope", - TableName = "ApiResourceScopes", - PrimaryKey = "Key: ApiResourceScope.Id PK", - Properties = - { - "Property: ApiResourceScope.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: ApiResourceScope.ApiResourceId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ApiResourceScope.Scope (string) Required MaxLength(200)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ApiResourceId'} "] : [], - FKs = - { - "ForeignKey: ApiResourceScope {'ApiResourceId'} -> ApiResource {'Id'} Required Cascade ToDependent: Scopes ToPrincipal: ApiResource", - }, - Navigations = - { - "Navigation: ApiResourceScope.ApiResource (ApiResource) Required ToPrincipal ApiResource Inverse: Scopes", - }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ApiResourceSecret", - TableName = "ApiResourceSecrets", - PrimaryKey = "Key: ApiResourceSecret.Id PK", - Properties = - { - "Property: ApiResourceSecret.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: ApiResourceSecret.ApiResourceId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ApiResourceSecret.Created (DateTime) Required", - "Property: ApiResourceSecret.Description (string) MaxLength(1000)", - "Property: ApiResourceSecret.Expiration (DateTime?)", - "Property: ApiResourceSecret.Type (string) Required MaxLength(250)", - "Property: ApiResourceSecret.Value (string) Required MaxLength(4000)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ApiResourceId'} "] : [], - FKs = - { - "ForeignKey: ApiResourceSecret {'ApiResourceId'} -> ApiResource {'Id'} Required Cascade ToDependent: Secrets ToPrincipal: ApiResource", - }, - Navigations = - { - "Navigation: ApiResourceSecret.ApiResource (ApiResource) Required ToPrincipal ApiResource Inverse: Secrets", - }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ApiScope", - TableName = "ApiScopes", - PrimaryKey = "Key: ApiScope.Id PK", - Properties = - { - "Property: ApiScope.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - "Property: ApiScope.Description (string) MaxLength(1000)", - "Property: ApiScope.DisplayName (string) MaxLength(200)", - "Property: ApiScope.Emphasize (bool) Required", - "Property: ApiScope.Enabled (bool) Required", - "Property: ApiScope.Name (string) Required Index MaxLength(200)", - "Property: ApiScope.Required (bool) Required", - "Property: ApiScope.ShowInDiscoveryDocument (bool) Required", - }, - Indexes = { "{'Name'} Unique", }, - Navigations = - { - "Navigation: ApiScope.Properties (List) Collection ToDependent ApiScopeProperty Inverse: Scope", - "Navigation: ApiScope.UserClaims (List) Collection ToDependent ApiScopeClaim Inverse: Scope", - }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ApiScopeClaim", - TableName = "ApiScopeClaims", - PrimaryKey = "Key: ApiScopeClaim.Id PK", - Properties = - { - "Property: ApiScopeClaim.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: ApiScopeClaim.ScopeId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ApiScopeClaim.Type (string) Required MaxLength(200)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ScopeId'} "] : [], - FKs = - { - "ForeignKey: ApiScopeClaim {'ScopeId'} -> ApiScope {'Id'} Required Cascade ToDependent: UserClaims ToPrincipal: Scope", - }, - Navigations = { "Navigation: ApiScopeClaim.Scope (ApiScope) Required ToPrincipal ApiScope Inverse: UserClaims", }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ApiScopeProperty", - TableName = "ApiScopeProperties", - PrimaryKey = "Key: ApiScopeProperty.Id PK", - Properties = - { - "Property: ApiScopeProperty.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - "Property: ApiScopeProperty.Key (string) Required MaxLength(250)", - $"Property: ApiScopeProperty.ScopeId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ApiScopeProperty.Value (string) Required MaxLength(2000)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ScopeId'} "] : [], - FKs = - { - "ForeignKey: ApiScopeProperty {'ScopeId'} -> ApiScope {'Id'} Required Cascade ToDependent: Properties ToPrincipal: Scope", - }, - Navigations = { "Navigation: ApiScopeProperty.Scope (ApiScope) Required ToPrincipal ApiScope Inverse: Properties", }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.Client", - TableName = "Clients", - PrimaryKey = "Key: Client.Id PK", - Properties = - { - "Property: Client.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - "Property: Client.AbsoluteRefreshTokenLifetime (int) Required", - "Property: Client.AccessTokenLifetime (int) Required", - "Property: Client.AccessTokenType (int) Required", - "Property: Client.AllowAccessTokensViaBrowser (bool) Required", - "Property: Client.AllowOfflineAccess (bool) Required", - "Property: Client.AllowPlainTextPkce (bool) Required", - "Property: Client.AllowRememberConsent (bool) Required", - "Property: Client.AllowedIdentityTokenSigningAlgorithms (string) MaxLength(100)", - "Property: Client.AlwaysIncludeUserClaimsInIdToken (bool) Required", - "Property: Client.AlwaysSendClientClaims (bool) Required", - "Property: Client.AuthorizationCodeLifetime (int) Required", - "Property: Client.BackChannelLogoutSessionRequired (bool) Required", - "Property: Client.BackChannelLogoutUri (string) MaxLength(2000)", - "Property: Client.ClientClaimsPrefix (string) MaxLength(200)", - "Property: Client.ClientId (string) Required Index MaxLength(200)", - "Property: Client.ClientName (string) MaxLength(200)", - "Property: Client.ClientUri (string) MaxLength(2000)", - "Property: Client.ConsentLifetime (int?)", - "Property: Client.Created (DateTime) Required", - "Property: Client.Description (string) MaxLength(1000)", - "Property: Client.DeviceCodeLifetime (int) Required", - "Property: Client.EnableLocalLogin (bool) Required", - "Property: Client.Enabled (bool) Required", - "Property: Client.FrontChannelLogoutSessionRequired (bool) Required", - "Property: Client.FrontChannelLogoutUri (string) MaxLength(2000)", - "Property: Client.IdentityTokenLifetime (int) Required", - "Property: Client.IncludeJwtId (bool) Required", - "Property: Client.LastAccessed (DateTime?)", - "Property: Client.LogoUri (string) MaxLength(2000)", - "Property: Client.NonEditable (bool) Required", - "Property: Client.PairWiseSubjectSalt (string) MaxLength(200)", - "Property: Client.ProtocolType (string) Required MaxLength(200)", - "Property: Client.RefreshTokenExpiration (int) Required", - "Property: Client.RefreshTokenUsage (int) Required", - "Property: Client.RequireClientSecret (bool) Required", - "Property: Client.RequireConsent (bool) Required", - "Property: Client.RequirePkce (bool) Required", - "Property: Client.RequireRequestObject (bool) Required", - "Property: Client.SlidingRefreshTokenLifetime (int) Required", - "Property: Client.UpdateAccessTokenClaimsOnRefresh (bool) Required", - "Property: Client.Updated (DateTime?)", - "Property: Client.UserCodeType (string) MaxLength(100)", - "Property: Client.UserSsoLifetime (int?)", - }, - Indexes = { "{'ClientId'} Unique", }, - Navigations = - { - "Navigation: Client.AllowedCorsOrigins (List) Collection ToDependent ClientCorsOrigin Inverse: Client", - "Navigation: Client.AllowedGrantTypes (List) Collection ToDependent ClientGrantType Inverse: Client", - "Navigation: Client.AllowedScopes (List) Collection ToDependent ClientScope Inverse: Client", - "Navigation: Client.Claims (List) Collection ToDependent ClientClaim Inverse: Client", - "Navigation: Client.ClientSecrets (List) Collection ToDependent ClientSecret Inverse: Client", - "Navigation: Client.IdentityProviderRestrictions (List) Collection ToDependent ClientIdPRestriction Inverse: Client", - "Navigation: Client.PostLogoutRedirectUris (List) Collection ToDependent ClientPostLogoutRedirectUri Inverse: Client", - "Navigation: Client.Properties (List) Collection ToDependent ClientProperty Inverse: Client", - "Navigation: Client.RedirectUris (List) Collection ToDependent ClientRedirectUri Inverse: Client", - }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ClientClaim", - TableName = "ClientClaims", - PrimaryKey = "Key: ClientClaim.Id PK", - Properties = - { - "Property: ClientClaim.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: ClientClaim.ClientId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ClientClaim.Type (string) Required MaxLength(250)", - "Property: ClientClaim.Value (string) Required MaxLength(250)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ClientId'} "] : [], - FKs = { "ForeignKey: ClientClaim {'ClientId'} -> Client {'Id'} Required Cascade ToDependent: Claims ToPrincipal: Client", }, - Navigations = { "Navigation: ClientClaim.Client (Client) Required ToPrincipal Client Inverse: Claims", }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ClientCorsOrigin", - TableName = "ClientCorsOrigins", - PrimaryKey = "Key: ClientCorsOrigin.Id PK", - Properties = - { - "Property: ClientCorsOrigin.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: ClientCorsOrigin.ClientId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ClientCorsOrigin.Origin (string) Required MaxLength(150)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ClientId'} "] : [], - FKs = - { - "ForeignKey: ClientCorsOrigin {'ClientId'} -> Client {'Id'} Required Cascade ToDependent: AllowedCorsOrigins ToPrincipal: Client", - }, - Navigations = { "Navigation: ClientCorsOrigin.Client (Client) Required ToPrincipal Client Inverse: AllowedCorsOrigins", }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ClientGrantType", - TableName = "ClientGrantTypes", - PrimaryKey = "Key: ClientGrantType.Id PK", - Properties = - { - "Property: ClientGrantType.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: ClientGrantType.ClientId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ClientGrantType.GrantType (string) Required MaxLength(250)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ClientId'} "] : [], - FKs = - { - "ForeignKey: ClientGrantType {'ClientId'} -> Client {'Id'} Required Cascade ToDependent: AllowedGrantTypes ToPrincipal: Client", - }, - Navigations = { "Navigation: ClientGrantType.Client (Client) Required ToPrincipal Client Inverse: AllowedGrantTypes", }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ClientIdPRestriction", - TableName = "ClientIdPRestrictions", - PrimaryKey = "Key: ClientIdPRestriction.Id PK", - Properties = - { - "Property: ClientIdPRestriction.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: ClientIdPRestriction.ClientId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ClientIdPRestriction.Provider (string) Required MaxLength(200)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ClientId'} "] : [], - FKs = - { - "ForeignKey: ClientIdPRestriction {'ClientId'} -> Client {'Id'} Required Cascade ToDependent: IdentityProviderRestrictions ToPrincipal: Client", - }, - Navigations = - { - "Navigation: ClientIdPRestriction.Client (Client) Required ToPrincipal Client Inverse: IdentityProviderRestrictions", - }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ClientPostLogoutRedirectUri", - TableName = "ClientPostLogoutRedirectUris", - PrimaryKey = "Key: ClientPostLogoutRedirectUri.Id PK", - Properties = - { - "Property: ClientPostLogoutRedirectUri.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: ClientPostLogoutRedirectUri.ClientId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ClientPostLogoutRedirectUri.PostLogoutRedirectUri (string) Required MaxLength(2000)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ClientId'} "] : [], - FKs = - { - "ForeignKey: ClientPostLogoutRedirectUri {'ClientId'} -> Client {'Id'} Required Cascade ToDependent: PostLogoutRedirectUris ToPrincipal: Client", - }, - Navigations = - { - "Navigation: ClientPostLogoutRedirectUri.Client (Client) Required ToPrincipal Client Inverse: PostLogoutRedirectUris", - }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ClientProperty", - TableName = "ClientProperties", - PrimaryKey = "Key: ClientProperty.Id PK", - Properties = - { - "Property: ClientProperty.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: ClientProperty.ClientId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ClientProperty.Key (string) Required MaxLength(250)", - "Property: ClientProperty.Value (string) Required MaxLength(2000)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ClientId'} "] : [], - FKs = - { - "ForeignKey: ClientProperty {'ClientId'} -> Client {'Id'} Required Cascade ToDependent: Properties ToPrincipal: Client", - }, - Navigations = { "Navigation: ClientProperty.Client (Client) Required ToPrincipal Client Inverse: Properties", }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ClientRedirectUri", - TableName = "ClientRedirectUris", - PrimaryKey = "Key: ClientRedirectUri.Id PK", - Properties = - { - "Property: ClientRedirectUri.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: ClientRedirectUri.ClientId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ClientRedirectUri.RedirectUri (string) Required MaxLength(2000)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ClientId'} "] : [], - FKs = - { - "ForeignKey: ClientRedirectUri {'ClientId'} -> Client {'Id'} Required Cascade ToDependent: RedirectUris ToPrincipal: Client", - }, - Navigations = { "Navigation: ClientRedirectUri.Client (Client) Required ToPrincipal Client Inverse: RedirectUris", }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ClientScope", - TableName = "ClientScopes", - PrimaryKey = "Key: ClientScope.Id PK", - Properties = - { - "Property: ClientScope.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: ClientScope.ClientId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ClientScope.Scope (string) Required MaxLength(200)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ClientId'} "] : [], - FKs = - { - "ForeignKey: ClientScope {'ClientId'} -> Client {'Id'} Required Cascade ToDependent: AllowedScopes ToPrincipal: Client", - }, - Navigations = { "Navigation: ClientScope.Client (Client) Required ToPrincipal Client Inverse: AllowedScopes", }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.ClientSecret", - TableName = "ClientSecrets", - PrimaryKey = "Key: ClientSecret.Id PK", - Properties = - { - "Property: ClientSecret.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: ClientSecret.ClientId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: ClientSecret.Created (DateTime) Required", - "Property: ClientSecret.Description (string) MaxLength(2000)", - "Property: ClientSecret.Expiration (DateTime?)", - "Property: ClientSecret.Type (string) Required MaxLength(250)", - "Property: ClientSecret.Value (string) Required MaxLength(4000)", - }, - Indexes = HasForeignKeyIndexes ? ["{'ClientId'} "] : [], - FKs = - { - "ForeignKey: ClientSecret {'ClientId'} -> Client {'Id'} Required Cascade ToDependent: ClientSecrets ToPrincipal: Client", - }, - Navigations = { "Navigation: ClientSecret.Client (Client) Required ToPrincipal Client Inverse: ClientSecrets", }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.IdentityResource", - TableName = "IdentityResources", - PrimaryKey = "Key: IdentityResource.Id PK", - Properties = - { - "Property: IdentityResource.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - "Property: IdentityResource.Created (DateTime) Required", - "Property: IdentityResource.Description (string) MaxLength(1000)", - "Property: IdentityResource.DisplayName (string) MaxLength(200)", - "Property: IdentityResource.Emphasize (bool) Required", - "Property: IdentityResource.Enabled (bool) Required", - "Property: IdentityResource.Name (string) Required Index MaxLength(200)", - "Property: IdentityResource.NonEditable (bool) Required", - "Property: IdentityResource.Required (bool) Required", - "Property: IdentityResource.ShowInDiscoveryDocument (bool) Required", - "Property: IdentityResource.Updated (DateTime?)", - }, - Indexes = { "{'Name'} Unique", }, - Navigations = - { - "Navigation: IdentityResource.Properties (List) Collection ToDependent IdentityResourceProperty Inverse: IdentityResource", - "Navigation: IdentityResource.UserClaims (List) Collection ToDependent IdentityResourceClaim Inverse: IdentityResource", - }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.IdentityResourceClaim", - TableName = "IdentityResourceClaims", - PrimaryKey = "Key: IdentityResourceClaim.Id PK", - Properties = - { - "Property: IdentityResourceClaim.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: IdentityResourceClaim.IdentityResourceId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: IdentityResourceClaim.Type (string) Required MaxLength(200)", - }, - Indexes = HasForeignKeyIndexes ? ["{'IdentityResourceId'} "] : [], - FKs = - { - "ForeignKey: IdentityResourceClaim {'IdentityResourceId'} -> IdentityResource {'Id'} Required Cascade ToDependent: UserClaims ToPrincipal: IdentityResource", - }, - Navigations = - { - "Navigation: IdentityResourceClaim.IdentityResource (IdentityResource) Required ToPrincipal IdentityResource Inverse: UserClaims", - }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.IdentityResourceProperty", - TableName = "IdentityResourceProperties", - PrimaryKey = "Key: IdentityResourceProperty.Id PK", - Properties = - { - "Property: IdentityResourceProperty.Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd", - $"Property: IdentityResourceProperty.IdentityResourceId (int) Required FK{(HasForeignKeyIndexes ? " Index" : "")}", - "Property: IdentityResourceProperty.Key (string) Required MaxLength(250)", - "Property: IdentityResourceProperty.Value (string) Required MaxLength(2000)", - }, - Indexes = HasForeignKeyIndexes ? ["{'IdentityResourceId'} "] : [], - FKs = - { - "ForeignKey: IdentityResourceProperty {'IdentityResourceId'} -> IdentityResource {'Id'} Required Cascade ToDependent: Properties ToPrincipal: IdentityResource", - }, - Navigations = - { - "Navigation: IdentityResourceProperty.IdentityResource (IdentityResource) Required ToPrincipal IdentityResource Inverse: Properties", - }, - } - ]; - - protected ConfigurationDbContext CreateContext() - => Fixture.CreateContext(); - - protected virtual Task ExecuteWithStrategyInTransactionAsync( - Func testOperation, - Func nestedTestOperation1 = null, - Func nestedTestOperation2 = null, - Func nestedTestOperation3 = null) - => TestHelpers.ExecuteWithStrategyInTransactionAsync( - CreateContext, UseTransaction, - testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3); - - protected virtual void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction) - => facade.UseTransaction(transaction.GetDbTransaction()); - - public abstract class ConfigurationDbContextFixtureBase : SharedStoreFixtureBase - { - protected override IServiceCollection AddServices(IServiceCollection serviceCollection) - => base.AddServices(serviceCollection) - .AddSingleton(); - - public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder) - => base.AddOptions(builder) - .EnableDetailedErrors() - .EnableSensitiveDataLogging() - .ConfigureWarnings(b => b.Default(WarningBehavior.Throw) - .Log(CoreEventId.SensitiveDataLoggingEnabledWarning) - .Log(CoreEventId.PossibleUnintendedReferenceComparisonWarning)); - - protected override bool UsePooling - => false; // The IdentityServer ConfigurationDbContext has additional service dependencies - } -} diff --git a/test/EFCore.AspNet.Specification.Tests/EFCore.AspNet.Specification.Tests.csproj b/test/EFCore.AspNet.Specification.Tests/EFCore.AspNet.Specification.Tests.csproj index 3ea53b38ea8..00355f309e4 100644 --- a/test/EFCore.AspNet.Specification.Tests/EFCore.AspNet.Specification.Tests.csproj +++ b/test/EFCore.AspNet.Specification.Tests/EFCore.AspNet.Specification.Tests.csproj @@ -51,10 +51,7 @@ - - - diff --git a/test/EFCore.AspNet.Specification.Tests/PersistedGrantDbContextTestBase.cs b/test/EFCore.AspNet.Specification.Tests/PersistedGrantDbContextTestBase.cs deleted file mode 100644 index 09ac4acdbcb..00000000000 --- a/test/EFCore.AspNet.Specification.Tests/PersistedGrantDbContextTestBase.cs +++ /dev/null @@ -1,341 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using IdentityServer4.EntityFramework; -using IdentityServer4.EntityFramework.DbContexts; -using IdentityServer4.EntityFramework.Options; -using IdentityServer4.EntityFramework.Stores; -using IdentityServer4.Models; -using IdentityServer4.Stores; -using IdentityServer4.Stores.Serialization; - -namespace Microsoft.EntityFrameworkCore; - -public abstract class PersistedGrantDbContextTestBase( - PersistedGrantDbContextTestBase.PersistedGrantDbContextFixtureBase fixture) - : IClassFixture - where TFixture : PersistedGrantDbContextTestBase.PersistedGrantDbContextFixtureBase -{ - protected PersistedGrantDbContextFixtureBase Fixture { get; } = fixture; - - [ConditionalFact] - public async Task Can_call_PersistedGrantStore_GetAllAsync() - => await ExecuteWithStrategyInTransactionAsync( - async context => - { - await SaveGrants(context); - }, - async context => - { - var store = new PersistedGrantStore(context, new FakeLogger()); - - var results = (await store.GetAllAsync( - new PersistedGrantFilter - { - Type = "T1", - SessionId = "Se1", - SubjectId = "Su1" - })).ToList(); - - Assert.Equal(2, results.Count); - } - ); - - private static async Task SaveGrants(PersistedGrantDbContext context) - { - var store = new PersistedGrantStore(context, new FakeLogger()); - await store.StoreAsync( - new PersistedGrant - { - Key = "K1", - Type = "T1", - SubjectId = "Su1", - SessionId = "Se1", - ClientId = "C1", - Description = "D1", - CreationTime = DateTime.Now, - Expiration = null, - ConsumedTime = null, - Data = "Data1" - }); - await store.StoreAsync( - new PersistedGrant - { - Key = "K2", - Type = "T1", - SubjectId = "Su1", - SessionId = "Se1", - ClientId = "C2", - Description = "D2", - CreationTime = DateTime.Now, - Expiration = DateTime.Now + new TimeSpan(1, 0, 0, 0), - ConsumedTime = null, - Data = "Data2" - }); - await store.StoreAsync( - new PersistedGrant - { - Key = "K3", - Type = "T2", - SubjectId = "Su2", - SessionId = "Se2", - ClientId = "C1", - Description = "D3", - CreationTime = DateTime.Now, - Expiration = null, - ConsumedTime = null, - Data = "Data3" - }); - } - - [ConditionalFact] - public async Task Can_call_PersistedGrantStore_GetAsync() - => await ExecuteWithStrategyInTransactionAsync( - async context => - { - await SaveGrants(context); - }, - async context => - { - var store = new PersistedGrantStore(context, new FakeLogger()); - - Assert.Equal("Data2", (await store.GetAsync("K2")).Data); - Assert.Null(await store.GetAsync("???")); - } - ); - - [ConditionalFact] - public async Task Can_call_PersistedGrantStore_RemoveAsync() - => await ExecuteWithStrategyInTransactionAsync( - async context => - { - await SaveGrants(context); - }, - async context => - { - var store = new PersistedGrantStore(context, new FakeLogger()); - - await store.RemoveAsync("K2"); - Assert.Null(await store.GetAsync("K2")); - await store.RemoveAsync("???"); - } - ); - - [ConditionalFact] - public async Task Can_call_PersistedGrantStore_RemoveAllAsync() - => await ExecuteWithStrategyInTransactionAsync( - async context => - { - await SaveGrants(context); - }, - async context => - { - var store = new PersistedGrantStore(context, new FakeLogger()); - - await store.RemoveAllAsync( - new PersistedGrantFilter - { - Type = "T1", - SessionId = "Se1", - SubjectId = "Su1" - }); - - Assert.Null(await store.GetAsync("K1")); - Assert.Null(await store.GetAsync("K2")); - Assert.NotNull(await store.GetAsync("K3")); - } - ); - - [ConditionalFact] - public async Task Can_call_TokenCleanupService_RemoveExpiredGrantsAsync() - => await ExecuteWithStrategyInTransactionAsync( - async context => - { - await SaveGrants(context); - await SaveDevices(context); - }, - async context => - { - var service = new TokenCleanupService(new OperationalStoreOptions(), context, new FakeLogger()); - - await service.RemoveExpiredGrantsAsync(); - } - ); - - [ConditionalFact] - public async Task Can_call_DeviceFlowStore_FindByUserCodeAsync() - => await ExecuteWithStrategyInTransactionAsync( - async context => - { - await SaveDevices(context); - }, - async context => - { - var store = new DeviceFlowStore(context, new PersistentGrantSerializer(), new FakeLogger()); - - Assert.Equal("D2", (await store.FindByUserCodeAsync("U2")).Description); - } - ); - - [ConditionalFact] - public async Task Can_call_DeviceFlowStore_FindByDeviceCodeAsync_and_RemoveByDeviceCodeAsync() - => await ExecuteWithStrategyInTransactionAsync( - async context => - { - await SaveDevices(context); - }, - async context => - { - var store = new DeviceFlowStore(context, new PersistentGrantSerializer(), new FakeLogger()); - - Assert.Equal("D2", (await store.FindByDeviceCodeAsync("DC2")).Description); - await store.RemoveByDeviceCodeAsync("DC2"); - Assert.Null(await store.FindByDeviceCodeAsync("DC2")); - await store.RemoveByDeviceCodeAsync("DC2"); - Assert.Null(await store.FindByDeviceCodeAsync("DC2")); - } - ); - - private static async Task SaveDevices(PersistedGrantDbContext context) - { - var store = new DeviceFlowStore(context, new PersistentGrantSerializer(), new FakeLogger()); - - await store.StoreDeviceAuthorizationAsync( - "DC1", "U1", new DeviceCode - { - CreationTime = DateTime.Now, - Lifetime = 100, - ClientId = "C1", - Description = "D1", - IsOpenId = false, - IsAuthorized = true, - RequestedScopes = new List(), - AuthorizedScopes = new List(), - SessionId = "S1" - }); - - await store.StoreDeviceAuthorizationAsync( - "DC2", "U2", new DeviceCode - { - CreationTime = DateTime.Now, - Lifetime = 100, - ClientId = "C2", - Description = "D2", - IsOpenId = false, - IsAuthorized = true, - RequestedScopes = new List(), - AuthorizedScopes = new List(), - SessionId = "S2" - }); - - await store.StoreDeviceAuthorizationAsync( - "DC3", "U3", new DeviceCode - { - CreationTime = DateTime.Now, - Lifetime = 100, - ClientId = "C3", - Description = "D3", - IsOpenId = false, - IsAuthorized = true, - RequestedScopes = new List(), - AuthorizedScopes = new List(), - SessionId = "S3" - }); - } - - [ConditionalFact] - public void Can_build_PersistedGrantDbContext_model() - { - using (var context = CreateContext()) - { - var entityTypeMappings = context.Model.GetEntityTypes().Select(e => new EntityTypeMapping(e)).ToList(); - - EntityTypeMapping.AssertEqual(ExpectedMappings, entityTypeMappings); - } - } - - protected virtual List ExpectedMappings - => - [ - new() - { - Name = "IdentityServer4.EntityFramework.Entities.DeviceFlowCodes", - TableName = "DeviceCodes", - PrimaryKey = "Key: DeviceFlowCodes.UserCode PK", - Properties = - { - "Property: DeviceFlowCodes.UserCode (string) Required PK AfterSave:Throw MaxLength(200)", - "Property: DeviceFlowCodes.ClientId (string) Required MaxLength(200)", - "Property: DeviceFlowCodes.CreationTime (DateTime) Required", - "Property: DeviceFlowCodes.Data (string) Required MaxLength(50000)", - "Property: DeviceFlowCodes.Description (string) MaxLength(200)", - "Property: DeviceFlowCodes.DeviceCode (string) Required Index MaxLength(200)", - "Property: DeviceFlowCodes.Expiration (DateTime?) Required Index", - "Property: DeviceFlowCodes.SessionId (string) MaxLength(100)", - "Property: DeviceFlowCodes.SubjectId (string) MaxLength(200)", - }, - Indexes = - { - "{'DeviceCode'} Unique", "{'Expiration'} ", - }, - }, - new() - { - Name = "IdentityServer4.EntityFramework.Entities.PersistedGrant", - TableName = "PersistedGrants", - PrimaryKey = "Key: PersistedGrant.Key PK", - Properties = - { - "Property: PersistedGrant.Key (string) Required PK AfterSave:Throw MaxLength(200)", - "Property: PersistedGrant.ClientId (string) Required Index MaxLength(200)", - "Property: PersistedGrant.ConsumedTime (DateTime?)", - "Property: PersistedGrant.CreationTime (DateTime) Required", - "Property: PersistedGrant.Data (string) Required MaxLength(50000)", - "Property: PersistedGrant.Description (string) MaxLength(200)", - "Property: PersistedGrant.Expiration (DateTime?) Index", - "Property: PersistedGrant.SessionId (string) Index MaxLength(100)", - "Property: PersistedGrant.SubjectId (string) Index MaxLength(200)", - "Property: PersistedGrant.Type (string) Required Index MaxLength(50)", - }, - Indexes = - { - "{'Expiration'} ", - "{'SubjectId', 'ClientId', 'Type'} ", - "{'SubjectId', 'SessionId', 'Type'} ", - }, - } - ]; - - protected PersistedGrantDbContext CreateContext() - => Fixture.CreateContext(); - - protected virtual Task ExecuteWithStrategyInTransactionAsync( - Func testOperation, - Func nestedTestOperation1 = null, - Func nestedTestOperation2 = null, - Func nestedTestOperation3 = null) - => TestHelpers.ExecuteWithStrategyInTransactionAsync( - CreateContext, UseTransaction, - testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3); - - protected virtual void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction) - => facade.UseTransaction(transaction.GetDbTransaction()); - - public abstract class PersistedGrantDbContextFixtureBase : SharedStoreFixtureBase - { - protected override IServiceCollection AddServices(IServiceCollection serviceCollection) - => base.AddServices(serviceCollection) - .AddSingleton(); - - public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder) - => base.AddOptions(builder) - .EnableDetailedErrors() - .EnableSensitiveDataLogging() - .ConfigureWarnings(b => b.Default(WarningBehavior.Throw) - .Log(CoreEventId.SensitiveDataLoggingEnabledWarning) - .Log(CoreEventId.PossibleUnintendedReferenceComparisonWarning)); - - protected override bool UsePooling - => false; // The IdentityServer ConfigurationDbContext has additional service dependencies - } -} diff --git a/test/EFCore.AspNet.SqlServer.FunctionalTests/ConfigurationDbContextSqlServerTest.cs b/test/EFCore.AspNet.SqlServer.FunctionalTests/ConfigurationDbContextSqlServerTest.cs deleted file mode 100644 index 1ad02f08ccb..00000000000 --- a/test/EFCore.AspNet.SqlServer.FunctionalTests/ConfigurationDbContextSqlServerTest.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.EntityFrameworkCore; - -public class ConfigurationDbContextSqlServerTest(ConfigurationDbContextSqlServerTest.ConfigurationDbContextSqlServerFixture fixture) - : ConfigurationDbContextTestBase(fixture) -{ - public class ConfigurationDbContextSqlServerFixture : ConfigurationDbContextFixtureBase - { - protected override ITestStoreFactory TestStoreFactory - => SqlServerTestStoreFactory.Instance; - - protected override string StoreName - => "ConfigurationDbContext"; - } -} diff --git a/test/EFCore.AspNet.SqlServer.FunctionalTests/EFCore.AspNet.SqlServer.FunctionalTests.csproj b/test/EFCore.AspNet.SqlServer.FunctionalTests/EFCore.AspNet.SqlServer.FunctionalTests.csproj index 9a527a88ac1..ed3086b264d 100644 --- a/test/EFCore.AspNet.SqlServer.FunctionalTests/EFCore.AspNet.SqlServer.FunctionalTests.csproj +++ b/test/EFCore.AspNet.SqlServer.FunctionalTests/EFCore.AspNet.SqlServer.FunctionalTests.csproj @@ -50,8 +50,6 @@ - - diff --git a/test/EFCore.AspNet.SqlServer.FunctionalTests/PersistedGrantDbContextSqlServerTest.cs b/test/EFCore.AspNet.SqlServer.FunctionalTests/PersistedGrantDbContextSqlServerTest.cs deleted file mode 100644 index c307d9ebb0c..00000000000 --- a/test/EFCore.AspNet.SqlServer.FunctionalTests/PersistedGrantDbContextSqlServerTest.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.EntityFrameworkCore; - -public class PersistedGrantDbContextSqlServerTest(PersistedGrantDbContextSqlServerTest.PersistedGrantDbContextSqlServerFixture fixture) - : PersistedGrantDbContextTestBase(fixture) -{ - public class PersistedGrantDbContextSqlServerFixture : PersistedGrantDbContextFixtureBase - { - protected override ITestStoreFactory TestStoreFactory - => SqlServerTestStoreFactory.Instance; - - protected override string StoreName - => "PersistedGrantDbContext"; - } -} diff --git a/test/EFCore.AspNet.Sqlite.FunctionalTests/ConfigurationDbContextSqliteTest.cs b/test/EFCore.AspNet.Sqlite.FunctionalTests/ConfigurationDbContextSqliteTest.cs deleted file mode 100644 index 9ba31d37094..00000000000 --- a/test/EFCore.AspNet.Sqlite.FunctionalTests/ConfigurationDbContextSqliteTest.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.EntityFrameworkCore; - -public class ConfigurationDbContextSqliteTest(ConfigurationDbContextSqliteTest.ConfigurationDbContextSqliteFixture fixture) - : ConfigurationDbContextTestBase(fixture) -{ - public class ConfigurationDbContextSqliteFixture : ConfigurationDbContextFixtureBase - { - protected override ITestStoreFactory TestStoreFactory - => SqliteTestStoreFactory.Instance; - - protected override string StoreName - => "ConfigurationDbContext"; - } -} diff --git a/test/EFCore.AspNet.Sqlite.FunctionalTests/EFCore.AspNet.Sqlite.FunctionalTests.csproj b/test/EFCore.AspNet.Sqlite.FunctionalTests/EFCore.AspNet.Sqlite.FunctionalTests.csproj index 9c670219fb4..5838fe849ea 100644 --- a/test/EFCore.AspNet.Sqlite.FunctionalTests/EFCore.AspNet.Sqlite.FunctionalTests.csproj +++ b/test/EFCore.AspNet.Sqlite.FunctionalTests/EFCore.AspNet.Sqlite.FunctionalTests.csproj @@ -49,8 +49,6 @@ - - diff --git a/test/EFCore.AspNet.Sqlite.FunctionalTests/PersistedGrantDbContextSqliteTest.cs b/test/EFCore.AspNet.Sqlite.FunctionalTests/PersistedGrantDbContextSqliteTest.cs deleted file mode 100644 index 8c480f5dba4..00000000000 --- a/test/EFCore.AspNet.Sqlite.FunctionalTests/PersistedGrantDbContextSqliteTest.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.EntityFrameworkCore; - -public class PersistedGrantDbContextSqliteTest(PersistedGrantDbContextSqliteTest.PersistedGrantDbContextSqliteFixture fixture) - : PersistedGrantDbContextTestBase(fixture) -{ - public class PersistedGrantDbContextSqliteFixture : PersistedGrantDbContextFixtureBase - { - protected override ITestStoreFactory TestStoreFactory - => SqliteTestStoreFactory.Instance; - - protected override string StoreName - => "PersistedGrantDbContext"; - } -} diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/JsonQueryJsonTypeSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/JsonQueryJsonTypeSqlServerTest.cs index 71b9815e0f3..5a46b59f420 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/JsonQueryJsonTypeSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/JsonQueryJsonTypeSqlServerTest.cs @@ -28,27 +28,27 @@ FROM [JsonEntitiesBasic] AS [j] """); } -// public override async Task Basic_json_projection_owner_entity_duplicated(bool async) -// { -// await base.Basic_json_projection_owner_entity_duplicated(async); - -// AssertSql( -// """ -//SELECT [j].[Id], [j].[EntityBasicId], [j].[Name], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot] -//FROM [JsonEntitiesBasic] AS [j] -//"""); -// } - -// public override async Task Basic_json_projection_owner_entity_duplicated_NoTracking(bool async) -// { -// await base.Basic_json_projection_owner_entity_duplicated_NoTracking(async); - -// AssertSql( -// """ -//SELECT [j].[Id], [j].[Name], [j].[OwnedCollection], [j].[OwnedCollection] -//FROM [JsonEntitiesSingleOwned] AS [j] -//"""); -// } + // public override async Task Basic_json_projection_owner_entity_duplicated(bool async) + // { + // await base.Basic_json_projection_owner_entity_duplicated(async); + + // AssertSql( + // """ + //SELECT [j].[Id], [j].[EntityBasicId], [j].[Name], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot] + //FROM [JsonEntitiesBasic] AS [j] + //"""); + // } + + // public override async Task Basic_json_projection_owner_entity_duplicated_NoTracking(bool async) + // { + // await base.Basic_json_projection_owner_entity_duplicated_NoTracking(async); + + // AssertSql( + // """ + //SELECT [j].[Id], [j].[Name], [j].[OwnedCollection], [j].[OwnedCollection] + //FROM [JsonEntitiesSingleOwned] AS [j] + //"""); + // } public override async Task Basic_json_projection_owner_entity_duplicated_NoTrackingWithIdentityResolution(bool async) { @@ -61,27 +61,27 @@ FROM [JsonEntitiesSingleOwned] AS [j] """); } -// public override async Task Basic_json_projection_owner_entity_twice(bool async) -// { -// await base.Basic_json_projection_owner_entity_twice(async); + // public override async Task Basic_json_projection_owner_entity_twice(bool async) + // { + // await base.Basic_json_projection_owner_entity_twice(async); -// AssertSql( -// """ -//SELECT [j].[Id], [j].[EntityBasicId], [j].[Name], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot] -//FROM [JsonEntitiesBasic] AS [j] -//"""); -// } + // AssertSql( + // """ + //SELECT [j].[Id], [j].[EntityBasicId], [j].[Name], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot] + //FROM [JsonEntitiesBasic] AS [j] + //"""); + // } -// public override async Task Basic_json_projection_owner_entity_twice_NoTracking(bool async) -// { -// await base.Basic_json_projection_owner_entity_twice_NoTracking(async); + // public override async Task Basic_json_projection_owner_entity_twice_NoTracking(bool async) + // { + // await base.Basic_json_projection_owner_entity_twice_NoTracking(async); -// AssertSql( -// """ -//SELECT [j].[Id], [j].[EntityBasicId], [j].[Name], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot] -//FROM [JsonEntitiesBasic] AS [j] -//"""); -// } + // AssertSql( + // """ + //SELECT [j].[Id], [j].[EntityBasicId], [j].[Name], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot] + //FROM [JsonEntitiesBasic] AS [j] + //"""); + // } public override async Task Basic_json_projection_owner_entity_twice_NoTrackingWithIdentityResolution(bool async) { @@ -105,17 +105,17 @@ FROM [JsonEntitiesBasic] AS [j] """); } -// public override async Task Basic_json_projection_owned_reference_duplicated(bool async) -// { -// await base.Basic_json_projection_owned_reference_duplicated(async); + // public override async Task Basic_json_projection_owned_reference_duplicated(bool async) + // { + // await base.Basic_json_projection_owned_reference_duplicated(async); -// AssertSql( -// """ -//SELECT [j].[OwnedReferenceRoot], [j].[Id], JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch'), [j].[OwnedReferenceRoot], JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch') -//FROM [JsonEntitiesBasic] AS [j] -//ORDER BY [j].[Id] -//"""); -// } + // AssertSql( + // """ + //SELECT [j].[OwnedReferenceRoot], [j].[Id], JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch'), [j].[OwnedReferenceRoot], JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch') + //FROM [JsonEntitiesBasic] AS [j] + //ORDER BY [j].[Id] + //"""); + // } public override async Task Basic_json_projection_owned_reference_duplicated_NoTrackingWithIdentityResolution(bool async) { @@ -129,17 +129,17 @@ ORDER BY [j].[Id] """); } -// public override async Task Basic_json_projection_owned_reference_duplicated2(bool async) -// { -// await base.Basic_json_projection_owned_reference_duplicated2(async); + // public override async Task Basic_json_projection_owned_reference_duplicated2(bool async) + // { + // await base.Basic_json_projection_owned_reference_duplicated2(async); -// AssertSql( -// """ -//SELECT [j].[OwnedReferenceRoot], [j].[Id], JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedReferenceLeaf'), [j].[OwnedReferenceRoot], JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedReferenceLeaf') -//FROM [JsonEntitiesBasic] AS [j] -//ORDER BY [j].[Id] -//"""); -// } + // AssertSql( + // """ + //SELECT [j].[OwnedReferenceRoot], [j].[Id], JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedReferenceLeaf'), [j].[OwnedReferenceRoot], JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedReferenceLeaf') + //FROM [JsonEntitiesBasic] AS [j] + //ORDER BY [j].[Id] + //"""); + // } public override async Task Basic_json_projection_owned_reference_duplicated2_NoTrackingWithIdentityResolution(bool async) { @@ -253,27 +253,27 @@ FROM [JsonEntitiesCustomNaming] AS [j] """); } -// public override async Task Json_projection_with_deduplication(bool async) -// { -// await base.Json_projection_with_deduplication(async); + // public override async Task Json_projection_with_deduplication(bool async) + // { + // await base.Json_projection_with_deduplication(async); -// AssertSql( -// """ -//SELECT [j].[Id], JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch'), JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedReferenceLeaf'), JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedCollectionLeaf'), JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedCollectionBranch'), JSON_VALUE([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedReferenceLeaf.SomethingSomething') -//FROM [JsonEntitiesBasic] AS [j] -//"""); -// } + // AssertSql( + // """ + //SELECT [j].[Id], JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch'), JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedReferenceLeaf'), JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedCollectionLeaf'), JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedCollectionBranch'), JSON_VALUE([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedReferenceLeaf.SomethingSomething') + //FROM [JsonEntitiesBasic] AS [j] + //"""); + // } -// public override async Task Json_projection_with_deduplication_reverse_order(bool async) -// { -// await base.Json_projection_with_deduplication_reverse_order(async); + // public override async Task Json_projection_with_deduplication_reverse_order(bool async) + // { + // await base.Json_projection_with_deduplication_reverse_order(async); -// AssertSql( -// """ -//SELECT JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedReferenceLeaf'), [j].[Id], [j].[OwnedReferenceRoot], [j].[EntityBasicId], [j].[Name], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot] -//FROM [JsonEntitiesBasic] AS [j] -//"""); -// } + // AssertSql( + // """ + //SELECT JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedReferenceLeaf'), [j].[Id], [j].[OwnedReferenceRoot], [j].[EntityBasicId], [j].[Name], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot] + //FROM [JsonEntitiesBasic] AS [j] + //"""); + // } public override async Task Json_property_in_predicate(bool async) { @@ -592,22 +592,22 @@ FROM [JsonEntitiesBasic] AS [j] """); } -// public override async Task Project_json_entity_FirstOrDefault_subquery(bool async) -// { -// await base.Project_json_entity_FirstOrDefault_subquery(async); + // public override async Task Project_json_entity_FirstOrDefault_subquery(bool async) + // { + // await base.Project_json_entity_FirstOrDefault_subquery(async); -// AssertSql( -// """ -//SELECT [j1].[c], [j1].[Id] -//FROM [JsonEntitiesBasic] AS [j] -//OUTER APPLY ( -// SELECT TOP(1) JSON_QUERY([j0].[OwnedReferenceRoot], '$.OwnedReferenceBranch') AS [c], [j0].[Id] -// FROM [JsonEntitiesBasic] AS [j0] -// ORDER BY [j0].[Id] -//) AS [j1] -//ORDER BY [j].[Id] -//"""); -// } + // AssertSql( + // """ + //SELECT [j1].[c], [j1].[Id] + //FROM [JsonEntitiesBasic] AS [j] + //OUTER APPLY ( + // SELECT TOP(1) JSON_QUERY([j0].[OwnedReferenceRoot], '$.OwnedReferenceBranch') AS [c], [j0].[Id] + // FROM [JsonEntitiesBasic] AS [j0] + // ORDER BY [j0].[Id] + //) AS [j1] + //ORDER BY [j].[Id] + //"""); + // } public override async Task Project_json_entity_FirstOrDefault_subquery_with_binding_on_top(bool async) { @@ -632,56 +632,56 @@ public override async Task Project_json_entity_FirstOrDefault_subquery_with_enti @""); } -// public override async Task Project_json_entity_FirstOrDefault_subquery_deduplication(bool async) -// { -// await base.Project_json_entity_FirstOrDefault_subquery_deduplication(async); - -// AssertSql( -// """ -//SELECT [j1].[c], [j1].[Id], [j1].[c0], [j1].[Id0], [j1].[c1], [j1].[c2], [j1].[c3], [j1].[c4] -//FROM [JsonEntitiesBasic] AS [j] -//OUTER APPLY ( -// SELECT TOP(1) JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedCollectionBranch') AS [c], [j].[Id], [j0].[OwnedReferenceRoot] AS [c0], [j0].[Id] AS [Id0], JSON_QUERY([j0].[OwnedReferenceRoot], '$.OwnedReferenceBranch') AS [c1], JSON_VALUE([j0].[OwnedReferenceRoot], '$.Name') AS [c2], CAST(JSON_VALUE([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.Enum') AS int) AS [c3], 1 AS [c4] -// FROM [JsonEntitiesBasic] AS [j0] -// ORDER BY [j0].[Id] -//) AS [j1] -//ORDER BY [j].[Id] -//"""); -// } - -// public override async Task Project_json_entity_FirstOrDefault_subquery_deduplication_and_outer_reference(bool async) -// { -// await base.Project_json_entity_FirstOrDefault_subquery_deduplication_and_outer_reference(async); - -// AssertSql( -// """ -//SELECT [j1].[c], [j1].[Id], [j1].[c0], [j1].[Id0], [j1].[c1], [j1].[c2], [j1].[c3], [j1].[c4] -//FROM [JsonEntitiesBasic] AS [j] -//OUTER APPLY ( -// SELECT TOP(1) JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedCollectionBranch') AS [c], [j].[Id], [j0].[OwnedReferenceRoot] AS [c0], [j0].[Id] AS [Id0], JSON_QUERY([j0].[OwnedReferenceRoot], '$.OwnedReferenceBranch') AS [c1], JSON_VALUE([j0].[OwnedReferenceRoot], '$.Name') AS [c2], CAST(JSON_VALUE([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.Enum') AS int) AS [c3], 1 AS [c4] -// FROM [JsonEntitiesBasic] AS [j0] -// ORDER BY [j0].[Id] -//) AS [j1] -//ORDER BY [j].[Id] -//"""); -// } - -// public override async Task Project_json_entity_FirstOrDefault_subquery_deduplication_outer_reference_and_pruning(bool async) -// { -// await base.Project_json_entity_FirstOrDefault_subquery_deduplication_outer_reference_and_pruning(async); - -// AssertSql( -// """ -//SELECT [j1].[c], [j1].[Id], [j1].[c0] -//FROM [JsonEntitiesBasic] AS [j] -//OUTER APPLY ( -// SELECT TOP(1) JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedCollectionBranch') AS [c], [j].[Id], 1 AS [c0] -// FROM [JsonEntitiesBasic] AS [j0] -// ORDER BY [j0].[Id] -//) AS [j1] -//ORDER BY [j].[Id] -//"""); -// } + // public override async Task Project_json_entity_FirstOrDefault_subquery_deduplication(bool async) + // { + // await base.Project_json_entity_FirstOrDefault_subquery_deduplication(async); + + // AssertSql( + // """ + //SELECT [j1].[c], [j1].[Id], [j1].[c0], [j1].[Id0], [j1].[c1], [j1].[c2], [j1].[c3], [j1].[c4] + //FROM [JsonEntitiesBasic] AS [j] + //OUTER APPLY ( + // SELECT TOP(1) JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedCollectionBranch') AS [c], [j].[Id], [j0].[OwnedReferenceRoot] AS [c0], [j0].[Id] AS [Id0], JSON_QUERY([j0].[OwnedReferenceRoot], '$.OwnedReferenceBranch') AS [c1], JSON_VALUE([j0].[OwnedReferenceRoot], '$.Name') AS [c2], CAST(JSON_VALUE([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.Enum') AS int) AS [c3], 1 AS [c4] + // FROM [JsonEntitiesBasic] AS [j0] + // ORDER BY [j0].[Id] + //) AS [j1] + //ORDER BY [j].[Id] + //"""); + // } + + // public override async Task Project_json_entity_FirstOrDefault_subquery_deduplication_and_outer_reference(bool async) + // { + // await base.Project_json_entity_FirstOrDefault_subquery_deduplication_and_outer_reference(async); + + // AssertSql( + // """ + //SELECT [j1].[c], [j1].[Id], [j1].[c0], [j1].[Id0], [j1].[c1], [j1].[c2], [j1].[c3], [j1].[c4] + //FROM [JsonEntitiesBasic] AS [j] + //OUTER APPLY ( + // SELECT TOP(1) JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedCollectionBranch') AS [c], [j].[Id], [j0].[OwnedReferenceRoot] AS [c0], [j0].[Id] AS [Id0], JSON_QUERY([j0].[OwnedReferenceRoot], '$.OwnedReferenceBranch') AS [c1], JSON_VALUE([j0].[OwnedReferenceRoot], '$.Name') AS [c2], CAST(JSON_VALUE([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.Enum') AS int) AS [c3], 1 AS [c4] + // FROM [JsonEntitiesBasic] AS [j0] + // ORDER BY [j0].[Id] + //) AS [j1] + //ORDER BY [j].[Id] + //"""); + // } + + // public override async Task Project_json_entity_FirstOrDefault_subquery_deduplication_outer_reference_and_pruning(bool async) + // { + // await base.Project_json_entity_FirstOrDefault_subquery_deduplication_outer_reference_and_pruning(async); + + // AssertSql( + // """ + //SELECT [j1].[c], [j1].[Id], [j1].[c0] + //FROM [JsonEntitiesBasic] AS [j] + //OUTER APPLY ( + // SELECT TOP(1) JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedCollectionBranch') AS [c], [j].[Id], 1 AS [c0] + // FROM [JsonEntitiesBasic] AS [j0] + // ORDER BY [j0].[Id] + //) AS [j1] + //ORDER BY [j].[Id] + //"""); + // } public override async Task Json_entity_with_inheritance_basic_projection(bool async) { @@ -1151,7 +1151,9 @@ public override async Task Json_collection_Distinct_Count_with_predicate(bool as { // TODO:SQLJSON Json type is not comparable Assert.Equal( - "The json data type cannot be selected as DISTINCT because it is not comparable.\nThe json data type cannot be selected as DISTINCT because it is not comparable.", + "The json data type cannot be selected as DISTINCT because it is not comparable." + + Environment.NewLine + + "The json data type cannot be selected as DISTINCT because it is not comparable.", (await Assert.ThrowsAsync(() => base.Json_collection_Distinct_Count_with_predicate(async))).Message); AssertSql( @@ -1369,7 +1371,9 @@ public override async Task Json_collection_distinct_in_projection(bool async) { // TODO:SQLJSON Json type is not comparable Assert.Equal( - "The json data type cannot be selected as DISTINCT because it is not comparable.\nThe json data type cannot be selected as DISTINCT because it is not comparable.", + "The json data type cannot be selected as DISTINCT because it is not comparable." + + Environment.NewLine + + "The json data type cannot be selected as DISTINCT because it is not comparable.", (await Assert.ThrowsAsync(() => base.Json_collection_distinct_in_projection(async))).Message); AssertSql( @@ -1420,7 +1424,9 @@ public override async Task Json_multiple_collection_projections(bool async) { // TODO:SQLJSON Json type is not comparable Assert.Equal( - "The json data type cannot be selected as DISTINCT because it is not comparable.\nThe json data type cannot be selected as DISTINCT because it is not comparable.", + "The json data type cannot be selected as DISTINCT because it is not comparable." + + Environment.NewLine + + "The json data type cannot be selected as DISTINCT because it is not comparable.", (await Assert.ThrowsAsync(() => base.Json_multiple_collection_projections(async))).Message); AssertSql( @@ -1462,7 +1468,9 @@ public override async Task Json_branch_collection_distinct_and_other_collection( { // TODO:SQLJSON Json type is not comparable Assert.Equal( - "The json data type cannot be selected as DISTINCT because it is not comparable.\nThe json data type cannot be selected as DISTINCT because it is not comparable.", + "The json data type cannot be selected as DISTINCT because it is not comparable." + + Environment.NewLine + + "The json data type cannot be selected as DISTINCT because it is not comparable.", (await Assert.ThrowsAsync(() => base.Json_branch_collection_distinct_and_other_collection(async))).Message); AssertSql( @@ -1505,45 +1513,45 @@ FROM OPENJSON([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedCollectionL """); } -// public override async Task Json_collection_SelectMany(bool async) -// { -// await base.Json_collection_SelectMany(async); - -// AssertSql( -// """ -//SELECT [j].[Id], [o].[Name], [o].[Names], [o].[Number], [o].[Numbers], [o].[OwnedCollectionBranch], [o].[OwnedReferenceBranch] -//FROM [JsonEntitiesBasic] AS [j] -//CROSS APPLY OPENJSON(CAST([j].[OwnedCollectionRoot] AS nvarchar(max)), '$') WITH ( -// [Name] nvarchar(max) '$.Name', -// [Names] nvarchar(max) '$.Names' AS JSON, -// [Number] int '$.Number', -// [Numbers] nvarchar(max) '$.Numbers' AS JSON, -// [OwnedCollectionBranch] nvarchar(max) '$.OwnedCollectionBranch' AS JSON, -// [OwnedReferenceBranch] nvarchar(max) '$.OwnedReferenceBranch' AS JSON -//) AS [o] -//"""); -// } - -// public override async Task Json_nested_collection_SelectMany(bool async) -// { -// await base.Json_nested_collection_SelectMany(async); - -// AssertSql( -// """ -//SELECT [j].[Id], [o].[Date], [o].[Enum], [o].[Enums], [o].[Fraction], [o].[NullableEnum], [o].[NullableEnums], [o].[OwnedCollectionLeaf], [o].[OwnedReferenceLeaf] -//FROM [JsonEntitiesBasic] AS [j] -//CROSS APPLY OPENJSON(CAST([j].[OwnedReferenceRoot] AS nvarchar(max)), '$.OwnedCollectionBranch') WITH ( -// [Date] datetime2 '$.Date', -// [Enum] int '$.Enum', -// [Enums] nvarchar(max) '$.Enums' AS JSON, -// [Fraction] decimal(18,2) '$.Fraction', -// [NullableEnum] int '$.NullableEnum', -// [NullableEnums] nvarchar(max) '$.NullableEnums' AS JSON, -// [OwnedCollectionLeaf] nvarchar(max) '$.OwnedCollectionLeaf' AS JSON, -// [OwnedReferenceLeaf] nvarchar(max) '$.OwnedReferenceLeaf' AS JSON -//) AS [o] -//"""); -// } + // public override async Task Json_collection_SelectMany(bool async) + // { + // await base.Json_collection_SelectMany(async); + + // AssertSql( + // """ + //SELECT [j].[Id], [o].[Name], [o].[Names], [o].[Number], [o].[Numbers], [o].[OwnedCollectionBranch], [o].[OwnedReferenceBranch] + //FROM [JsonEntitiesBasic] AS [j] + //CROSS APPLY OPENJSON(CAST([j].[OwnedCollectionRoot] AS nvarchar(max)), '$') WITH ( + // [Name] nvarchar(max) '$.Name', + // [Names] nvarchar(max) '$.Names' AS JSON, + // [Number] int '$.Number', + // [Numbers] nvarchar(max) '$.Numbers' AS JSON, + // [OwnedCollectionBranch] nvarchar(max) '$.OwnedCollectionBranch' AS JSON, + // [OwnedReferenceBranch] nvarchar(max) '$.OwnedReferenceBranch' AS JSON + //) AS [o] + //"""); + // } + + // public override async Task Json_nested_collection_SelectMany(bool async) + // { + // await base.Json_nested_collection_SelectMany(async); + + // AssertSql( + // """ + //SELECT [j].[Id], [o].[Date], [o].[Enum], [o].[Enums], [o].[Fraction], [o].[NullableEnum], [o].[NullableEnums], [o].[OwnedCollectionLeaf], [o].[OwnedReferenceLeaf] + //FROM [JsonEntitiesBasic] AS [j] + //CROSS APPLY OPENJSON(CAST([j].[OwnedReferenceRoot] AS nvarchar(max)), '$.OwnedCollectionBranch') WITH ( + // [Date] datetime2 '$.Date', + // [Enum] int '$.Enum', + // [Enums] nvarchar(max) '$.Enums' AS JSON, + // [Fraction] decimal(18,2) '$.Fraction', + // [NullableEnum] int '$.NullableEnum', + // [NullableEnums] nvarchar(max) '$.NullableEnums' AS JSON, + // [OwnedCollectionLeaf] nvarchar(max) '$.OwnedCollectionLeaf' AS JSON, + // [OwnedReferenceLeaf] nvarchar(max) '$.OwnedReferenceLeaf' AS JSON + //) AS [o] + //"""); + // } public override async Task Json_collection_of_primitives_SelectMany(bool async) { @@ -2240,14 +2248,14 @@ FROM [JsonEntitiesBasic] AS [j] ORDER BY [j].[Id], [j0].[Id] """); -// AssertSql( -//""" -//SELECT JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedCollectionLeaf'), [j].[Id], [j0].[Id], [j0].[Name], [j0].[ParentId], JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedReferenceLeaf'), [j1].[Id], [j1].[Name], [j1].[ParentId], JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedCollectionBranch'), [j].[OwnedCollectionRoot] -//FROM [JsonEntitiesBasic] AS [j] -//LEFT JOIN [JsonEntitiesBasicForReference] AS [j0] ON [j].[Id] = [j0].[ParentId] -//LEFT JOIN [JsonEntitiesBasicForCollection] AS [j1] ON [j].[Id] = [j1].[ParentId] -//ORDER BY [j].[Id], [j0].[Id] -//"""); + // AssertSql( + //""" + //SELECT JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedCollectionLeaf'), [j].[Id], [j0].[Id], [j0].[Name], [j0].[ParentId], JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedReferenceBranch.OwnedReferenceLeaf'), [j1].[Id], [j1].[Name], [j1].[ParentId], JSON_QUERY([j].[OwnedReferenceRoot], '$.OwnedCollectionBranch'), [j].[OwnedCollectionRoot] + //FROM [JsonEntitiesBasic] AS [j] + //LEFT JOIN [JsonEntitiesBasicForReference] AS [j0] ON [j].[Id] = [j0].[ParentId] + //LEFT JOIN [JsonEntitiesBasicForCollection] AS [j1] ON [j].[Id] = [j1].[ParentId] + //ORDER BY [j].[Id], [j0].[Id] + //"""); } public override async Task Json_all_types_entity_projection(bool async)