private ScriptResult CompareAndUpdateDatabase(IComparerSettings settings, TestCaseStructure testCaseStructure)
    {
        var comparer      = CreateComparer(settings);
        var compareResult = default(ScriptResult);

        try
        {
            compareResult = comparer.Compare().Script;
        }
        catch (Exception ex) when(testCaseStructure.ExpectedCompareException?.IsAssignableFrom(ex.GetType()) ?? false)
        {
            Assert.Pass();
            return(null);
        }
        if (testCaseStructure.ExpectedCompareException != null)
        {
            Assert.Fail("Expected exception but nothing happened.");
            return(null);
        }
        TestContext.WriteLine("*** Change script:");
        var commands = compareResult.AllStatements.ToArray();

        foreach (var item in commands)
        {
            TestContext.WriteLine(item);
        }
        TestContext.WriteLine();
        Helpers.Database.ExecuteScript(m_Version, Helpers.Database.DatabaseLocation.Target, commands);
        return(compareResult);
    }
Beispiel #2
0
 private Comparer CreateComparer(IComparerSettings settings)
 {
     return(Comparer.ForTwoDatabases(
                settings,
                Helpers.Database.GetConnectionString(m_Version, Helpers.Database.DatabaseLocation.Source),
                Helpers.Database.GetConnectionString(m_Version, Helpers.Database.DatabaseLocation.Target)));
 }
Beispiel #3
0
 public ComparerContext(IComparerSettings settings)
 {
     DroppedObjects        = new HashSet <TypeObjectNameKey>();
     CreatedRelationFields = new HashSet <RelationFieldKey>();
     DeferredColumnsToDrop = new List <CommandGroup>();
     m_EmptyBodiesEnabled  = false;
     Settings = settings ?? throw new ArgumentNullException(nameof(settings));
 }
Beispiel #4
0
        public static Comparer ForTwoDatabases(IComparerSettings settings, string sourceConnectionString, string targetConnectionString)
        {
            var container       = Bootstrapper.BootstrapContainerDefault(settings);
            var metadataFactory = container.Resolve <IMetadataFactory>();
            var sourceMetadata  = metadataFactory.Create(sourceConnectionString);
            var targetMetadata  = metadataFactory.Create(targetConnectionString);

            Parallel.Invoke(
                sourceMetadata.Initialize,
                targetMetadata.Initialize);
            return((Comparer)container.Resolve <IComparerFactory>().Create(settings, sourceMetadata, targetMetadata));
        }
Beispiel #5
0
        public static IWindsorContainer BootstrapContainerDefault(IComparerSettings settings)
        {
            var container = new WindsorContainer();

            container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel));
            container.Kernel.AddHandlerSelector(new SqlHelperSelector(settings));
            container.Kernel.AddHandlerSelector(new DatabaseObjectSelector(settings));
            container.AddFacility <TypedFactoryFacility>();
            container.Register(Component.For <IComparerSettings>().Instance(settings));
            container.Install(FromAssembly.InThisApplication(Assembly.GetExecutingAssembly()));
            return(container);
        }
Beispiel #6
0
        private ScriptResult UpdateDatabase(IComparerSettings settings, TestCaseSpecificAsserts specificAsserts)
        {
            var comparer      = CreateComparer(settings);
            var compareResult = default(ScriptResult);

            try
            {
                compareResult = comparer.Compare().Script;
            }
            catch (Exception ex) when(specificAsserts?.ExpectedCompareException?.IsAssignableFrom(ex.GetType()) ?? false)
            {
                TestContext.WriteLine("Pass on expected exception.");
                Assert.Pass();
                return(default);
Beispiel #7
0
        private ScriptResult UpdateDatabase(IComparerSettings settings)
        {
            var comparer      = CreateComparer(settings);
            var compareResult = comparer.Compare().Script;

            TestContext.WriteLine("Change script:");
            var commands = compareResult.AllStatements.ToArray();

            foreach (var item in commands)
            {
                TestContext.WriteLine(item);
            }
            TestContext.WriteLine();
            Helpers.Database.ExecuteScript(m_Version, Helpers.Database.DatabaseLocation.Target, commands);
            return(compareResult);
        }
Beispiel #8
0
        public static Comparer ForTwoDatabases(IComparerSettings settings, string sourceConnectionString, string targetConnectionString)
        {
            var sqlHelper             = GetSqlHelper(settings.TargetVersion);
            var databaseObjectFactory = GetDatabaseObjectFactory(settings.TargetVersion, sqlHelper);
            var sourceMetadata        = new Metadata(sourceConnectionString, databaseObjectFactory);
            var targetMetadata        = new Metadata(targetConnectionString, databaseObjectFactory);

            Parallel.Invoke(
                sourceMetadata.Initialize,
                targetMetadata.Initialize);
            return(new Comparer(
                       new ScriptBuilder(sqlHelper),
                       new ComparerContext(settings),
                       sourceMetadata,
                       targetMetadata));
        }
Beispiel #9
0
        private void AssertComparerSeesNoDifference(IComparerSettings settings)
        {
            var comparer = CreateComparer(settings);
            var commands = comparer.Compare().Statements.ToArray();

            try
            {
                Assert.That(commands, Is.Empty);
            }
            catch
            {
                TestContext.WriteLine("Differences:");
                foreach (var item in commands)
                {
                    TestContext.WriteLine(item);
                }
                TestContext.WriteLine();
                throw;
            }
        }
Beispiel #10
0
 public SqlHelperSelector(IComparerSettings comparerSettings)
     : base(comparerSettings)
 {
 }
Beispiel #11
0
 public DatabaseObjectSelector(IComparerSettings comparerSettings)
     : base(comparerSettings)
 {
 }
Beispiel #12
0
 public VersionHandlerSelector(IComparerSettings comparerSettings)
 {
     ComparerSettings = comparerSettings ?? throw new ArgumentNullException(nameof(comparerSettings));
     m_Suffix         = ComparerSettings.TargetVersion.VersionSuffix();
 }
Beispiel #13
0
 public DatabaseObjectFactorySelector(IComparerSettings comparerSettings)
 {
     ComparerSettings = comparerSettings ?? throw new ArgumentNullException(nameof(comparerSettings));
     m_Suffix         = ComparerSettings.TargetVersion.VersionSuffix();
 }