protected virtual void AssertLog(LoggerMessages expected) { AssertLoggerMessages(expected.Warn, _logger.Messages.Warn, "WARNING"); AssertLoggerMessages(expected.Error, _logger.Messages.Error, "ERROR"); AssertLoggerMessages(expected.Info, _logger.Messages.Info, "INFO"); }
public async void Principal_missing_primary_key() { using (var testStore = SqliteTestStore.GetOrCreateShared("NoPrincipal").AsTransient()) { testStore.ExecuteNonQuery(@"CREATE TABLE Dependent ( Id PRIMARY KEY, PrincipalId INT, FOREIGN KEY (PrincipalId) REFERENCES Principal(Id) ); CREATE TABLE Principal ( Id INT);"); testStore.Transaction.Commit(); var results = await Generator.GenerateAsync(new ReverseEngineeringConfiguration { Provider = MetadataModelProvider, ConnectionString = testStore.Connection.ConnectionString, Namespace = "E2E.Sqlite", OutputPath = "testout" }); var expectedLog = new LoggerMessages { Warn = { Strings.MissingPrimaryKey("Principal"), Strings.ForeignKeyScaffoldError("Dependent","PrincipalId"), } }; AssertLog(expectedLog); var expectedFileSet = new FileSet(new FileSystemFileService(), "ReverseEngineering/Expected/NoPrincipalPk") { Files = { "ModelContext.expected", "Dependent.expected", "Principal.expected", } }; var actualFileSet = new FileSet(InMemoryFiles, "testout") { Files = results.Select(Path.GetFileName).ToList() }; AssertEqualFileContents(expectedFileSet, actualFileSet); AssertCompile(actualFileSet); } }
public async void It_uses_templates() { var dbContextFileName = "EntityFramework.Sqlite.Design." + ReverseEngineeringGenerator.DbContextTemplateFileName; var entityTypeFileName = "EntityFramework.Sqlite.Design." + ReverseEngineeringGenerator.EntityTypeTemplateFileName; var entityTemplate = "This is an entity type template! (For real)"; var contextTemplate = "Also a 100% legit template"; var outputDir = "gen"; var templatesDir = "templates"; using (var testStore = SqliteTestStore.CreateScratch()) { testStore.ExecuteNonQuery("CREATE TABLE RealMccoy ( Col1 text PRIMARY KEY); "); InMemoryFiles.OutputFile(templatesDir, dbContextFileName, contextTemplate); InMemoryFiles.OutputFile(templatesDir, entityTypeFileName, entityTemplate); var config = new ReverseEngineeringConfiguration { ConnectionString = testStore.Connection.ConnectionString, Provider = MetadataModelProvider, Namespace = "Test", OutputPath = outputDir, CustomTemplatePath = templatesDir }; var filePaths = await Generator.GenerateAsync(config); var expectedLog = new LoggerMessages { Info = { "Using custom template " + Path.Combine(templatesDir, dbContextFileName), "Using custom template " + Path.Combine(templatesDir, entityTypeFileName) } }; AssertLog(expectedLog); Assert.Equal(2, filePaths.Count); foreach (var fileName in filePaths.Select(Path.GetFileName)) { var fileContents = InMemoryFiles.RetrieveFileContents(outputDir, fileName); var contents = fileName.EndsWith("Context.cs") ? contextTemplate : entityTemplate; Assert.Equal(contents, fileContents); } } }
public async void Missing_primary_key() { using (var testStore = SqliteTestStore.CreateScratch()) { testStore.ExecuteNonQuery("CREATE TABLE Alicia ( Keys TEXT );"); var results = await Generator.GenerateAsync(new ReverseEngineeringConfiguration { Provider = MetadataModelProvider, ConnectionString = testStore.Connection.ConnectionString, Namespace = "E2E.Sqlite", OutputPath = "testout" }); var errorMessage = Strings.MissingPrimaryKey("Alicia"); var expectedLog = new LoggerMessages { Warn = { errorMessage } }; AssertLog(expectedLog); Assert.Contains(errorMessage, InMemoryFiles.RetrieveFileContents("testout", "Alicia.cs")); } }
public async void Principal_missing_primary_key() { using (var testStore = SqliteTestStore.GetOrCreateShared("NoPrincipalPk" + DbSuffix).AsTransient()) { testStore.ExecuteNonQuery(@"CREATE TABLE Dependent ( Id PRIMARY KEY, PrincipalId INT, FOREIGN KEY (PrincipalId) REFERENCES Principal(Id) ); CREATE TABLE Principal ( Id INT);"); testStore.Transaction.Commit(); var results = await Generator.GenerateAsync(new ReverseEngineeringConfiguration { ConnectionString = testStore.Connection.ConnectionString, ProjectPath = "testout", ProjectRootNamespace = "E2E.Sqlite", UseFluentApiOnly = UseFluentApiOnly, TableSelectionSet = TableSelectionSet.All }); var expectedLog = new LoggerMessages { Warn = { RelationalDesignStrings.MissingPrimaryKey("Principal"), RelationalDesignStrings.UnableToGenerateEntityType("Principal"), RelationalDesignStrings.ForeignKeyScaffoldErrorPrincipalTableScaffoldingError("Dependent(PrincipalId)", "Principal") } }; AssertLog(expectedLog); var expectedFileSet = new FileSet(new FileSystemFileService(), Path.Combine(ExpectedResultsParentDir, "NoPrincipalPk")) { Files = { "NoPrincipalPk" + DbSuffix + "Context.expected", "Dependent.expected", } }; var actualFileSet = new FileSet(InMemoryFiles, "testout") { Files = Enumerable.Repeat(results.ContextFile, 1).Concat(results.EntityTypeFiles).Select(Path.GetFileName).ToList() }; AssertEqualFileContents(expectedFileSet, actualFileSet); AssertCompile(actualFileSet); } }
public async void Missing_primary_key() { using (var testStore = SqliteTestStore.CreateScratch()) { testStore.ExecuteNonQuery("CREATE TABLE Alicia ( Keys TEXT );"); var results = await Generator.GenerateAsync(new ReverseEngineeringConfiguration { ConnectionString = testStore.Connection.ConnectionString, ProjectPath = "testout", ProjectRootNamespace = "E2E.Sqlite", UseFluentApiOnly = UseFluentApiOnly, TableSelectionSet = TableSelectionSet.All }); var errorMessage = RelationalDesignStrings.UnableToGenerateEntityType("Alicia"); var expectedLog = new LoggerMessages { Warn = { RelationalDesignStrings.MissingPrimaryKey("Alicia"), errorMessage, } }; AssertLog(expectedLog); Assert.Contains(errorMessage, InMemoryFiles.RetrieveFileContents("testout", Path.GetFileName(results.ContextFile))); } }
protected virtual void AssertLog(LoggerMessages expected) { Assert.Equal(expected.Warn, _logger.Messages.Warn); Assert.Equal(expected.Info, _logger.Messages.Info); Assert.Equal(expected.Verbose, _logger.Messages.Verbose); }
protected virtual void AssertLog(LoggerMessages expected) { AssertLoggerMessages(expected.Warn, _logger.Messages.Warn, "WARNING"); AssertLoggerMessages(expected.Error, _logger.Messages.Error, "ERROR"); AssertLoggerMessages(expected.Info, _logger.Messages.Info, "INFO"); }