Example #1
0
        private RuntimeConfiguration CreateRuntimeConfiguration(string connectionString, DbPlatform dbPlatform, DbAltererOptions options)
        {
            var providerLocator = new ProviderLocator(new ProviderFactory()); // CLEAN: use DI container

            var providerInfo = providerLocator.GetLatest(dbPlatform);
            var validatorFactory = new ValidatorFactory(providerInfo, options, providerLocator);
            var validator = validatorFactory.Create();
            var connectionInfo = new ConnectionInfo(connectionString, providerInfo.Metadata.InvariantName, providerInfo.Metadata.SupportsTransactions, providerInfo.Metadata.EnableAnsiQuotesCommand);
            var sqlDispatcher = new SqlDispatcher(options.GetScriptingOptions(), providerInfo.Provider, providerInfo.Metadata);
            return new RuntimeConfiguration(providerInfo, connectionInfo, validator, sqlDispatcher);
        }
        public void CheckProviderValidation(DbPlatform platformUnderExecution, DbAltererOptions options, int expectedTotalNumberOfSupportedProviders, int expectedValidationRuns)
        {
            // arrange
            var providerLocator = new ProviderLocator(new ProviderFactory());
            int totalNumberOfSupportedProviders = options.SupportedPlatforms.Sum(n => providerLocator.GetAllForMinimumRequirement(n).Count());
            var validatorFactory = new ValidatorFactory(providerLocator.GetExactly(platformUnderExecution), options, providerLocator);
            Validator validator = validatorFactory.Create();

            var reporter = A.Fake<IMigrationReporter>();
            string errors;
            string warnings;

            // act
            validator.Validate(new[] { reporter }, out errors, out warnings);

            // assert
            Assert.AreEqual(expectedTotalNumberOfSupportedProviders, totalNumberOfSupportedProviders, "Wrong total number of providers.");
            A.CallTo(() => reporter.Report(A<IMigrationContext>._)).MustHaveHappened(Repeated.Exactly.Times(expectedValidationRuns));
        }