public void does_build_merge_for_table_with_no_schema_defined()
 {
     var tableRepository = new TableRepository(GetPath());
     var mergeRepository = new MergeStatementRepository(tableRepository, Path.Combine(Directories.GetSampleSolution(), @"NestedProjects\Nested\ABC\DEF\Script.PostDeploy.sql"));
     var merge = mergeRepository.Get().FirstOrDefault(p => p.Name.Value == "NoSchema");
     Assert.IsNotNull(merge);
 }
 public void does_not_build_merge_for_table_with_no_inline_table()
 {
     var tableRepository = new TableRepository(Path.Combine(Directories.GetSampleSolution(), @"NestedProjects\Nested\bin\Debug\Nested.dacpac"));
     var mergeRepository = new MergeStatementRepository(tableRepository, Path.Combine(Directories.GetSampleSolution(), @"NestedProjects\Nested\ABC\DEF\Script.PostDeploy.sql"));
     var merge = mergeRepository.Get().FirstOrDefault(p => p.Name.Value == "NoInlineTable");
     Assert.IsNull(merge);
 }
 public void can_parse_generated_merge_statement()
 {
     var tableRepository = new TableRepository(Path.Combine(Directories.GetSampleSolution(), @"NestedProjects\Nested\bin\Debug\Nested.dacpac"));
     var mergeRepository = new MergeStatementRepository(tableRepository, Path.Combine(Directories.GetSampleSolution(), @"NestedProjects\Nested\ABC\DEF\Script.PostDeploy.sql"));
     var merge = mergeRepository.Get().FirstOrDefault(p=>p.Name.Value == "TheTable");
     Assert.AreEqual(2, merge.Data.Rows.Count);
     Assert.AreEqual("Ed", merge.Data.Rows[0][1]);
     Assert.AreEqual("Ian", merge.Data.Rows[1][1]);
     Assert.IsTrue(merge.Option.HasDelete);
     Assert.IsTrue(merge.Option.HasUpdate);
     Assert.IsTrue(merge.Option.HasInsert);
 }
        public void file_offset_and_length_are_correct()
        {
            var tableRepository = new TableRepository(Path.Combine(Directories.GetSampleSolution(), @"NestedProjects\Nested\bin\Debug\Nested.dacpac"));
            var mergeRepository = new MergeStatementRepository(tableRepository, Path.Combine(Directories.GetSampleSolution(), @"NestedProjects\Nested\ABC\DEF\Script.PostDeploy.sql"));
            var merge = mergeRepository.Get().FirstOrDefault(p => p.Name.Value == "TheTable");

            using (var reader = new StreamReader(merge.ScriptDescriptor.FilePath))
            {
                var script = reader.ReadToEnd().Substring(merge.ScriptDescriptor.ScriptOffset, merge.ScriptDescriptor.ScriptLength);
                Assert.AreEqual(@"MERGE INTO dbo.TheTable
             AS TARGET
            USING (VALUES (1, 'Ed', 1), (2, 'Ian', 0)) AS SOURCE(Id, name, fun) ON SOURCE.[Id] = TARGET.[Id]
            WHEN NOT MATCHED BY TARGET THEN INSERT (Id, name, fun) VALUES (SOURCE.Id, SOURCE.name, SOURCE.fun)
            WHEN MATCHED AND (NULLIF (SOURCE.fun, TARGET.fun) IS NOT NULL
                  OR NULLIF (SOURCE.name, TARGET.name) IS NOT NULL
                  OR NULLIF (SOURCE.Id, TARGET.Id) IS NOT NULL) THEN UPDATE
            SET TARGET.Id   = SOURCE.Id,
            TARGET.name = SOURCE.name,
            TARGET.fun  = SOURCE.fun
            WHEN NOT MATCHED BY SOURCE THEN DELETE;", script);
            }
        }
Esempio n. 5
0
        public void test()
        {
            var tableRepository = new TableRepository(Path.Combine(Directories.GetSampleSolution(), @"NestedProjects\Nested\bin\Debug\Nested.dacpac"));
            
            var m = new Merge.MergeDescriptor.Merge();

            var tempFile = Path.Combine(Path.GetTempPath(),
                Guid.NewGuid().ToString().Replace("-", "").Replace("{", "").Replace("}", ""));

            File.CreateText(tempFile).Close();

            m.ScriptDescriptor = new InScriptDescriptor(0, 0, tempFile);
            m.ScriptDescriptor.OriginalText = null;
            m.Table = tableRepository.Get().First(p=>p.Name.GetName() == "TheTable");
            m.Data = new DataTable();
            foreach (var c in m.Table.Columns)
            {
                m.Data.Columns.Add(c.Name.GetName());
            }

            for (int i = 0; i < 10; i++)
            {
                var r = m.Data.NewRow();
                for (int j = 0; j < r.ItemArray.Length; j++)
                {
                    r[j] = i;
                }
                m.Data.Rows.Add(r);
            }
            m.Name = m.Table.Name.ToIdentifier();

            m.Option = new MergeOptions(true, true, false, true);


            var writer = new Merge.MergeDescriptor.MergeWriter(m);
            Assert.DoesNotThrow(writer.Write);

            File.Delete(tempFile);
        }
Esempio n. 6
0
        private TreeViewItem GetScriptNode(TableRepository tables, ProjectItem item)
        {
            var node = new TreeViewItem();
            node.Header = item.Name;

            //parse the merge statements...
            var repoitory = new MergeStatementRepository(tables, item.FileNames[0]);
            repoitory.Populate();

            foreach (var merge in repoitory.Get())
            {
                merge.Data.ExtendedProperties["Changed"] = false;
                var mergeNode = new TreeViewItem();
                mergeNode.Header = merge.Name.Value;
                mergeNode.Tag = merge;
                mergeNode.ContextMenu = ProjectItems.Resources["TableContext"] as ContextMenu;
                node.Items.Add(mergeNode);
            }

            node.ContextMenu = ProjectItems.Resources["FileContext"] as ContextMenu;

            if (item.Properties.Item("FullPath") == null)
            {
                MessageBox.Show("Error unable to get propert FullPath on script file, unable to build tree");
                return null;
            }


            node.Tag = new ScriptNodeTag
            {
                ScriptPath = item.Properties.Item("FullPath").Value.ToString(),
                Tables = tables
            };

            return node;
        }
Esempio n. 7
0
        private TreeViewItem GetScripts(Project project, TableRepository tables, string type)
        {
            var node = new TreeViewItem();
            node.Header = type;

            foreach (var item in new ProjectItemEnumerator().Get(project).Where(p => p.HasBuildAction(type)))
            {
                node.Items.Add(GetScriptNode(tables, item));
            }


            return node;
        }
Esempio n. 8
0
        private void CreateProjectDefaults(TreeViewItem root, Project project)
        {
            root.Header = project.Name;
            root.Selected += mergeNode_Selected;

            var tables = new TableRepository(DacpacPath.Get(project));

            var preDeploy = GetScripts(project, tables, "PreDeploy");
            var postDeploy = GetScripts(project, tables, "PostDeploy");
            var other = GetScripts(project, tables, "None");

            root.Items.Add(preDeploy);
            root.Items.Add(postDeploy);
            root.Items.Add(other);
        }
        public void OriginalText_is_set_correctly()
        {
            var tableRepository = new TableRepository(GetPath());
            var mergeRepository = new MergeStatementRepository(tableRepository, Path.Combine(Directories.GetSampleSolution(), @"NestedProjects\Nested\ABC\DEF\Script.PostDeploy.sql"));
            var merge = mergeRepository.Get().FirstOrDefault(p => p.Name.Value == "TheTable");

            
                Assert.AreEqual(@"MERGE INTO dbo.TheTable
 AS TARGET
USING (VALUES (1, 'Ed', 1), (2, 'Ian', 0)) AS SOURCE(Id, name, fun) ON SOURCE.[Id] = TARGET.[Id]
WHEN NOT MATCHED BY TARGET THEN INSERT (Id, name, fun) VALUES (SOURCE.Id, SOURCE.name, SOURCE.fun)
WHEN MATCHED AND (NULLIF (SOURCE.fun, TARGET.fun) IS NOT NULL
                  OR NULLIF (SOURCE.name, TARGET.name) IS NOT NULL
                  OR NULLIF (SOURCE.Id, TARGET.Id) IS NOT NULL) THEN UPDATE 
SET TARGET.Id   = SOURCE.Id,
    TARGET.name = SOURCE.name,
    TARGET.fun  = SOURCE.fun
WHEN NOT MATCHED BY SOURCE THEN DELETE;", merge.ScriptDescriptor.OriginalText);
            
        }
 public void sets_merge_options_to_show_missing_delete_clause()
 {
     var tableRepository = new TableRepository(GetPath());
     var mergeRepository = new MergeStatementRepository(tableRepository, Path.Combine(Directories.GetSampleSolution(), @"NestedProjects\Nested\ABC\DEF\Script.PostDeploy.sql"));
     var merge = mergeRepository.Get().FirstOrDefault(p => p.Name.Value == "NoDelete");
     Assert.IsFalse(merge.Option.HasDelete);
     Assert.IsTrue(merge.Option.HasInsert);
     Assert.IsTrue(merge.Option.HasUpdate);
 }
        public void ignores_other_statements_in_file()
        {
            var tableRepository = new TableRepository(GetPath());
            var mergeRepository = new MergeStatementRepository(tableRepository, Path.Combine(Directories.GetSampleSolution(), @"NestedProjects\Nested\ABC\DEF\Script.NotIncluded.sql"));
            Assert.DoesNotThrow(() =>
            {
                mergeRepository.Get();
            });

            Assert.AreEqual(0, mergeRepository.Get().Count);
        }
 public MergeStatementRepository(TableRepository tables, string path)
 {
     _tables = tables;
     _path = path;
 }