public void ScaffoldModel_works_with_overridden_connection_string() { var resolver = new TestNamedConnectionStringResolver("Data Source=Test"); var databaseModelFactory = new TestDatabaseModelFactory(); databaseModelFactory.ScaffoldedConnectionString = "Data Source=ScaffoldedConnectionString"; var scaffolder = new DesignTimeServicesBuilder( typeof(ReverseEngineerScaffolderTest).Assembly, typeof(ReverseEngineerScaffolderTest).Assembly, new TestOperationReporter(), new string[0]) .CreateServiceCollection("Microsoft.EntityFrameworkCore.SqlServer") .AddSingleton <INamedConnectionStringResolver>(resolver) .AddScoped <IDatabaseModelFactory>(p => databaseModelFactory) .BuildServiceProvider(validateScopes: true) .CreateScope() .ServiceProvider .GetRequiredService <IReverseEngineerScaffolder>(); var result = scaffolder.ScaffoldModel( "Name=DefaultConnection", new DatabaseModelFactoryOptions(), new ModelReverseEngineerOptions(), new ModelCodeGenerationOptions { ModelNamespace = "Foo" }); Assert.Contains("Data Source=ScaffoldedConnectionString", result.ContextFile.Code); Assert.DoesNotContain("Name=DefaultConnection", result.ContextFile.Code); Assert.DoesNotContain("Data Source=Test", result.ContextFile.Code); }
public void ScaffoldModel_works_with_named_connection_string() { var resolver = new TestNamedConnectionStringResolver("Data Source=Test"); var databaseModelFactory = new TestDatabaseModelFactory(); var scaffolder = new ServiceCollection() .AddEntityFrameworkDesignTimeServices() .AddSingleton <INamedConnectionStringResolver>(resolver) .AddSingleton <IDatabaseModelFactory>(databaseModelFactory) .AddSingleton <IRelationalTypeMappingSource, TestRelationalTypeMappingSource>() .AddSingleton <LoggingDefinitions, TestRelationalLoggingDefinitions>() .AddSingleton <IProviderConfigurationCodeGenerator, TestProviderCodeGenerator>() .AddSingleton <IAnnotationCodeGenerator, AnnotationCodeGenerator>() .BuildServiceProvider() .GetRequiredService <IReverseEngineerScaffolder>(); var result = scaffolder.ScaffoldModel( "Name=DefaultConnection", new DatabaseModelFactoryOptions(), new ModelReverseEngineerOptions(), new ModelCodeGenerationOptions()); Assert.Equal("Data Source=Test", databaseModelFactory.ConnectionString); Assert.Contains("Name=DefaultConnection", result.ContextFile.Code); Assert.DoesNotContain("Data Source=Test", result.ContextFile.Code); Assert.DoesNotContain("#warning", result.ContextFile.Code); }
public void ScaffoldModel_works_with_named_connection_string() { var resolver = new TestNamedConnectionStringResolver("Data Source=Test"); var databaseModelFactory = new TestDatabaseModelFactory(); var scaffolder = new DesignTimeServicesBuilder( typeof(ReverseEngineerScaffolderTest).Assembly, typeof(ReverseEngineerScaffolderTest).Assembly, new TestOperationReporter(), new string[0]) .CreateServiceCollection(SqlServerTestHelpers.Instance.CreateContext()) .AddSingleton <INamedConnectionStringResolver>(resolver) .AddSingleton <IDatabaseModelFactory>(databaseModelFactory) .BuildServiceProvider() .GetRequiredService <IReverseEngineerScaffolder>(); var result = scaffolder.ScaffoldModel( "Name=DefaultConnection", new DatabaseModelFactoryOptions(), new ModelReverseEngineerOptions(), new ModelCodeGenerationOptions { ModelNamespace = "Foo" }); Assert.Equal("Data Source=Test", databaseModelFactory.ConnectionString); Assert.Contains("Name=DefaultConnection", result.ContextFile.Code); Assert.DoesNotContain("Data Source=Test", result.ContextFile.Code); Assert.DoesNotContain("#warning", result.ContextFile.Code); }