Repository: dotnet/efcore
File: test/EFCore.SqlServer.FunctionalTests/Query/Translations/JsonTranslationsSqlServerTest.cs (C#)

Code before:
    {
        protected override ITestStoreFactory TestStoreFactory
            => SqlServerTestStoreFactory.Instance;

        public virtual bool UsingJsonType
            => TestEnvironment.SqlServerMajorVersion >= 17;

        // When testing against SQL Server 2025 or later, set the compatibility level to 170 to use the json type instead of nvarchar(max).
        public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
        {
            var options = base.AddOptions(builder);

            return TestEnvironment.SqlServerMajorVersion < 17
                ? options
                : options.UseSqlServerCompatibilityLevel(170);
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
        {
            base.OnModelCreating(modelBuilder, context);

            if (UsingJsonType)
            {
                modelBuilder.Entity<JsonTranslationsEntity>().Property(e => e.JsonString).HasColumnType("json");
            }
        }

        protected override string RemoveJsonProperty(string column, string jsonPath)
            => $"JSON_MODIFY({column}, '{jsonPath}', NULL)";
    }

    [ConditionalFact]
    public virtual void Check_all_tests_overridden()
        => TestHelpers.AssertAllMethodsOverridden(GetType());

    private void AssertSql(params string[] expected)
        => Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
}


Review comment (suggestion):
`UsingJsonType` is based on `SqlServerMajorVersion >= 17`, but the test condition is `SqlServerCondition.SupportsJsonType` (which uses `TestEnvironment.IsJsonTypeSupported` and can also be true on Azure SQL when compatibility level is 170+). If Azure SQL reports a product major version < 17 but still satisfies SupportsJsonType, JsonString won’t be mapped to `json` and the JsonContains tests may end up running against nvarchar. Consider basing `UsingJsonType` (and the conditional `HasColumnType("json")` mapping) on `TestEnvironment.IsJsonTypeSupported` to match the condition used to enable these tests.

Code after:
        // When testing against SQL Server 2025 or later, set the compatibility level to 170 to use the json type instead of nvarchar(max).
        public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
        {
            var options = base.AddOptions(builder);

            return TestEnvironment.SqlServerMajorVersion < 17
                ? options
                : options.UseSqlServerCompatibilityLevel(170);
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
        {
            base.OnModelCreating(modelBuilder, context);

            if (TestEnvironment.IsJsonTypeSupported)
            {
                modelBuilder.Entity<JsonTranslationsEntity>().Property(e => e.JsonString).HasColumnType("json");
            }
        }

        protected override string RemoveJsonProperty(string column, string jsonPath)
            => $"JSON_MODIFY({column}, '{jsonPath}', NULL)";
    }

    [ConditionalFact]
    public virtual void Check_all_tests_overridden()
        => TestHelpers.AssertAllMethodsOverridden(GetType());

    private void AssertSql(params string[] expected)
        => Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
}