Skip to content

Commit

Permalink
Detect SqlServer features automagically rather than using env vars
Browse files Browse the repository at this point in the history
fixes dotnet#20318

I have attempted to cater for current implicit assumptions - but it is opaque to me what SQL Server edtions tests are actually run against.

Tested with SQL 2016 Developer Edition and LocalDb version 14
  • Loading branch information
ErikEJ committed Mar 22, 2020
1 parent ac46335 commit 48674c6
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public void Constructed_select_query_CommandBuilder_throws_when_negative_Command
}

[ConditionalTheory]
[SqlServerCondition(SqlServerCondition.SupportsSequences)]
[InlineData(59, 6)]
[InlineData(50, 5)]
[InlineData(20, 2)]
Expand Down Expand Up @@ -82,10 +81,7 @@ public ChipsContext(DbContextOptions options)

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
if (TestEnvironment.GetFlag(nameof(SqlServerCondition.SupportsSequences)) ?? true)
{
modelBuilder.UseHiLo();
}
modelBuilder.UseHiLo();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public SqlServerDatabaseModelFactoryTest(SqlServerDatabaseModelFixture fixture)
#region Sequences

[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsSequences)]
public void Create_sequences_with_facets()
{
Test(
Expand Down Expand Up @@ -82,7 +81,6 @@ MAXVALUE 8
}

[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsSequences)]
public void Sequence_min_max_start_values_are_null_if_default()
{
Test(
Expand Down Expand Up @@ -118,7 +116,6 @@ public void Sequence_min_max_start_values_are_null_if_default()
}

[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsSequences)]
public void Sequence_min_max_start_values_are_not_null_if_decimal()
{
Test(
Expand Down Expand Up @@ -146,7 +143,6 @@ public void Sequence_min_max_start_values_are_not_null_if_decimal()
}

[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsSequences)]
public void Sequence_using_type_alias()
{
Fixture.TestStore.ExecuteNonQuery(
Expand Down Expand Up @@ -177,7 +173,6 @@ public void Sequence_using_type_alias()
}

[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsSequences)]
public void Sequence_using_type_with_facets()
{
Test(
Expand All @@ -200,7 +195,6 @@ public void Sequence_using_type_with_facets()
}

[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsSequences)]
public void Filter_sequences_based_on_schema()
{
Test(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// ReSharper disable InconsistentNaming
namespace Microsoft.EntityFrameworkCore
{
[SqlServerCondition(SqlServerCondition.SupportsSequences)]
public class SequenceEndToEndTest : IDisposable
{
[ConditionalFact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public BlogContextIdentity(string databaseName)
}
}

[SqlServerCondition(SqlServerCondition.SupportsSequences)]
[ConditionalFact]
public void Insert_with_sequence_HiLo()
{
Expand Down Expand Up @@ -99,7 +98,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}

[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsSequences)]
public void Insert_with_default_value_from_sequence()
{
using var testStore = SqlServerTestStore.CreateInitialized(DatabaseName);
Expand Down Expand Up @@ -177,7 +175,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}

[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsSequences)]
public void Insert_with_default_string_value_from_sequence()
{
using var testStore = SqlServerTestStore.CreateInitialized(DatabaseName);
Expand Down Expand Up @@ -231,7 +228,6 @@ public class BlogWithStringKey
}

[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsSequences)]
public void Insert_with_key_default_value_from_sequence()
{
using var testStore = SqlServerTestStore.CreateInitialized(DatabaseName);
Expand Down Expand Up @@ -872,7 +868,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}

[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsSequences)]
public void Insert_explicit_value_throws_when_readonly_sequence_before_save()
{
using var testStore = SqlServerTestStore.CreateInitialized(DatabaseName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ namespace Microsoft.EntityFrameworkCore.TestUtilities
[Flags]
public enum SqlServerCondition
{
SupportsSequences = 1 << 0,
IsSqlAzure = 1 << 1,
IsNotSqlAzure = 1 << 2,
SupportsMemoryOptimized = 1 << 3,
SupportsAttach = 1 << 4,
SupportsHiddenColumns = 1 << 5,
IsNotCI = 1 << 6,
SupportsFullTextSearch = 1 << 7,
SupportsOnlineIndexes = 1 << 8
IsSqlAzure = 1 << 0,
IsNotSqlAzure = 1 << 1,
SupportsMemoryOptimized = 1 << 2,
SupportsAttach = 1 << 3,
SupportsHiddenColumns = 1 << 4,
IsNotCI = 1 << 5,
SupportsFullTextSearch = 1 << 6,
SupportsOnlineIndexes = 1 << 7,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@ public SqlServerConditionAttribute(SqlServerCondition conditions)
public ValueTask<bool> IsMetAsync()
{
var isMet = true;
if (Conditions.HasFlag(SqlServerCondition.SupportsSequences))
{
isMet &= TestEnvironment.GetFlag(nameof(SqlServerCondition.SupportsSequences)) ?? true;
}

if (Conditions.HasFlag(SqlServerCondition.SupportsHiddenColumns))
{
isMet &= TestEnvironment.GetFlag(nameof(SqlServerCondition.SupportsHiddenColumns)) ?? false;
isMet &= TestEnvironment.IsHiddenColumnsSupported;
}

if (Conditions.HasFlag(SqlServerCondition.SupportsMemoryOptimized))
{
isMet &= TestEnvironment.GetFlag(nameof(SqlServerCondition.SupportsMemoryOptimized)) ?? false;
isMet &= TestEnvironment.IsMemoryOptimizedTablesSupported;
}

if (Conditions.HasFlag(SqlServerCondition.IsSqlAzure))
Expand All @@ -50,7 +46,7 @@ public ValueTask<bool> IsMetAsync()
if (Conditions.HasFlag(SqlServerCondition.SupportsAttach))
{
var defaultConnection = new SqlConnectionStringBuilder(TestEnvironment.DefaultConnection);
isMet &= defaultConnection.DataSource.Contains("(localdb)")
isMet &= defaultConnection.DataSource.Contains("(localdb)", StringComparison.OrdinalIgnoreCase)
|| defaultConnection.UserInstance;
}

Expand All @@ -64,6 +60,11 @@ public ValueTask<bool> IsMetAsync()
isMet &= TestEnvironment.IsFullTextSearchSupported;
}

if (Conditions.HasFlag(SqlServerCondition.SupportsOnlineIndexes))
{
isMet &= TestEnvironment.IsOnlineIndexingSupported;
}

return new ValueTask<bool>(isMet);
}

Expand Down
Loading

0 comments on commit 48674c6

Please sign in to comment.