Example #1
0
        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);
        }
Example #2
0
        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);
        }