private TSqlModel CreateFilteredModel(SchemaBasedFilter schemaFilter, TSqlModel model) { ModelFilterer modelFilterer = new ModelFilterer(schemaFilter); TSqlModel filteredModel = modelFilterer.CreateFilteredModel(model); _trash.Add(filteredModel); return filteredModel; }
public void TestValidationErrorsIfExcludeReferencedSchema() { // Given a set of scripts with "dev", "test" and "production" filters var model = CreateTestModel(); // When filtering to only incude "test" filters var schemaFilter = new SchemaBasedFilter("test"); schemaFilter.Filtering = SchemaBasedFilter.FilterType.Include; var filteredModel = CreateFilteredModel(schemaFilter, model); // Then expect validation of the model to fail since "test" objects depend on elements in the "prod" schema IList<DacModelMessage> validationResults = filteredModel.Validate(); Assert.IsTrue(validationResults.Any(message => message.MessageType == DacMessageType.Error), "Expect validation errors"); }
public void TestSchemaFilterIncludingSchemas() { // Given a model with objects that use "dev", "test" and "prod" schemas var model = CreateTestModel(); // When filtering to include "dev" and "production" schemas var schemaFilter = new SchemaBasedFilter("dev", "prod"); schemaFilter.Filtering = SchemaBasedFilter.FilterType.Include; var filteredModel = CreateFilteredModel(schemaFilter, model); // Then expect only "test" schema objects to be excluded Assert.AreEqual(TopLevelProdElementCount + TopLevelDevElementCount, CountTablesViewsAndSchemas(filteredModel)); }
public void TestUpdateDacpacWithFilteredModel() { // Given a model with objects that use "dev", "test" and "prod" schemas var model = CreateTestModel(); string existingPackagePath = GetTestFilePath("original.dacpac"); BuildPackage(model, existingPackagePath); // When saving a dacpac for deployment to production (filtering to exclude "dev" and "test" schemas) var schemaFilter = new SchemaBasedFilter("dev", "test"); ModelFilterer modelFilterer = new ModelFilterer(schemaFilter); modelFilterer.UpdateDacpacModelWithFilter(existingPackagePath); // Then expect only the "prod" schema objects to remain in the new package var filteredModel = _trash.Add(new TSqlModel(existingPackagePath)); Assert.AreEqual(TopLevelProdElementCount, CountTablesViewsAndSchemas(filteredModel)); }
public void TestSchemaFilterExcludingSchemas() { // Given a model with objects that use "dev", "test" and "prod" schemas var model = CreateTestModel(); // When deploying to production (filtering to exclude "dev" and "test" schemas) var schemaFilter = new SchemaBasedFilter("dev", "test"); var filteredModel = CreateFilteredModel(schemaFilter, model); // Then expect only the "prod" schema objects to remain Assert.AreEqual(TopLevelProdElementCount, CountTablesViewsAndSchemas(filteredModel)); AssertAllObjectsHaveSchemaName(filteredModel, "prod"); }