public void Principal_missing_primary_key() { using (var testStore = SqliteTestStore.GetOrCreateShared("NoPrincipalPk" + DbSuffix)) { testStore.ExecuteNonQuery(@"CREATE TABLE IF NOT EXISTS Dependent ( Id PRIMARY KEY, PrincipalId INT, FOREIGN KEY (PrincipalId) REFERENCES Principal(Id) ); CREATE TABLE IF NOT EXISTS Principal ( Id INT);"); var results = Generator.Generate( testStore.ConnectionString, Enumerable.Empty <string>(), Enumerable.Empty <string>(), TestProjectPath, outputPath: null, rootNamespace: "E2E.Sqlite", contextName: null, useDataAnnotations: UseDataAnnotations, overwriteFiles: false, useDatabaseNames: false); Assert.Contains("warn: " + DesignStrings.MissingPrimaryKey("Principal"), _reporter.Messages); Assert.Contains("warn: " + DesignStrings.UnableToGenerateEntityType("Principal"), _reporter.Messages); Assert.Contains("warn: " + DesignStrings.ForeignKeyScaffoldErrorPrincipalTableScaffoldingError("Dependent(PrincipalId)", "Principal"), _reporter.Messages); var expectedFileSet = new FileSet(new FileSystemFileService(), Path.Combine(ExpectedResultsParentDir, "NoPrincipalPk")) { Files = { "NoPrincipalPk" + DbSuffix + "Context.cs", "Dependent.cs" } }; var actualFileSet = new FileSet(InMemoryFiles, TestProjectFullPath) { Files = Enumerable.Repeat(results.ContextFile, 1).Concat(results.EntityTypeFiles).Select(Path.GetFileName).ToList() }; AssertEqualFileContents(expectedFileSet, actualFileSet); AssertCompile(actualFileSet); } }
public void E2ETest_UseAttributesInsteadOfFluentApi() { var filePaths = Generator.Generate( _connectionString, Tables, Enumerable.Empty <string>(), TestProjectDir + Path.DirectorySeparatorChar, // tests that ending DirectorySeparatorChar does not affect namespace TestSubDir, TestNamespace, contextName: "AttributesContext", useDataAnnotations: true, overwriteFiles: false, useDatabaseNames: false); var actualFileSet = new FileSet(InMemoryFiles, Path.GetFullPath(Path.Combine(TestProjectDir, TestSubDir))) { Files = Enumerable.Repeat(filePaths.ContextFile, 1).Concat(filePaths.EntityTypeFiles).Select(Path.GetFileName).ToList() }; var expectedFileSet = new FileSet(new FileSystemFileService(), Path.Combine("ReverseEngineering", "Expected", "Attributes"), contents => contents.Replace("{{connectionString}}", _connectionString)) { Files = new List <string> { "AttributesContext.cs" } .Concat(_expectedEntityTypeFiles).ToList() }; Assert.Contains(_reporter.Messages, m => m.StartsWith("warn: ") && m.Contains("PK__Filtered__")); Assert.Contains("warn: " + DesignStrings.CannotFindTypeMappingForColumn("dbo.AllDataTypes.geographyColumn", "geography"), _reporter.Messages); Assert.Contains("warn: " + DesignStrings.CannotFindTypeMappingForColumn("dbo.AllDataTypes.geometryColumn", "geometry"), _reporter.Messages); Assert.Contains("warn: " + DesignStrings.CannotFindTypeMappingForColumn("dbo.AllDataTypes.hierarchyidColumn", "hierarchyid"), _reporter.Messages); Assert.Contains("warn: " + DesignStrings.CannotFindTypeMappingForColumn("dbo.AllDataTypes.sql_variantColumn", "sql_variant"), _reporter.Messages); Assert.Contains("warn: " + DesignStrings.UnableToScaffoldIndexMissingProperty("IX_UnscaffoldableIndex", "sql_variantColumn,hierarchyidColumn"), _reporter.Messages); Assert.Contains("warn: " + DesignStrings.CannotFindTypeMappingForColumn("dbo.TableWithUnmappablePrimaryKeyColumn.TableWithUnmappablePrimaryKeyColumnID", "hierarchyid"), _reporter.Messages); Assert.Contains("warn: " + DesignStrings.PrimaryKeyErrorPropertyNotFound("dbo.TableWithUnmappablePrimaryKeyColumn", "TableWithUnmappablePrimaryKeyColumnID"), _reporter.Messages); Assert.Contains("warn: " + DesignStrings.UnableToGenerateEntityType("dbo.TableWithUnmappablePrimaryKeyColumn"), _reporter.Messages); Assert.Equal(9, _reporter.Messages.Count(m => m.StartsWith("warn: "))); AssertEqualFileContents(expectedFileSet, actualFileSet); AssertCompile(actualFileSet); }
public void Self_referencing() { using (var testStore = SqliteTestStore.GetOrCreateShared("SelfRef" + DbSuffix)) { testStore.ExecuteNonQuery(@"CREATE TABLE IF NOT EXISTS SelfRef ( Id INTEGER PRIMARY KEY, SelfForeignKey INTEGER, FOREIGN KEY (SelfForeignKey) REFERENCES SelfRef (Id) );"); var results = Generator.Generate( testStore.ConnectionString, Enumerable.Empty <string>(), Enumerable.Empty <string>(), TestProjectPath, outputPath: null, rootNamespace: "E2E.Sqlite", contextName: null, useDataAnnotations: UseDataAnnotations, overwriteFiles: false, useDatabaseNames: false); Assert.Empty(_reporter.Messages.Where(m => m.StartsWith("warn: "))); var expectedFileSet = new FileSet(new FileSystemFileService(), Path.Combine(ExpectedResultsParentDir, "SelfRef")) { Files = { "SelfRef" + DbSuffix + "Context.cs", "SelfRef.cs" } }; var actualFileSet = new FileSet(InMemoryFiles, TestProjectFullPath) { Files = Enumerable.Repeat(results.ContextFile, 1).Concat(results.EntityTypeFiles).Select(Path.GetFileName).ToList() }; AssertEqualFileContents(expectedFileSet, actualFileSet); AssertCompile(actualFileSet); } }
public void Sequences() { using (var scratch = SqlServerTestStore.Create("SqlServerE2E")) { scratch.ExecuteNonQuery(@" CREATE SEQUENCE CountByTwo START WITH 1 INCREMENT BY 2; CREATE SEQUENCE CyclicalCountByThree START WITH 6 INCREMENT BY 3 MAXVALUE 27 MINVALUE 0 CYCLE; CREATE SEQUENCE TinyIntSequence AS tinyint START WITH 1; CREATE SEQUENCE SmallIntSequence AS smallint START WITH 1; CREATE SEQUENCE IntSequence AS int START WITH 1; CREATE SEQUENCE DecimalSequence AS decimal; CREATE SEQUENCE NumericSequence AS numeric;"); var expectedFileSet = new FileSet( new FileSystemFileService(), Path.Combine("ReverseEngineering", "Expected"), contents => contents.Replace("{{connectionString}}", scratch.ConnectionString)) { Files = new List <string> { "SequenceContext.cs" } }; var filePaths = Generator.Generate( scratch.ConnectionString, Enumerable.Empty <string>(), Enumerable.Empty <string>(), TestProjectDir + Path.DirectorySeparatorChar, outputPath: null, // not used for this test rootNamespace: TestNamespace, contextName: "SequenceContext", useDataAnnotations: false, overwriteFiles: false, useDatabaseNames: false); var actualFileSet = new FileSet(InMemoryFiles, Path.GetFullPath(TestProjectDir)) { Files = new[] { filePaths.ContextFile }.Concat(filePaths.EntityTypeFiles).Select(Path.GetFileName).ToList() }; Assert.Contains("warn: " + DesignStrings.BadSequenceType("DecimalSequence", "decimal"), _reporter.Messages); Assert.Contains("warn: " + DesignStrings.BadSequenceType("NumericSequence", "numeric"), _reporter.Messages); Assert.Equal(2, _reporter.Messages.Count(m => m.StartsWith("warn: "))); AssertEqualFileContents(expectedFileSet, actualFileSet); AssertCompile(actualFileSet); } }