public async Task BuildAliasTablesResultSetListForAllEnvironments_ResultsFound_ReturnsCorrectNumberOfRows() { // Arrange _db2QueryHelper.Setup(x => x.GetAliasTableDetailsWithinWhitelistedDatabaseNamesToMatch( It.IsAny <string>(), It.IsAny <List <string> >(), It.IsAny <List <string> >())) // Return the actual value from this method - no need to mock it. .Returns(_db2QueryHelperConcrete.GetAliasTableDetailsWithinWhitelistedDatabaseNamesToMatch( "main.TestSchemaTableModel", _listSchemaTables.Where(t => t.TYPE == RelevantTableTypes[0]).Select(t => t.NAME).ToList(), new List <string> { MatchingDatabase1String })); var dbSchemaScrapeAccess = new Db2SchemaScrapeAccess(_logger.Object, _dbConnection.Object, _db2QueryHelper.Object); // This is the return collection var returnAliasTableCollection = _listSchemaTables .Select(x => new SchemaTableModel { Type = x.TYPE, AliasTableLocation = x.LOCATION, Name = x.NAME, AliasTableName = x.NAME, AliasTableEnvironment = MatchingAliasCreatorString, DatabaseName = x.DBNAME }) .ToList(); try { // Act await dbSchemaScrapeAccess.BuildAliasTablesResultSetListForAllEnvironments( MatchingLocationString, new List <string> { MatchingDatabase1String }, returnAliasTableCollection, _testInMemoryDatabase.OpenConnection(), string.Empty); } catch (Exception e) { Console.WriteLine(e); throw; } // Assert returnAliasTableCollection.First().SchemaColumns.Count.Should().Be(1); }
public Db2SchemaScrapeAccessTests() { _logger = new Mock <ILoggerAdapter <Db2SchemaScrapeAccess> >(); _dbConnection = new Mock <IDbConnectionManager <Db2Context> >(); _db2QueryHelper = new Mock <IDb2QueryHelper>(); // Using a SQL Lite in-memory database to test the DbContext. _testInMemoryDatabase = new TestInMemoryDatabase(); _testInMemoryDatabase.Insert(_listSchemaTables); _testInMemoryDatabase.Insert(_listSchemaColumns); _dbConnection.Setup(c => c.GetDbConnectionFromContextAsync()).ReturnsAsync(_testInMemoryDatabase.OpenConnection()); // Arrange setup of the common Db2QueryHelper methods. _db2QueryHelper.Setup(x => x.GetDb2SysTablesName(It.IsAny <string>())) // Name of SqlLite in-memory database .Returns("main.TestSchemaTableModel"); _db2QueryHelper.Setup(x => x.GetDb2SysColumnsName(It.IsAny <string>())) // Name of SqlLite in-memory database .Returns("main.TestSchemaColumnModel"); _db2QueryHelper.Setup(x => x.GetColumnDetailsForEnvironmentQueryFormatted( "main.TestSchemaColumnModel")) // Return the actual value from this method - no need to mock it. .Returns(_db2QueryHelperConcrete.GetColumnDetailsForEnvironmentQueryFormatted( "main.TestSchemaColumnModel")); }
public async Task BuildAliasTablesResultSetListForAllEnvironments_PhysicalTableExistsInEnvironmentWithSameNameAsAliasTable_MessageLoggedAndPhysicalPreferred() { // Arrange _db2QueryHelper.Setup(x => x.GetAliasTableDetailsWithinWhitelistedDatabaseNamesToMatch( It.IsAny <string>(), It.IsAny <List <string> >(), It.IsAny <List <string> >())) // Return the actual value from this method - no need to mock it. .Returns(_db2QueryHelperConcrete.GetAliasTableDetailsWithinWhitelistedDatabaseNamesToMatch( "main.TestSchemaTableModel", _listSchemaTables.Where(t => t.TYPE == RelevantTableTypes[0]).Select(t => t.NAME).ToList(), new List <string> { MatchingDatabase1String })); // Insert another table with the same name into the in-memory database as the Alias table to act as the 'Physical' table. var newTestInMemoryDatabase = new TestInMemoryDatabase(); _listSchemaTables.Add(new TestSchemaTableModel { Id = 0, NAME = "ALIASTABLE1", DBNAME = MatchingDatabase1String, // This is type = 'T' for physical Table. TYPE = RelevantTableTypes[1], CREATOR = MatchingCreatorString }); // Insert a column into this physical table. _listSchemaColumns.Add(new TestSchemaColumnModel { Id = 100, NAME = "COLUMN1", TBNAME = "ALIASTABLE1", COLNO = "1", KEYSEQ = "1", LENGTH = "1", COLTYPE = "1", NULLS = "0", DEFAULT = "0", SCALE = "0", TBCREATOR = MatchingCreatorString }); newTestInMemoryDatabase.Insert(_listSchemaTables); newTestInMemoryDatabase.Insert(_listSchemaColumns); var dbSchemaScrapeAccess = new Db2SchemaScrapeAccess(_logger.Object, _dbConnection.Object, _db2QueryHelper.Object); // This is the return collection var returnAliasTableCollection = _listSchemaTables .Select(x => new SchemaTableModel { Type = x.TYPE, AliasTableLocation = x.LOCATION, Name = x.NAME, AliasTableName = x.NAME, AliasTableEnvironment = MatchingCreatorString, DatabaseName = x.DBNAME, SchemaColumns = new List <SchemaColumnModel> { new SchemaColumnModel { Name = "" } } }) .ToList(); try { // Act await dbSchemaScrapeAccess.BuildAliasTablesResultSetListForAllEnvironments( MatchingLocationString, new List <string> { MatchingDatabase1String }, returnAliasTableCollection, newTestInMemoryDatabase.OpenConnection(), string.Empty); } catch (Exception e) { Console.WriteLine(e); throw; } // Assert _logger.Verify(x => x.LogInformation( It.Is <string>(s => s.Contains("A physical Table with existing Columns was found in the original TablesResultSetMasterList")), It.IsAny <string>(), It.IsAny <string>()), Times.Once); }