Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes to migration tests #19699

Merged
merged 1 commit into from
Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions test/EFCore.Relational.Specification.Tests/MigrationsTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ await Test(

e.HasKey("CustomId");
e.HasAlternateKey("SSN");
e.HasCheckConstraint("CK_SSN", $"{DelimitIdentifier("SSN")} > 0");
e.HasCheckConstraint("CK_EmployerId", $"{DelimitIdentifier("EmployerId")} > 0");
e.HasOne("Employers").WithMany("People").HasForeignKey("EmployerId");

e.HasComment("Table comment");
Expand Down Expand Up @@ -338,17 +338,16 @@ public virtual Task Add_column_with_defaultValueSql()
=> Test(
builder => builder.Entity("People").Property<int>("Id"),
builder => { },
builder => builder.Entity("People").Property<DateTime?>("Birthday")
.HasColumnType("date")
.HasDefaultValueSql("CURRENT_TIMESTAMP"),
builder => builder.Entity("People").Property<int>("Sum")
.HasDefaultValueSql("1 + 2"),
model =>
{
var table = Assert.Single(model.Tables);
Assert.Equal(2, table.Columns.Count);
var nameColumn = Assert.Single(table.Columns, c => c.Name == "Birthday");
Assert.Equal("date", nameColumn.StoreType);
Assert.True(nameColumn.IsNullable);
Assert.Equal("(getdate())", nameColumn.DefaultValueSql);
var sumColumn = Assert.Single(table.Columns, c => c.Name == "Sum");
Assert.Contains("1", sumColumn.DefaultValueSql);
Assert.Contains("+", sumColumn.DefaultValueSql);
Assert.Contains("2", sumColumn.DefaultValueSql);
});

[ConditionalFact]
Expand All @@ -358,17 +357,17 @@ public virtual Task Add_column_with_computedSql()
"People", e =>
{
e.Property<int>("Id");
e.Property<string>("FirstName");
e.Property<string>("LastName");
e.Property<int>("X");
e.Property<int>("Y");
}),
builder => { },
builder => builder.Entity("People").Property<string>("FullName").HasComputedColumnSql("FirstName + ' ' + LastName"),
builder => builder.Entity("People").Property<string>("Sum").HasComputedColumnSql($"{DelimitIdentifier("X")} + {DelimitIdentifier("Y")}"),
model =>
{
var table = Assert.Single(model.Tables);
var column = Assert.Single(table.Columns, c => c.Name == "FullName");
Assert.Contains("FirstName", column.ComputedColumnSql);
Assert.Contains("LastName", column.ComputedColumnSql);
var sumColumn = Assert.Single(table.Columns, c => c.Name == "Sum");
Assert.Contains("X", sumColumn.ComputedColumnSql);
Assert.Contains("Y", sumColumn.ComputedColumnSql);
});

// TODO: Check this out
Expand Down Expand Up @@ -581,17 +580,18 @@ public virtual Task Alter_column_make_computed()
"People", e =>
{
e.Property<int>("Id");
e.Property<string>("FirstName");
e.Property<string>("LastName");
e.Property<int>("X");
e.Property<int>("Y");
}),
builder => builder.Entity("People").Property<string>("FullName"),
builder => builder.Entity("People").Property<string>("FullName").HasComputedColumnSql("FirstName + ' ' + LastName"),
builder => builder.Entity("People").Property<int>("Sum"),
builder => builder.Entity("People").Property<int>("Sum").HasComputedColumnSql($"{DelimitIdentifier("X")} + {DelimitIdentifier("Y")}"),
model =>
{
var table = Assert.Single(model.Tables);
var column = Assert.Single(table.Columns, c => c.Name == "FullName");
Assert.Contains("FirstName", column.ComputedColumnSql);
Assert.Contains("LastName", column.ComputedColumnSql);
var sumColumn = Assert.Single(table.Columns, c => c.Name == "Sum");
Assert.Contains("X", sumColumn.ComputedColumnSql);
Assert.Contains("Y", sumColumn.ComputedColumnSql);
Assert.Contains("+", sumColumn.ComputedColumnSql);
});

[ConditionalFact]
Expand All @@ -601,18 +601,19 @@ public virtual Task Alter_column_change_computed()
"People", e =>
{
e.Property<int>("Id");
e.Property<string>("FirstName");
e.Property<string>("LastName");
e.Property<string>("FullName");
e.Property<int>("X");
e.Property<int>("Y");
e.Property<int>("Sum");
}),
builder => builder.Entity("People").Property<string>("FullName").HasComputedColumnSql("FirstName + ' ' + LastName"),
builder => builder.Entity("People").Property<string>("FullName").HasComputedColumnSql("FirstName + ', ' + LastName"),
builder => builder.Entity("People").Property<int>("Sum").HasComputedColumnSql($"{DelimitIdentifier("X")} + {DelimitIdentifier("Y")}"),
builder => builder.Entity("People").Property<int>("Sum").HasComputedColumnSql($"{DelimitIdentifier("X")} - {DelimitIdentifier("Y")}"),
model =>
{
var table = Assert.Single(model.Tables);
var column = Assert.Single(table.Columns, c => c.Name == "FullName");
Assert.Contains("FirstName", column.ComputedColumnSql);
Assert.Contains("LastName", column.ComputedColumnSql);
var sumColumn = Assert.Single(table.Columns, c => c.Name == "Sum");
Assert.Contains("X", sumColumn.ComputedColumnSql);
Assert.Contains("Y", sumColumn.ComputedColumnSql);
Assert.Contains("-", sumColumn.ComputedColumnSql);
});

[ConditionalFact]
Expand Down
20 changes: 10 additions & 10 deletions test/EFCore.SqlServer.FunctionalTests/MigrationsSqlServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public MigrationsSqlServerTest(MigrationsSqlServerFixture fixture, ITestOutputHe
: base(fixture)
{
Fixture.TestSqlLoggerFactory.Clear();
//Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}

public override async Task Create_table()
Expand Down Expand Up @@ -56,7 +56,7 @@ public override async Task Create_table_all_settings()
[SSN] nvarchar(11) NOT NULL,
CONSTRAINT [PK_People] PRIMARY KEY ([CustomId]),
CONSTRAINT [AK_People_SSN] UNIQUE ([SSN]),
CONSTRAINT [CK_SSN] CHECK ([SSN] > 0),
CONSTRAINT [CK_EmployerId] CHECK ([EmployerId] > 0),
CONSTRAINT [FK_People_Employers_EmployerId] FOREIGN KEY ([EmployerId]) REFERENCES [Employers] ([Id]) ON DELETE NO ACTION
);
EXEC sp_addextendedproperty 'MS_Description', N'Table comment', 'SCHEMA', N'dbo2', 'TABLE', N'People';
Expand Down Expand Up @@ -315,15 +315,15 @@ public override async Task Add_column_with_defaultValueSql()
await base.Add_column_with_defaultValueSql();

AssertSql(
@"ALTER TABLE [People] ADD [Birthday] date NULL DEFAULT (CURRENT_TIMESTAMP);");
@"ALTER TABLE [People] ADD [Sum] int NOT NULL DEFAULT (1 + 2);");
}

public override async Task Add_column_with_computedSql()
{
await base.Add_column_with_computedSql();

AssertSql(
@"ALTER TABLE [People] ADD [FullName] AS FirstName + ' ' + LastName;");
@"ALTER TABLE [People] ADD [Sum] AS [X] + [Y];");
}

public override async Task Add_column_with_required()
Expand Down Expand Up @@ -495,10 +495,10 @@ public override async Task Alter_column_make_computed()
SELECT @var0 = [d].[name]
FROM [sys].[default_constraints] [d]
INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'FullName');
WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Sum');
IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];');
ALTER TABLE [People] DROP COLUMN [FullName];
ALTER TABLE [People] ADD [FullName] AS FirstName + ' ' + LastName;");
ALTER TABLE [People] DROP COLUMN [Sum];
ALTER TABLE [People] ADD [Sum] AS [X] + [Y];");
}

public override async Task Alter_column_change_computed()
Expand All @@ -510,10 +510,10 @@ public override async Task Alter_column_change_computed()
SELECT @var0 = [d].[name]
FROM [sys].[default_constraints] [d]
INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'FullName');
WHERE ([d].[parent_object_id] = OBJECT_ID(N'[People]') AND [c].[name] = N'Sum');
IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [People] DROP CONSTRAINT [' + @var0 + '];');
ALTER TABLE [People] DROP COLUMN [FullName];
ALTER TABLE [People] ADD [FullName] AS FirstName + ', ' + LastName;");
ALTER TABLE [People] DROP COLUMN [Sum];
ALTER TABLE [People] ADD [Sum] AS [X] - [Y];");
}

[ConditionalFact]
Expand Down