From fe9363252ca5afefaadcef031d612400afe78e27 Mon Sep 17 00:00:00 2001 From: Andriy Svyryd Date: Wed, 23 Oct 2019 16:09:08 -0700 Subject: [PATCH] Tweak the API for Azure edition options. (#18544) --- .../SqlServerModelBuilderExtensions.cs | 90 ++++++++++++++----- .../Extensions/SqlServerModelExtensions.cs | 34 +++---- .../Internal/SqlServerAnnotationNames.cs | 4 +- .../SqlServerMigrationsAnnotationProvider.cs | 5 +- .../Migrations/ModelSnapshotSqlServerTest.cs | 8 +- .../SqlAzure/SqlAzureDatabaseCreationTest.cs | 6 +- .../SqlServerMetadataBuilderExtensionsTest.cs | 58 ++++++------ .../SqlServerMetadataExtensionsTest.cs | 52 +++++------ .../Migrations/SqlServerModelDifferTest.cs | 4 +- 9 files changed, 151 insertions(+), 110 deletions(-) diff --git a/src/EFCore.SqlServer/Extensions/SqlServerModelBuilderExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerModelBuilderExtensions.cs index a87d0f2d056..e59e75a0056 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerModelBuilderExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerModelBuilderExtensions.cs @@ -319,21 +319,42 @@ public static bool CanSetDatabaseMaxSize( /// /// - /// Configures the service tier (EDITION) for Azure SQL Database. + /// Configures the service tier (EDITION) for Azure SQL Database as a string literal. /// /// - /// Literals should be delimited with ''. See Azure SQL Database documentation for supported values. + /// See Azure SQL Database documentation for supported values. /// /// /// The model builder. - /// The service tier of the database. + /// The service tier of the database as a string literal. /// The same builder instance so that multiple calls can be chained. public static ModelBuilder HasServiceTier([NotNull] this ModelBuilder modelBuilder, [NotNull] string serviceTier) { Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NotNull(serviceTier, nameof(serviceTier)); - modelBuilder.Model.SetServiceTier(serviceTier); + modelBuilder.Model.SetServiceTierSql("'" + serviceTier.Replace("'", "''") + "'"); + + return modelBuilder; + } + + /// + /// + /// Configures the service tier (EDITION) for Azure SQL Database as a SQL expression. + /// + /// + /// See Azure SQL Database documentation for supported values. + /// + /// + /// The model builder. + /// The expression for the service tier of the database. + /// The same builder instance so that multiple calls can be chained. + public static ModelBuilder HasServiceTierSql([NotNull] this ModelBuilder modelBuilder, [NotNull] string serviceTier) + { + Check.NotNull(modelBuilder, nameof(modelBuilder)); + Check.NotNull(serviceTier, nameof(serviceTier)); + + modelBuilder.Model.SetServiceTierSql(serviceTier); return modelBuilder; } @@ -343,22 +364,22 @@ public static ModelBuilder HasServiceTier([NotNull] this ModelBuilder modelBuild /// Attempts to configure the service tier (EDITION) for Azure SQL Database. /// /// - /// Literals should be delimited with ''. See Azure SQL Database documentation for supported values. + /// See Azure SQL Database documentation for supported values. /// /// /// The model builder. - /// The service tier of the database. + /// The expression for the service tier of the database. /// Indicates whether the configuration was specified using a data annotation. /// /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionModelBuilder HasServiceTier( + public static IConventionModelBuilder HasServiceTierSql( [NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string serviceTier, bool fromDataAnnotation = false) { - if (modelBuilder.CanSetServiceTier(serviceTier, fromDataAnnotation)) + if (modelBuilder.CanSetServiceTierSql(serviceTier, fromDataAnnotation)) { - modelBuilder.Metadata.SetServiceTier(serviceTier, fromDataAnnotation); + modelBuilder.Metadata.SetServiceTierSql(serviceTier, fromDataAnnotation); return modelBuilder; } @@ -369,34 +390,55 @@ public static IConventionModelBuilder HasServiceTier( /// Returns a value indicating whether the given value can be set as the service tier of the database. /// /// The model builder. - /// The service tier of the database. + /// The expression for the service tier of the database. /// Indicates whether the configuration was specified using a data annotation. /// true if the given value can be set as the service tier of the database. - public static bool CanSetServiceTier( + public static bool CanSetServiceTierSql( [NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string serviceTier, bool fromDataAnnotation = false) { Check.NotNull(modelBuilder, nameof(modelBuilder)); - return modelBuilder.CanSetAnnotation(SqlServerAnnotationNames.ServiceTier, serviceTier, fromDataAnnotation); + return modelBuilder.CanSetAnnotation(SqlServerAnnotationNames.ServiceTierSql, serviceTier, fromDataAnnotation); } /// /// - /// Configures the performance level (SERVICE_OBJECTIVE) for Azure SQL Database. + /// Configures the performance level (SERVICE_OBJECTIVE) for Azure SQL Database as a string literal. /// /// - /// Literals should be delimited with ''. See Azure SQL Database documentation for supported values. + /// See Azure SQL Database documentation for supported values. /// /// /// The model builder. - /// The performance level of the database. + /// The performance level of the database as a string literal. /// The same builder instance so that multiple calls can be chained. public static ModelBuilder HasPerformanceLevel([NotNull] this ModelBuilder modelBuilder, [NotNull] string performanceLevel) { Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NotNull(performanceLevel, nameof(performanceLevel)); - modelBuilder.Model.SetPerformanceLevel(performanceLevel); + modelBuilder.Model.SetPerformanceLevelSql("'" + performanceLevel.Replace("'", "''") + "'"); + + return modelBuilder; + } + + /// + /// + /// Configures the performance level (SERVICE_OBJECTIVE) for Azure SQL Database as a SQL expression. + /// + /// + /// See Azure SQL Database documentation for supported values. + /// + /// + /// The model builder. + /// The expression for the performance level of the database. + /// The same builder instance so that multiple calls can be chained. + public static ModelBuilder HasPerformanceLevelSql([NotNull] this ModelBuilder modelBuilder, [NotNull] string performanceLevel) + { + Check.NotNull(modelBuilder, nameof(modelBuilder)); + Check.NotNull(performanceLevel, nameof(performanceLevel)); + + modelBuilder.Model.SetPerformanceLevelSql(performanceLevel); return modelBuilder; } @@ -406,22 +448,22 @@ public static ModelBuilder HasPerformanceLevel([NotNull] this ModelBuilder model /// Attempts to configure the performance level (SERVICE_OBJECTIVE) for Azure SQL Database. /// /// - /// Literals should be delimited with ''. See Azure SQL Database documentation for supported values. + /// See Azure SQL Database documentation for supported values. /// /// /// The model builder. - /// The performance level of the database. + /// The expression for the performance level of the database. /// Indicates whether the configuration was specified using a data annotation. /// /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionModelBuilder HasPerformanceLevel( + public static IConventionModelBuilder HasPerformanceLevelSql( [NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string performanceLevel, bool fromDataAnnotation = false) { - if (modelBuilder.CanSetPerformanceLevel(performanceLevel, fromDataAnnotation)) + if (modelBuilder.CanSetPerformanceLevelSql(performanceLevel, fromDataAnnotation)) { - modelBuilder.Metadata.SetPerformanceLevel(performanceLevel, fromDataAnnotation); + modelBuilder.Metadata.SetPerformanceLevelSql(performanceLevel, fromDataAnnotation); return modelBuilder; } @@ -432,15 +474,15 @@ public static IConventionModelBuilder HasPerformanceLevel( /// Returns a value indicating whether the given value can be set as the performance level of the database. /// /// The model builder. - /// The performance level of the database. + /// The performance level of the database expression. /// Indicates whether the configuration was specified using a data annotation. /// true if the given value can be set as the performance level of the database. - public static bool CanSetPerformanceLevel( + public static bool CanSetPerformanceLevelSql( [NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string performanceLevel, bool fromDataAnnotation = false) { Check.NotNull(modelBuilder, nameof(modelBuilder)); - return modelBuilder.CanSetAnnotation(SqlServerAnnotationNames.PerformanceLevel, performanceLevel, fromDataAnnotation); + return modelBuilder.CanSetAnnotation(SqlServerAnnotationNames.PerformanceLevelSql, performanceLevel, fromDataAnnotation); } /// diff --git a/src/EFCore.SqlServer/Extensions/SqlServerModelExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerModelExtensions.cs index 6abb02c777e..e36a190f101 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerModelExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerModelExtensions.cs @@ -250,7 +250,7 @@ public static void SetDatabaseMaxSize( /// /// The model. /// The for the maximum size of the database. - public static ConfigurationSource? GetMaxSizeConfigurationSource([NotNull] this IConventionModel model) + public static ConfigurationSource? GetDatabaseMaxSizeConfigurationSource([NotNull] this IConventionModel model) => model.FindAnnotation(SqlServerAnnotationNames.MaxDatabaseSize)?.GetConfigurationSource(); /// @@ -258,16 +258,16 @@ public static void SetDatabaseMaxSize( /// /// The model. /// The service tier of the database. - public static string GetServiceTier([NotNull] this IModel model) - => (string)model[SqlServerAnnotationNames.ServiceTier]; + public static string GetServiceTierSql([NotNull] this IModel model) + => (string)model[SqlServerAnnotationNames.ServiceTierSql]; /// /// Sets the service tier of the database. /// /// The model. /// The value to set. - public static void SetServiceTier([NotNull] this IMutableModel model, [CanBeNull] string value) - => model.SetOrRemoveAnnotation(SqlServerAnnotationNames.ServiceTier, value); + public static void SetServiceTierSql([NotNull] this IMutableModel model, [CanBeNull] string value) + => model.SetOrRemoveAnnotation(SqlServerAnnotationNames.ServiceTierSql, value); /// /// Sets the service tier of the database. @@ -275,33 +275,33 @@ public static void SetServiceTier([NotNull] this IMutableModel model, [CanBeNull /// The model. /// The value to set. /// Indicates whether the configuration was specified using a data annotation. - public static void SetServiceTier( + public static void SetServiceTierSql( [NotNull] this IConventionModel model, [CanBeNull] string value, bool fromDataAnnotation = false) - => model.SetOrRemoveAnnotation(SqlServerAnnotationNames.ServiceTier, value, fromDataAnnotation); + => model.SetOrRemoveAnnotation(SqlServerAnnotationNames.ServiceTierSql, value, fromDataAnnotation); /// /// Returns the for the service tier of the database. /// /// The model. /// The for the service tier of the database. - public static ConfigurationSource? GetServiceTierConfigurationSource([NotNull] this IConventionModel model) - => model.FindAnnotation(SqlServerAnnotationNames.ServiceTier)?.GetConfigurationSource(); + public static ConfigurationSource? GetServiceTierSqlConfigurationSource([NotNull] this IConventionModel model) + => model.FindAnnotation(SqlServerAnnotationNames.ServiceTierSql)?.GetConfigurationSource(); /// /// Returns the performance level of the database. /// /// The model. /// The performance level of the database. - public static string GetPerformanceLevel([NotNull] this IModel model) - => (string)model[SqlServerAnnotationNames.PerformanceLevel]; + public static string GetPerformanceLevelSql([NotNull] this IModel model) + => (string)model[SqlServerAnnotationNames.PerformanceLevelSql]; /// /// Sets the performance level of the database. /// /// The model. /// The value to set. - public static void SetPerformanceLevel([NotNull] this IMutableModel model, [CanBeNull] string value) - => model.SetOrRemoveAnnotation(SqlServerAnnotationNames.PerformanceLevel, value); + public static void SetPerformanceLevelSql([NotNull] this IMutableModel model, [CanBeNull] string value) + => model.SetOrRemoveAnnotation(SqlServerAnnotationNames.PerformanceLevelSql, value); /// /// Sets the performance level of the database. @@ -309,16 +309,16 @@ public static void SetPerformanceLevel([NotNull] this IMutableModel model, [CanB /// The model. /// The value to set. /// Indicates whether the configuration was specified using a data annotation. - public static void SetPerformanceLevel( + public static void SetPerformanceLevelSql( [NotNull] this IConventionModel model, [CanBeNull] string value, bool fromDataAnnotation = false) - => model.SetOrRemoveAnnotation(SqlServerAnnotationNames.PerformanceLevel, value, fromDataAnnotation); + => model.SetOrRemoveAnnotation(SqlServerAnnotationNames.PerformanceLevelSql, value, fromDataAnnotation); /// /// Returns the for the performance level of the database. /// /// The model. /// The for the performance level of the database. - public static ConfigurationSource? GetPerformanceLevelConfigurationSource([NotNull] this IConventionModel model) - => model.FindAnnotation(SqlServerAnnotationNames.PerformanceLevel)?.GetConfigurationSource(); + public static ConfigurationSource? GetPerformanceLevelSqlConfigurationSource([NotNull] this IConventionModel model) + => model.FindAnnotation(SqlServerAnnotationNames.PerformanceLevelSql)?.GetConfigurationSource(); } } diff --git a/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationNames.cs b/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationNames.cs index ae180d2ea6b..ac73917367a 100644 --- a/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationNames.cs +++ b/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationNames.cs @@ -121,7 +121,7 @@ public static class SqlServerAnnotationNames /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public const string ServiceTier = Prefix + "ServiceTier"; + public const string ServiceTierSql = Prefix + "ServiceTierSql"; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -129,6 +129,6 @@ public static class SqlServerAnnotationNames /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public const string PerformanceLevel = Prefix + "PerformanceLevel"; + public const string PerformanceLevelSql = Prefix + "PerformanceLevelSql"; } } diff --git a/src/EFCore.SqlServer/Migrations/Internal/SqlServerMigrationsAnnotationProvider.cs b/src/EFCore.SqlServer/Migrations/Internal/SqlServerMigrationsAnnotationProvider.cs index 039be4361d5..6e661f9afe2 100644 --- a/src/EFCore.SqlServer/Migrations/Internal/SqlServerMigrationsAnnotationProvider.cs +++ b/src/EFCore.SqlServer/Migrations/Internal/SqlServerMigrationsAnnotationProvider.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Runtime.InteropServices.ComTypes; using System.Text; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -48,8 +47,8 @@ public SqlServerMigrationsAnnotationProvider([NotNull] MigrationsAnnotationProvi public override IEnumerable For(IModel model) { var maxSize = model.GetDatabaseMaxSize(); - var serviceTier = model.GetServiceTier(); - var performanceLevel = model.GetPerformanceLevel(); + var serviceTier = model.GetServiceTierSql(); + var performanceLevel = model.GetPerformanceLevelSql(); if (maxSize != null || serviceTier != null || performanceLevel != null) diff --git a/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs b/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs index e08a0f0d291..d9ec7d00e46 100644 --- a/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs +++ b/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs @@ -227,16 +227,16 @@ public virtual void Model_annotations_are_stored_in_snapshot() Test( builder => builder.HasAnnotation("AnnotationName", "AnnotationValue") .HasDatabaseMaxSize("100 MB") - .HasServiceTier("'basic'") - .HasPerformanceLevel("'S0'"), + .HasServiceTier("basic") + .HasPerformanceLevel("S0"), AddBoilerPlate( @" modelBuilder .HasAnnotation(""AnnotationName"", ""AnnotationValue"") .HasAnnotation(""Relational:MaxIdentifierLength"", 128) .HasAnnotation(""SqlServer:DatabaseMaxSize"", ""100 MB"") - .HasAnnotation(""SqlServer:PerformanceLevel"", ""'S0'"") - .HasAnnotation(""SqlServer:ServiceTier"", ""'basic'"") + .HasAnnotation(""SqlServer:PerformanceLevelSql"", ""'S0'"") + .HasAnnotation(""SqlServer:ServiceTierSql"", ""'basic'"") .HasAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn);"), o => { diff --git a/test/EFCore.SqlServer.FunctionalTests/SqlAzure/SqlAzureDatabaseCreationTest.cs b/test/EFCore.SqlServer.FunctionalTests/SqlAzure/SqlAzureDatabaseCreationTest.cs index ed5f6830356..2131a1fbb9d 100644 --- a/test/EFCore.SqlServer.FunctionalTests/SqlAzure/SqlAzureDatabaseCreationTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/SqlAzure/SqlAzureDatabaseCreationTest.cs @@ -50,7 +50,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.HasPerformanceLevel("ELASTIC_POOL ( name = unicornhack )"); + modelBuilder.HasPerformanceLevelSql("ELASTIC_POOL ( name = unicornhack )"); } } @@ -126,8 +126,8 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.HasDatabaseMaxSize("2 GB"); - modelBuilder.HasServiceTier("'BusinessCritical'"); - modelBuilder.HasPerformanceLevel("'BC_Gen4_1'"); + modelBuilder.HasServiceTier("BusinessCritical"); + modelBuilder.HasPerformanceLevel("BC_Gen4_1"); } } diff --git a/test/EFCore.SqlServer.Tests/Metadata/SqlServerMetadataBuilderExtensionsTest.cs b/test/EFCore.SqlServer.Tests/Metadata/SqlServerMetadataBuilderExtensionsTest.cs index 7e386d821db..3e2ba4f28dc 100644 --- a/test/EFCore.SqlServer.Tests/Metadata/SqlServerMetadataBuilderExtensionsTest.cs +++ b/test/EFCore.SqlServer.Tests/Metadata/SqlServerMetadataBuilderExtensionsTest.cs @@ -50,7 +50,7 @@ public void Can_access_model_max_size() var builder = CreateBuilder(); Assert.Null(builder.Metadata.GetDatabaseMaxSize()); - Assert.Null(builder.Metadata.GetMaxSizeConfigurationSource()); + Assert.Null(builder.Metadata.GetDatabaseMaxSizeConfigurationSource()); Assert.NotNull(builder.HasDatabaseMaxSize("50 GB")); Assert.Equal("50 GB", builder.Metadata.GetDatabaseMaxSize()); @@ -58,7 +58,7 @@ public void Can_access_model_max_size() Assert.NotNull( builder.HasDatabaseMaxSize("100 GB", fromDataAnnotation: true)); Assert.Equal("100 GB", builder.Metadata.GetDatabaseMaxSize()); - Assert.Equal(ConfigurationSource.DataAnnotation, builder.Metadata.GetMaxSizeConfigurationSource()); + Assert.Equal(ConfigurationSource.DataAnnotation, builder.Metadata.GetDatabaseMaxSizeConfigurationSource()); Assert.NotNull(builder.HasDatabaseMaxSize("100 GB")); Assert.Null(builder.HasDatabaseMaxSize("500 GB")); @@ -66,7 +66,7 @@ public void Can_access_model_max_size() Assert.NotNull(builder.HasDatabaseMaxSize(null, fromDataAnnotation: true)); Assert.Null(builder.Metadata.GetDatabaseMaxSize()); - Assert.Null(builder.Metadata.GetMaxSizeConfigurationSource()); + Assert.Null(builder.Metadata.GetDatabaseMaxSizeConfigurationSource()); } [ConditionalFact] @@ -74,24 +74,24 @@ public void Can_access_model_service_tier() { var builder = CreateBuilder(); - Assert.Null(builder.Metadata.GetServiceTier()); - Assert.Null(builder.Metadata.GetServiceTierConfigurationSource()); + Assert.Null(builder.Metadata.GetServiceTierSql()); + Assert.Null(builder.Metadata.GetServiceTierSqlConfigurationSource()); - Assert.NotNull(builder.HasServiceTier("premium")); - Assert.Equal("premium", builder.Metadata.GetServiceTier()); + Assert.NotNull(builder.HasServiceTierSql("premium")); + Assert.Equal("premium", builder.Metadata.GetServiceTierSql()); Assert.NotNull( - builder.HasServiceTier("basic", fromDataAnnotation: true)); - Assert.Equal("basic", builder.Metadata.GetServiceTier()); - Assert.Equal(ConfigurationSource.DataAnnotation, builder.Metadata.GetServiceTierConfigurationSource()); - Assert.NotNull(builder.HasServiceTier("basic")); + builder.HasServiceTierSql("basic", fromDataAnnotation: true)); + Assert.Equal("basic", builder.Metadata.GetServiceTierSql()); + Assert.Equal(ConfigurationSource.DataAnnotation, builder.Metadata.GetServiceTierSqlConfigurationSource()); + Assert.NotNull(builder.HasServiceTierSql("basic")); - Assert.Null(builder.HasServiceTier("premium")); - Assert.Equal("basic", builder.Metadata.GetServiceTier()); + Assert.Null(builder.HasServiceTierSql("premium")); + Assert.Equal("basic", builder.Metadata.GetServiceTierSql()); - Assert.NotNull(builder.HasServiceTier(null, fromDataAnnotation: true)); - Assert.Null(builder.Metadata.GetServiceTier()); - Assert.Null(builder.Metadata.GetServiceTierConfigurationSource()); + Assert.NotNull(builder.HasServiceTierSql(null, fromDataAnnotation: true)); + Assert.Null(builder.Metadata.GetServiceTierSql()); + Assert.Null(builder.Metadata.GetServiceTierSqlConfigurationSource()); } [ConditionalFact] @@ -99,24 +99,24 @@ public void Can_access_model_performance_level() { var builder = CreateBuilder(); - Assert.Null(builder.Metadata.GetPerformanceLevel()); - Assert.Null(builder.Metadata.GetPerformanceLevelConfigurationSource()); + Assert.Null(builder.Metadata.GetPerformanceLevelSql()); + Assert.Null(builder.Metadata.GetPerformanceLevelSqlConfigurationSource()); - Assert.NotNull(builder.HasPerformanceLevel("P1")); - Assert.Equal("P1", builder.Metadata.GetPerformanceLevel()); + Assert.NotNull(builder.HasPerformanceLevelSql("P1")); + Assert.Equal("P1", builder.Metadata.GetPerformanceLevelSql()); Assert.NotNull( - builder.HasPerformanceLevel("P4", fromDataAnnotation: true)); - Assert.Equal("P4", builder.Metadata.GetPerformanceLevel()); - Assert.Equal(ConfigurationSource.DataAnnotation, builder.Metadata.GetPerformanceLevelConfigurationSource()); - Assert.NotNull(builder.HasPerformanceLevel("P4")); + builder.HasPerformanceLevelSql("P4", fromDataAnnotation: true)); + Assert.Equal("P4", builder.Metadata.GetPerformanceLevelSql()); + Assert.Equal(ConfigurationSource.DataAnnotation, builder.Metadata.GetPerformanceLevelSqlConfigurationSource()); + Assert.NotNull(builder.HasPerformanceLevelSql("P4")); - Assert.Null(builder.HasPerformanceLevel("P1")); - Assert.Equal("P4", builder.Metadata.GetPerformanceLevel()); + Assert.Null(builder.HasPerformanceLevelSql("P1")); + Assert.Equal("P4", builder.Metadata.GetPerformanceLevelSql()); - Assert.NotNull(builder.HasPerformanceLevel(null, fromDataAnnotation: true)); - Assert.Null(builder.Metadata.GetPerformanceLevel()); - Assert.Null(builder.Metadata.GetPerformanceLevelConfigurationSource()); + Assert.NotNull(builder.HasPerformanceLevelSql(null, fromDataAnnotation: true)); + Assert.Null(builder.Metadata.GetPerformanceLevelSql()); + Assert.Null(builder.Metadata.GetPerformanceLevelSqlConfigurationSource()); } [ConditionalFact] diff --git a/test/EFCore.SqlServer.Tests/Metadata/SqlServerMetadataExtensionsTest.cs b/test/EFCore.SqlServer.Tests/Metadata/SqlServerMetadataExtensionsTest.cs index c4610f0d5df..791f514e670 100644 --- a/test/EFCore.SqlServer.Tests/Metadata/SqlServerMetadataExtensionsTest.cs +++ b/test/EFCore.SqlServer.Tests/Metadata/SqlServerMetadataExtensionsTest.cs @@ -21,22 +21,22 @@ public void Can_get_and_set_MaxSize() .Model; Assert.Null(model.GetDatabaseMaxSize()); - Assert.Null(((IConventionModel)model).GetMaxSizeConfigurationSource()); + Assert.Null(((IConventionModel)model).GetDatabaseMaxSizeConfigurationSource()); ((IConventionModel)model).SetDatabaseMaxSize("1 GB", fromDataAnnotation: true); Assert.Equal("1 GB", model.GetDatabaseMaxSize()); - Assert.Equal(ConfigurationSource.DataAnnotation, ((IConventionModel)model).GetMaxSizeConfigurationSource()); + Assert.Equal(ConfigurationSource.DataAnnotation, ((IConventionModel)model).GetDatabaseMaxSizeConfigurationSource()); model.SetDatabaseMaxSize("10 GB"); Assert.Equal("10 GB", model.GetDatabaseMaxSize()); - Assert.Equal(ConfigurationSource.Explicit, ((IConventionModel)model).GetMaxSizeConfigurationSource()); + Assert.Equal(ConfigurationSource.Explicit, ((IConventionModel)model).GetDatabaseMaxSizeConfigurationSource()); model.SetDatabaseMaxSize(null); Assert.Null(model.GetDatabaseMaxSize()); - Assert.Null(((IConventionModel)model).GetMaxSizeConfigurationSource()); + Assert.Null(((IConventionModel)model).GetDatabaseMaxSizeConfigurationSource()); } [ConditionalFact] @@ -47,23 +47,23 @@ public void Can_get_and_set_ServiceTier() var model = modelBuilder .Model; - Assert.Null(model.GetServiceTier()); - Assert.Null(((IConventionModel)model).GetMaxSizeConfigurationSource()); + Assert.Null(model.GetServiceTierSql()); + Assert.Null(((IConventionModel)model).GetDatabaseMaxSizeConfigurationSource()); - ((IConventionModel)model).SetServiceTier("basic", fromDataAnnotation: true); + ((IConventionModel)model).SetServiceTierSql("basic", fromDataAnnotation: true); - Assert.Equal("basic", model.GetServiceTier()); - Assert.Equal(ConfigurationSource.DataAnnotation, ((IConventionModel)model).GetServiceTierConfigurationSource()); + Assert.Equal("basic", model.GetServiceTierSql()); + Assert.Equal(ConfigurationSource.DataAnnotation, ((IConventionModel)model).GetServiceTierSqlConfigurationSource()); - model.SetServiceTier("standard"); + model.SetServiceTierSql("standard"); - Assert.Equal("standard", model.GetServiceTier()); - Assert.Equal(ConfigurationSource.Explicit, ((IConventionModel)model).GetServiceTierConfigurationSource()); + Assert.Equal("standard", model.GetServiceTierSql()); + Assert.Equal(ConfigurationSource.Explicit, ((IConventionModel)model).GetServiceTierSqlConfigurationSource()); - model.SetServiceTier(null); + model.SetServiceTierSql(null); - Assert.Null(model.GetServiceTier()); - Assert.Null(((IConventionModel)model).GetServiceTierConfigurationSource()); + Assert.Null(model.GetServiceTierSql()); + Assert.Null(((IConventionModel)model).GetServiceTierSqlConfigurationSource()); } [ConditionalFact] @@ -74,23 +74,23 @@ public void Can_get_and_set_PerformanceLevel() var model = modelBuilder .Model; - Assert.Null(model.GetPerformanceLevel()); - Assert.Null(((IConventionModel)model).GetPerformanceLevelConfigurationSource()); + Assert.Null(model.GetPerformanceLevelSql()); + Assert.Null(((IConventionModel)model).GetPerformanceLevelSqlConfigurationSource()); - ((IConventionModel)model).SetPerformanceLevel("S0", fromDataAnnotation: true); + ((IConventionModel)model).SetPerformanceLevelSql("S0", fromDataAnnotation: true); - Assert.Equal("S0", model.GetPerformanceLevel()); - Assert.Equal(ConfigurationSource.DataAnnotation, ((IConventionModel)model).GetPerformanceLevelConfigurationSource()); + Assert.Equal("S0", model.GetPerformanceLevelSql()); + Assert.Equal(ConfigurationSource.DataAnnotation, ((IConventionModel)model).GetPerformanceLevelSqlConfigurationSource()); - model.SetPerformanceLevel("ELASTIC_POOL (name = elastic_pool)"); + model.SetPerformanceLevelSql("ELASTIC_POOL (name = elastic_pool)"); - Assert.Equal("ELASTIC_POOL (name = elastic_pool)", model.GetPerformanceLevel()); - Assert.Equal(ConfigurationSource.Explicit, ((IConventionModel)model).GetPerformanceLevelConfigurationSource()); + Assert.Equal("ELASTIC_POOL (name = elastic_pool)", model.GetPerformanceLevelSql()); + Assert.Equal(ConfigurationSource.Explicit, ((IConventionModel)model).GetPerformanceLevelSqlConfigurationSource()); - model.SetPerformanceLevel(null); + model.SetPerformanceLevelSql(null); - Assert.Null(model.GetPerformanceLevel()); - Assert.Null(((IConventionModel)model).GetPerformanceLevelConfigurationSource()); + Assert.Null(model.GetPerformanceLevelSql()); + Assert.Null(((IConventionModel)model).GetPerformanceLevelSqlConfigurationSource()); } [ConditionalFact] diff --git a/test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs b/test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs index e84c73519de..469bd760643 100644 --- a/test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs +++ b/test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs @@ -28,9 +28,9 @@ public void Alter_database_edition_options() Execute( _ => { }, source => source.HasDatabaseMaxSize("100 MB") - .HasPerformanceLevel("'S0'"), + .HasPerformanceLevel("S0"), target => target - .HasServiceTier("'basic'"), + .HasServiceTier("basic"), upOps => { Assert.Equal(1, upOps.Count);