Skip to content

Commit fd22d64

Browse files
committed
moving tests for #32972 to relational so we also test SqLite
1 parent 4a1e206 commit fd22d64

File tree

3 files changed

+371
-249
lines changed

3 files changed

+371
-249
lines changed

test/EFCore.Relational.Specification.Tests/Migrations/MigrationsTestBase.cs

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,6 +2858,265 @@ public class MyNestedComplex
28582858
public DateTime Bar { get; set; }
28592859
}
28602860

2861+
[ConditionalFact]
2862+
public virtual Task Add_required_primitve_collection_to_existing_table()
2863+
=> Test(
2864+
builder => builder.Entity(
2865+
"Customer", e =>
2866+
{
2867+
e.Property<int>("Id").ValueGeneratedOnAdd();
2868+
e.HasKey("Id");
2869+
e.Property<string>("Name");
2870+
e.ToTable("Customers");
2871+
}),
2872+
builder => builder.Entity(
2873+
"Customer", e =>
2874+
{
2875+
e.Property<int>("Id").ValueGeneratedOnAdd();
2876+
e.HasKey("Id");
2877+
e.Property<string>("Name");
2878+
e.Property<List<int>>("Numbers").IsRequired();
2879+
e.ToTable("Customers");
2880+
}),
2881+
model =>
2882+
{
2883+
var customersTable = Assert.Single(model.Tables.Where(t => t.Name == "Customers"));
2884+
Assert.Collection(
2885+
customersTable.Columns,
2886+
c => Assert.Equal("Id", c.Name),
2887+
c => Assert.Equal("Name", c.Name),
2888+
c => Assert.Equal("Numbers", c.Name));
2889+
Assert.Same(
2890+
customersTable.Columns.Single(c => c.Name == "Id"),
2891+
Assert.Single(customersTable.PrimaryKey!.Columns));
2892+
});
2893+
2894+
[ConditionalFact]
2895+
public virtual Task Add_required_primitve_collection_with_custom_default_value_to_existing_table()
2896+
=> Test(
2897+
builder => builder.Entity(
2898+
"Customer", e =>
2899+
{
2900+
e.Property<int>("Id").ValueGeneratedOnAdd();
2901+
e.HasKey("Id");
2902+
e.Property<string>("Name");
2903+
e.ToTable("Customers");
2904+
}),
2905+
builder => builder.Entity(
2906+
"Customer", e =>
2907+
{
2908+
e.Property<int>("Id").ValueGeneratedOnAdd();
2909+
e.HasKey("Id");
2910+
e.Property<string>("Name");
2911+
e.Property<List<int>>("Numbers").IsRequired().HasDefaultValue(new List<int> { 1, 2, 3 });
2912+
e.ToTable("Customers");
2913+
}),
2914+
model =>
2915+
{
2916+
var customersTable = Assert.Single(model.Tables.Where(t => t.Name == "Customers"));
2917+
Assert.Collection(
2918+
customersTable.Columns,
2919+
c => Assert.Equal("Id", c.Name),
2920+
c => Assert.Equal("Name", c.Name),
2921+
c => Assert.Equal("Numbers", c.Name));
2922+
Assert.Same(
2923+
customersTable.Columns.Single(c => c.Name == "Id"),
2924+
Assert.Single(customersTable.PrimaryKey!.Columns));
2925+
});
2926+
2927+
[ConditionalFact]
2928+
public abstract Task Add_required_primitve_collection_with_custom_default_value_sql_to_existing_table();
2929+
2930+
protected virtual Task Add_required_primitve_collection_with_custom_default_value_sql_to_existing_table_core(string defaultValueSql)
2931+
=> Test(
2932+
builder => builder.Entity(
2933+
"Customer", e =>
2934+
{
2935+
e.Property<int>("Id").ValueGeneratedOnAdd();
2936+
e.HasKey("Id");
2937+
e.Property<string>("Name");
2938+
e.ToTable("Customers");
2939+
}),
2940+
builder => builder.Entity(
2941+
"Customer", e =>
2942+
{
2943+
e.Property<int>("Id").ValueGeneratedOnAdd();
2944+
e.HasKey("Id");
2945+
e.Property<string>("Name");
2946+
e.Property<List<int>>("Numbers").IsRequired().HasDefaultValueSql(defaultValueSql);
2947+
e.ToTable("Customers");
2948+
}),
2949+
model =>
2950+
{
2951+
var customersTable = Assert.Single(model.Tables.Where(t => t.Name == "Customers"));
2952+
Assert.Collection(
2953+
customersTable.Columns,
2954+
c => Assert.Equal("Id", c.Name),
2955+
c => Assert.Equal("Name", c.Name),
2956+
c => Assert.Equal("Numbers", c.Name));
2957+
Assert.Same(
2958+
customersTable.Columns.Single(c => c.Name == "Id"),
2959+
Assert.Single(customersTable.PrimaryKey!.Columns));
2960+
});
2961+
2962+
[ConditionalFact(Skip = "issue #33038")]
2963+
public virtual Task Add_required_primitve_collection_with_custom_converter_to_existing_table()
2964+
=> Test(
2965+
builder => builder.Entity(
2966+
"Customer", e =>
2967+
{
2968+
e.Property<int>("Id").ValueGeneratedOnAdd();
2969+
e.HasKey("Id");
2970+
e.Property<string>("Name");
2971+
e.ToTable("Customers");
2972+
}),
2973+
builder => builder.Entity(
2974+
"Customer", e =>
2975+
{
2976+
e.Property<int>("Id").ValueGeneratedOnAdd();
2977+
e.HasKey("Id");
2978+
e.Property<string>("Name");
2979+
e.Property<List<int>>("Numbers").HasConversion(new ValueConverter<List<int>, string>(
2980+
convertToProviderExpression: x => x != null && x.Count > 0 ? "some numbers" : "nothing",
2981+
convertFromProviderExpression: x => x == "nothing" ? new List<int> { } : new List<int> { 7, 8, 9 }))
2982+
.IsRequired();
2983+
e.ToTable("Customers");
2984+
}),
2985+
model =>
2986+
{
2987+
var customersTable = Assert.Single(model.Tables.Where(t => t.Name == "Customers"));
2988+
Assert.Collection(
2989+
customersTable.Columns,
2990+
c => Assert.Equal("Id", c.Name),
2991+
c => Assert.Equal("Name", c.Name),
2992+
c => Assert.Equal("Numbers", c.Name));
2993+
Assert.Same(
2994+
customersTable.Columns.Single(c => c.Name == "Id"),
2995+
Assert.Single(customersTable.PrimaryKey!.Columns));
2996+
});
2997+
2998+
[ConditionalFact]
2999+
public virtual Task Add_required_primitve_collection_with_custom_converter_and_custom_default_value_to_existing_table()
3000+
=> Test(
3001+
builder => builder.Entity(
3002+
"Customer", e =>
3003+
{
3004+
e.Property<int>("Id").ValueGeneratedOnAdd();
3005+
e.HasKey("Id");
3006+
e.Property<string>("Name");
3007+
e.ToTable("Customers");
3008+
}),
3009+
builder => builder.Entity(
3010+
"Customer", e =>
3011+
{
3012+
e.Property<int>("Id").ValueGeneratedOnAdd();
3013+
e.HasKey("Id");
3014+
e.Property<string>("Name");
3015+
e.Property<List<int>>("Numbers").HasConversion(new ValueConverter<List<int>, string>(
3016+
convertToProviderExpression: x => x != null && x.Count > 0 ? "some numbers" : "nothing",
3017+
convertFromProviderExpression: x => x == "nothing" ? new List<int> { } : new List<int> { 7, 8, 9 }))
3018+
.HasDefaultValue(new List<int> { 42 })
3019+
.IsRequired();
3020+
e.ToTable("Customers");
3021+
}),
3022+
model =>
3023+
{
3024+
var customersTable = Assert.Single(model.Tables.Where(t => t.Name == "Customers"));
3025+
Assert.Collection(
3026+
customersTable.Columns,
3027+
c => Assert.Equal("Id", c.Name),
3028+
c => Assert.Equal("Name", c.Name),
3029+
c => Assert.Equal("Numbers", c.Name));
3030+
Assert.Same(
3031+
customersTable.Columns.Single(c => c.Name == "Id"),
3032+
Assert.Single(customersTable.PrimaryKey!.Columns));
3033+
});
3034+
3035+
[ConditionalFact]
3036+
public virtual Task Add_optional_primitive_collection_to_existing_table()
3037+
=> Test(
3038+
builder => builder.Entity(
3039+
"Customer", e =>
3040+
{
3041+
e.Property<int>("Id").ValueGeneratedOnAdd();
3042+
e.HasKey("Id");
3043+
e.Property<string>("Name");
3044+
e.ToTable("Customers");
3045+
}),
3046+
builder => builder.Entity(
3047+
"Customer", e =>
3048+
{
3049+
e.Property<int>("Id").ValueGeneratedOnAdd();
3050+
e.HasKey("Id");
3051+
e.Property<string>("Name");
3052+
e.Property<List<int>>("Numbers");
3053+
e.ToTable("Customers");
3054+
}),
3055+
model =>
3056+
{
3057+
var customersTable = Assert.Single(model.Tables.Where(t => t.Name == "Customers"));
3058+
Assert.Collection(
3059+
customersTable.Columns,
3060+
c => Assert.Equal("Id", c.Name),
3061+
c => Assert.Equal("Name", c.Name),
3062+
c => Assert.Equal("Numbers", c.Name));
3063+
Assert.Same(
3064+
customersTable.Columns.Single(c => c.Name == "Id"),
3065+
Assert.Single(customersTable.PrimaryKey!.Columns));
3066+
});
3067+
3068+
[ConditionalFact]
3069+
public virtual Task Create_table_with_required_primitive_collection()
3070+
=> Test(
3071+
builder => { },
3072+
builder => builder.Entity(
3073+
"Customer", e =>
3074+
{
3075+
e.Property<int>("Id").ValueGeneratedOnAdd();
3076+
e.HasKey("Id");
3077+
e.Property<string>("Name");
3078+
e.Property<List<int>>("Numbers").IsRequired();
3079+
e.ToTable("Customers");
3080+
}),
3081+
model =>
3082+
{
3083+
var customersTable = Assert.Single(model.Tables.Where(t => t.Name == "Customers"));
3084+
Assert.Collection(
3085+
customersTable.Columns,
3086+
c => Assert.Equal("Id", c.Name),
3087+
c => Assert.Equal("Name", c.Name),
3088+
c => Assert.Equal("Numbers", c.Name));
3089+
Assert.Same(
3090+
customersTable.Columns.Single(c => c.Name == "Id"),
3091+
Assert.Single(customersTable.PrimaryKey!.Columns));
3092+
});
3093+
3094+
[ConditionalFact]
3095+
public virtual Task Create_table_with_optional_primitive_collection()
3096+
=> Test(
3097+
builder => { },
3098+
builder => builder.Entity(
3099+
"Customer", e =>
3100+
{
3101+
e.Property<int>("Id").ValueGeneratedOnAdd();
3102+
e.HasKey("Id");
3103+
e.Property<string>("Name");
3104+
e.Property<List<int>>("Numbers");
3105+
e.ToTable("Customers");
3106+
}),
3107+
model =>
3108+
{
3109+
var customersTable = Assert.Single(model.Tables.Where(t => t.Name == "Customers"));
3110+
Assert.Collection(
3111+
customersTable.Columns,
3112+
c => Assert.Equal("Id", c.Name),
3113+
c => Assert.Equal("Name", c.Name),
3114+
c => Assert.Equal("Numbers", c.Name));
3115+
Assert.Same(
3116+
customersTable.Columns.Single(c => c.Name == "Id"),
3117+
Assert.Single(customersTable.PrimaryKey!.Columns));
3118+
});
3119+
28613120
protected class Person
28623121
{
28633122
public int Id { get; set; }

0 commit comments

Comments
 (0)