public void ValidateContextNameInReverseEngineerGenerator(string contextName) { var cSharpUtilities = new CSharpUtilities(); var fileService = new InMemoryTemplateFileService(); var dbContextTemplateService = new HbsDbContextTemplateService(fileService); var entityTypeTemplateService = new HbsEntityTypeTemplateService(fileService); var reverseEngineer = new ReverseEngineerScaffolder( new FakeDatabaseModelFactory(), new FakeScaffoldingModelFactory(new TestOperationReporter()), new HbsCSharpScaffoldingGenerator( fileService, dbContextTemplateService, entityTypeTemplateService, new HbsCSharpDbContextGenerator( new FakeScaffoldingProviderCodeGenerator(), new FakeAnnotationCodeGenerator(), cSharpUtilities, new HbsDbContextTemplateService(fileService)), new HbsCSharpEntityTypeGenerator( cSharpUtilities, new HbsEntityTypeTemplateService(fileService))), cSharpUtilities); Assert.Equal( DesignStrings.ContextClassNotValidCSharpIdentifier(contextName), Assert.Throws <ArgumentException>( () => reverseEngineer.Generate( connectionString: "connectionstring", tables: Enumerable.Empty <string>(), schemas: Enumerable.Empty <string>(), projectPath: "FakeProjectPath", outputPath: null, rootNamespace: "FakeNamespace", contextName: contextName, useDataAnnotations: false, overwriteFiles: false, useDatabaseNames: false)) .Message); }
private Dictionary <string, string> ReverseEngineerFiles(ReverseEngineerOptions options, bool useDataAnnotations) { var fileService = new InMemoryTemplateFileService(); fileService.InputFiles(ContextClassTemplate, ContextImportsTemplate, ContextDbSetsTemplate, EntityClassTemplate, EntityImportsTemplate, EntityCtorTemplate, EntityPropertiesTemplate); var dbContextTemplateService = new HbsDbContextTemplateService(fileService); var entityTypeTemplateService = new HbsEntityTypeTemplateService(fileService); ICSharpUtilities cSharpUtilities = new CSharpUtilities(); ICSharpDbContextGenerator realContextGenerator = new HbsCSharpDbContextGenerator( new SqlServerScaffoldingCodeGenerator(), new SqlServerAnnotationCodeGenerator(new AnnotationCodeGeneratorDependencies()), cSharpUtilities, new HbsDbContextTemplateService(fileService)); ICSharpDbContextGenerator contextGenerator = options == ReverseEngineerOptions.DbContextOnly || options == ReverseEngineerOptions.DbContextOnly ? realContextGenerator : new NullCSharpDbContextGenerator(); ICSharpEntityTypeGenerator realEntityGenerator = new HbsCSharpEntityTypeGenerator( cSharpUtilities, new HbsEntityTypeTemplateService(fileService)); ICSharpEntityTypeGenerator entityGenerator = options == ReverseEngineerOptions.EntitiesOnly || options == ReverseEngineerOptions.DbContextAndEntities ? realEntityGenerator : new NullCSharpEntityTypeGenerator(); IScaffoldingCodeGenerator scaffoldingGenerator = new HbsCSharpScaffoldingGenerator( fileService, dbContextTemplateService, entityTypeTemplateService, contextGenerator, entityGenerator); var modelFactory = new SqlServerDatabaseModelFactory( new DiagnosticsLogger <DbLoggerCategory.Scaffolding>( new TestSqlLoggerFactory(), new LoggingOptions(), new DiagnosticListener("Fake"))); var reverseEngineer = new ReverseEngineerScaffolder( modelFactory, new FakeScaffoldingModelFactory(new TestOperationReporter()), scaffoldingGenerator, cSharpUtilities); // Act var files = reverseEngineer.Generate( connectionString: Constants.Connections.SqlServerConnection, tables: Enumerable.Empty <string>(), schemas: Enumerable.Empty <string>(), projectPath: Constants.Parameters.ProjectPath, outputPath: null, rootNamespace: Constants.Parameters.RootNamespace, contextName: Constants.Parameters.ContextName, useDataAnnotations: useDataAnnotations, overwriteFiles: false, useDatabaseNames: false); var generatedFiles = new Dictionary <string, string>(); if (options == ReverseEngineerOptions.DbContextOnly || options == ReverseEngineerOptions.DbContextAndEntities) { var contextPath = files.ContextFile; var context = fileService.RetrieveTemplateFileContents( Path.GetDirectoryName(contextPath), Path.GetFileName(contextPath)); generatedFiles.Add(Constants.Files.DbContextFile, context); } if (options == ReverseEngineerOptions.EntitiesOnly || options == ReverseEngineerOptions.DbContextAndEntities) { var categoryPath = files.EntityTypeFiles[0]; var category = fileService.RetrieveTemplateFileContents( Path.GetDirectoryName(categoryPath), Path.GetFileName(categoryPath)); var productPath = files.EntityTypeFiles[1]; var product = fileService.RetrieveTemplateFileContents( Path.GetDirectoryName(productPath), Path.GetFileName(productPath)); generatedFiles.Add(Constants.Files.CategoryFile, category); generatedFiles.Add(Constants.Files.ProductFile, product); } return(generatedFiles); }