Exemplo n.º 1
0
 protected virtual void AssertLog(LoggerMessages expected)
 {
     AssertLoggerMessages(expected.Error, _reporter.Messages.Error, "ERROR");
     AssertLoggerMessages(expected.Warn, _reporter.Messages.Warn, "WARNING");
     AssertLoggerMessages(expected.Info, _reporter.Messages.Info, "INFO");
     AssertLoggerMessages(expected.Debug, _reporter.Messages.Info, "DEBUG");
 }
Exemplo n.º 2
0
        public async void Principal_missing_primary_key()
        {
            using (var testStore = SqliteTestStore.GetOrCreateShared("NoPrincipalPk" + DbSuffix).AsTransient())
            {
                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);");
                testStore.Transaction.Commit();

                var results = await Generator.GenerateAsync(new ReverseEngineeringConfiguration
                {
                    ConnectionString = testStore.ConnectionString,
                    ProjectPath = TestProjectPath,
                    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, TestProjectFullPath)
                {
                    Files = Enumerable.Repeat(results.ContextFile, 1).Concat(results.EntityTypeFiles).Select(Path.GetFileName).ToList()
                };
                AssertEqualFileContents(expectedFileSet, actualFileSet);
                AssertCompile(actualFileSet);
            }
        }
Exemplo n.º 3
0
 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");
 }
Exemplo n.º 4
0
        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.ConnectionString,
                    ProjectPath = TestProjectPath,
                    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(TestProjectFullPath, Path.GetFileName(results.ContextFile)));
            }
        }