Repository: dotnet/efcore
File: test/EFCore.SqlServer.Tests/Storage/SqlServerTypeMappingSourceTest.cs (C#)

Code before:

        exception = Assert.Throws<InvalidOperationException>(() => GetTypeMapping(typeof(SqlVector<float>), maxLength: -1));
        Assert.Equal(SqlServerStrings.VectorDimensionsInvalid, exception.Message);

        // We do allow constructing a vector type mapping with no dimensions, since the scaffolder requires it
        // (see comment in SqlServerVectorTypeMapping)
        var typeMapping = GetTypeMapping(typeof(SqlVector<float>));
        Assert.Null(typeMapping.Size);
    }

    #endregion Vector

    [ConditionalFact]
    public void Plugins_can_override_builtin_mappings()
    {
        var typeMappingSource = new SqlServerTypeMappingSource(
            TestServiceFactory.Instance.Create<TypeMappingSourceDependencies>(),
            TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>() with
            {
                Plugins = [new FakeTypeMappingSourcePlugin()]
            });

        Assert.Equal("String", typeMappingSource.GetMapping("datetime2").ClrType.Name);
    }

    private class FakeTypeMappingSourcePlugin : IRelationalTypeMappingSourcePlugin
    {
        public RelationalTypeMapping FindMapping(in RelationalTypeMappingInfo mappingInfo)
            => new StringTypeMapping("datetime2", null);
    }

    protected override IRelationalTypeMappingSource CreateRelationalTypeMappingSource(IModel model)
    {
        var typeMappingSource = new SqlServerTypeMappingSource(
            TestServiceFactory.Instance.Create<TypeMappingSourceDependencies>(),
            TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>());

        model.ModelDependencies = new RuntimeModelDependencies(typeMappingSource, null!, null!);

        return typeMappingSource;
    }

    private enum LongEnum : long;

    private enum IntEnum;

    private enum ShortEnum : short;

    private enum ByteEnum : byte;

    protected override ModelBuilder CreateModelBuilder(Action<ModelConfigurationBuilder> configureConventions = null)

Review comment (suggestion):
```suggestion
    public void Json_is_mapped_to_json_type_with_UseSqlServer_with_compatibility_level_170()
```

Code after:
        Assert.Equal(SqlServerStrings.VectorDimensionsInvalid, exception.Message);

        exception = Assert.Throws<InvalidOperationException>(() => GetTypeMapping(typeof(SqlVector<float>), maxLength: -1));
        Assert.Equal(SqlServerStrings.VectorDimensionsInvalid, exception.Message);

        // We do allow constructing a vector type mapping with no dimensions, since the scaffolder requires it
        // (see comment in SqlServerVectorTypeMapping)
        var typeMapping = GetTypeMapping(typeof(SqlVector<float>));
        Assert.Null(typeMapping.Size);
    }

    #endregion Vector

    #region Json

    [ConditionalFact]
    public void Json_is_mapped_to_nvarchar_with_UseSqlServer_by_default()
    {
        var typeMappingSource = CreateTypeMappingSource(o => o.UseSqlServer(null));

        Assert.Equal("nvarchar(max)", typeMappingSource.GetMapping(typeof(JsonTypePlaceholder)).StoreType);
        Assert.Equal("nvarchar(max)", typeMappingSource.GetMapping(typeof(int[])).StoreType);
    }

    [ConditionalFact]
    public void Json_is_mapped_to_nvarchar_with_UseSqlServer_with_compatibility_level_170()
    {
        var typeMappingSource = CreateTypeMappingSource(o =>
            o.UseSqlServer((string)null, o => o.UseCompatibilityLevel(170)));

        Assert.Equal("json", typeMappingSource.GetMapping(typeof(JsonTypePlaceholder)).StoreType);
        Assert.Equal("json", typeMappingSource.GetMapping(typeof(int[])).StoreType);
    }

    [ConditionalFact]
    public void Json_is_mapped_to_json_type_with_UseAzureSql_by_default()
    {
        var typeMappingSource = CreateTypeMappingSource(o => o.UseAzureSql(null));

        Assert.Equal("json", typeMappingSource.GetMapping(typeof(JsonTypePlaceholder)).StoreType);
        Assert.Equal("json", typeMappingSource.GetMapping(typeof(int[])).StoreType);
    }

    [ConditionalFact]
    public void Json_is_mapped_to_nvarchar_with_compatibility_level_170_when_explicitly_specified()
    {
        var typeMappingSource = CreateTypeMappingSource(o =>
            o.UseSqlServer((string)null, o => o.UseCompatibilityLevel(170)));

        Assert.Equal("nvarchar(max)", typeMappingSource.FindMapping(typeof(JsonTypePlaceholder), "nvarchar(max)").StoreType);
        Assert.Equal("nvarchar(max)", typeMappingSource.FindMapping(typeof(int[]), "nvarchar(max)").StoreType);