public async Task GetDatabasesByCreatorAsync__RequiredParamsNotSupplied_ThrowsAppropriateError(string creatorString, string locationString) { // Arrange var dbSchemaScrapeAccess = new Db2SchemaScrapeAccess(_logger.Object, _dbConnection.Object, _db2QueryHelper.Object); // Act + Assert await Assert.ThrowsAsync <KeyNotFoundException>(async() => await dbSchemaScrapeAccess.GetDatabasesByCreatorAsync( creatorString, locationString, new List <string>())); }
public async Task GetDatabasesByCreatorAsync_CorrectMatchingDatabaseNameSupplied_ReturnsCorrectNumberOfRows() { // Arrange var concreteWhitelistDatabaseNames = _db2QueryHelperConcrete.WhitelistDatabaseNamesToBeIngestedInSchemaAppendFilter( new List <string> { MatchingDatabase1String }, SharedConstants.Db2SchemaScrape.Db2SystemDatabaseNameOfAliasTables); _db2QueryHelper.Setup(x => x.WhitelistDatabaseNamesToBeIngestedInSchemaAppendFilter( It.IsAny <List <string> >(), SharedConstants.Db2SchemaScrape.Db2SystemDatabaseNameOfAliasTables)) .Returns(concreteWhitelistDatabaseNames); _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 })); _db2QueryHelper.Setup(x => x.GetTableDetailsForEnvironmentQueryFormatted( "main.TestSchemaTableModel", concreteWhitelistDatabaseNames, string.Empty)) // Return the actual value from this method - no need to mock it. .Returns(_db2QueryHelperConcrete.GetTableDetailsForEnvironmentQueryFormatted( "main.TestSchemaTableModel", concreteWhitelistDatabaseNames, string.Empty)); var schemaTablesThatMatchOurQuery = _listSchemaTables .Where(x => x.CREATOR == MatchingCreatorString && RelevantTableTypes.Contains(x.TYPE)); var dbSchemaScrapeAccess = new Db2SchemaScrapeAccess(_logger.Object, _dbConnection.Object, _db2QueryHelper.Object); // Act var result = await dbSchemaScrapeAccess.GetDatabasesByCreatorAsync( MatchingCreatorString, MatchingLocationString, new List <string> { MatchingDatabase1String }); // Assert // There are multiple results loaded that match, but they have the same DBNAME, so should only be 1 distinct Database result returned. result.As <List <SchemaDatabaseModel> >().Should().Equals(schemaTablesThatMatchOurQuery.Select(x => x.DBNAME).Distinct()); }
public async Task GetDatabasesByCreatorAsync_InCorrectMatchingDatabaseNameSupplied_ReturnsZeroRows() { // Arrange var concreteWhitelistDatabaseNames = _db2QueryHelperConcrete.WhitelistDatabaseNamesToBeIngestedInSchemaAppendFilter( new List <string> { DatabaseNameNotInOurInternalDataSet }, SharedConstants.Db2SchemaScrape.Db2SystemDatabaseNameOfAliasTables); _db2QueryHelper.Setup(x => x.WhitelistDatabaseNamesToBeIngestedInSchemaAppendFilter( It.IsAny <List <string> >(), SharedConstants.Db2SchemaScrape.Db2SystemDatabaseNameOfAliasTables)) .Returns(concreteWhitelistDatabaseNames); _db2QueryHelper.Setup(x => x.GetTableDetailsForEnvironmentQueryFormatted( "main.TestSchemaTableModel", concreteWhitelistDatabaseNames, string.Empty)) // Return the actual value from this method - no need to mock it. .Returns(_db2QueryHelperConcrete.GetTableDetailsForEnvironmentQueryFormatted( "main.TestSchemaTableModel", concreteWhitelistDatabaseNames, string.Empty)); var dbSchemaScrapeAccess = new Db2SchemaScrapeAccess(_logger.Object, _dbConnection.Object, _db2QueryHelper.Object); // Act var result = await dbSchemaScrapeAccess.GetDatabasesByCreatorAsync( MatchingCreatorString, MatchingLocationString, new List <string> { DatabaseNameNotInOurInternalDataSet }); // Assert // AS we are using a Database name not in our test dataset, should be 0 results. result.As <List <SchemaDatabaseModel> >().Count.Should().Be(0); }