-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add entity splitting tests for migrations and update pipeline
Don't use identity be default for columns with FKs even when the property is mapped to other columns that should use identity Part of #620
- Loading branch information
1 parent
f72888f
commit da9fe63
Showing
13 changed files
with
314 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationStrategyConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
test/EFCore.Relational.Specification.Tests/EntitySplittingTestBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// ReSharper disable InconsistentNaming | ||
namespace Microsoft.EntityFrameworkCore; | ||
|
||
public abstract class EntitySplittingTestBase : NonSharedModelTestBase | ||
{ | ||
protected EntitySplittingTestBase(ITestOutputHelper testOutputHelper) | ||
{ | ||
//TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); | ||
} | ||
|
||
[ConditionalFact(Skip = "Entity splitting query Issue #620")] | ||
public virtual async Task Can_roundtrip() | ||
{ | ||
await InitializeAsync(OnModelCreating, sensitiveLogEnabled: false); | ||
|
||
await using (var context = CreateContext()) | ||
{ | ||
var meterReading = new MeterReading { ReadingStatus = MeterReadingStatus.NotAccesible, CurrentRead = "100" }; | ||
|
||
context.Add(meterReading); | ||
|
||
TestSqlLoggerFactory.Clear(); | ||
|
||
await context.SaveChangesAsync(); | ||
|
||
Assert.Empty(TestSqlLoggerFactory.Log.Where(l => l.Level == LogLevel.Warning)); | ||
} | ||
|
||
await using (var context = CreateContext()) | ||
{ | ||
var reading = await context.MeterReadings.SingleAsync(); | ||
|
||
Assert.Equal(MeterReadingStatus.NotAccesible, reading.ReadingStatus); | ||
Assert.Equal("100", reading.CurrentRead); | ||
} | ||
} | ||
|
||
protected override string StoreName { get; } = "EntitySplittingTest"; | ||
|
||
protected TestSqlLoggerFactory TestSqlLoggerFactory | ||
=> (TestSqlLoggerFactory)ListLoggerFactory; | ||
|
||
protected ContextFactory<EntitySplittingContext> ContextFactory { get; private set; } | ||
|
||
protected void AssertSql(params string[] expected) | ||
=> TestSqlLoggerFactory.AssertBaseline(expected); | ||
|
||
protected virtual void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<MeterReading>( | ||
ob => | ||
{ | ||
ob.ToTable("MeterReadings"); | ||
ob.SplitToTable( | ||
"MeterReadingDetails", t => | ||
{ | ||
t.Property(o => o.PreviousRead); | ||
t.Property(o => o.CurrentRead); | ||
}); | ||
}); | ||
} | ||
|
||
protected async Task InitializeAsync(Action<ModelBuilder> onModelCreating, bool sensitiveLogEnabled = true) | ||
=> ContextFactory = await InitializeAsync<EntitySplittingContext>( | ||
onModelCreating, | ||
shouldLogCategory: _ => true, | ||
onConfiguring: options => | ||
{ | ||
options.ConfigureWarnings(w => w.Log(RelationalEventId.OptionalDependentWithAllNullPropertiesWarning)) | ||
.ConfigureWarnings(w => w.Log(RelationalEventId.OptionalDependentWithoutIdentifyingPropertyWarning)) | ||
.EnableSensitiveDataLogging(sensitiveLogEnabled); | ||
} | ||
); | ||
|
||
protected virtual EntitySplittingContext CreateContext() | ||
=> ContextFactory.CreateContext(); | ||
|
||
public override void Dispose() | ||
{ | ||
base.Dispose(); | ||
|
||
ContextFactory = null; | ||
} | ||
|
||
protected class EntitySplittingContext : PoolableDbContext | ||
{ | ||
public EntitySplittingContext(DbContextOptions options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
public DbSet<MeterReading> MeterReadings { get; set; } | ||
} | ||
|
||
protected class MeterReading | ||
{ | ||
public int Id { get; set; } | ||
public MeterReadingStatus? ReadingStatus { get; set; } | ||
public string CurrentRead { get; set; } | ||
public string PreviousRead { get; set; } | ||
} | ||
|
||
protected enum MeterReadingStatus | ||
{ | ||
Running = 0, | ||
NotAccesible = 2 | ||
} | ||
} |
Oops, something went wrong.