Repository: dotnet/efcore
File: test/EFCore.SqlServer.FunctionalTests/Migrations/SqlServerMigrationsSqlGeneratorTest.cs (C#)

Code before:
""");
    }

    [ConditionalFact]
    public void Invalid_column_type_throws_meaningful_exception()
    {
        var ex = Assert.Throws<InvalidOperationException>(() =>
            Generate(
                new CreateTableOperation
                {
                    Name = "People",
                    Columns =
                    {
                        new AddColumnOperation
                        {
                            Name = "FirstName",
                            Table = "People",
                            ClrType = typeof(string),
                            ColumnType = "decimal(18,2)", // Invalid store type for string
                            IsNullable = false
                        }
                    }
                }));

        Assert.Contains("People.FirstName", ex.Message);
        Assert.Contains("String", ex.Message);
    }

    [ConditionalFact]
    public void Invalid_column_type_for_unmappable_clr_type_throws_meaningful_exception()
    {
        var ex = Assert.Throws<InvalidOperationException>(() =>
            Generate(
                new AddColumnOperation
                {
                    Name = "TestColumn",
                    Table = "TestTable",
                    ClrType = typeof(System.IO.FileStream), // Unmappable CLR type
                    ColumnType = null,
                    IsNullable = false
                }));

        Assert.Contains("TestTable.TestColumn", ex.Message);
        Assert.Contains("FileStream", ex.Message);
    }

    [ConditionalFact]
    public void Column_type_found_from_default_value_when_clr_type_unmappable()
    {
        Generate(
            new AddColumnOperation

Review comment (suggestion):
Verify that the exception message is equal to `RelationalStrings.UnsupportedTypeForColumn` in both of these tests

Code after:
ALTER TABLE [Person] ADD DEFAULT N'' FOR [Name];
""");
    }



    [ConditionalFact]
    public void Invalid_column_type_for_unmappable_clr_type_throws_meaningful_exception()
    {
        var ex = Assert.Throws<InvalidOperationException>(() =>
            Generate(
                new AddColumnOperation
                {
                    Name = "TestColumn",
                    Table = "TestTable",
                    ClrType = typeof(System.IO.FileStream), // Unmappable CLR type
                    ColumnType = null,
                    IsNullable = false
                }));

        Assert.Equal(RelationalStrings.UnsupportedTypeForColumn("TestTable", "TestColumn", "FileStream"), ex.Message);
    }

    private static void CreateGotModel(ModelBuilder b)
        => b.HasDefaultSchema("dbo").Entity(
            "Person", pb =>
            {
                pb.ToTable("People");
                pb.Property<string>("FirstName").HasColumnName("First Name");
                pb.Property<string>("LastName").HasColumnName("Last Name");
                pb.Property<string>("Birthplace").HasColumnName("Birthplace");
                pb.Property<string>("Allegiance").HasColumnName("House Allegiance");
                pb.Property<string>("Culture").HasColumnName("Culture");
                pb.HasKey("FirstName", "LastName");
            });
}