Exemple #1
0
        public void PrimaryKey()
        {
            var scriptPath = ".\\tableOne.sql";
            if(File.Exists(scriptPath))
                File.Delete(scriptPath);

            File.Copy("..\\..\\..\\ProjectWithConstraints\\TableOne.sql", scriptPath);

            //var namer = new ConstraintNamer(scriptPath,
            //    "..\\..\\..\\ProjectWithConstraints\\bin\\Release\\ProjectWithConstraints.dacpac");

            var namer = new ConstraintNamer(File.ReadAllText(scriptPath));

            var changedText = namer.Go();

            Assert.LessOrEqual(-1, changedText.IndexOf("[Id] INT NOT NULL PRIMARY KEY"), changedText);
            Assert.Greater( changedText.IndexOf("CONSTRAINT [PK_TableOne] PRIMARY KEY ([Id])"), -1, changedText);
        }
        private void NameConstraintsCalled(object sender, EventArgs e)
        {
            try
            {
                var dte = (DTE) GetService(typeof (DTE));
                if (null == dte || dte.ActiveDocument == null)
                {
                    return;
                }

                var doc = dte.ActiveDocument.Object("TextDocument") as TextDocument;
                if (null == doc)
                {
                    return;
                }

                var ep = doc.StartPoint.CreateEditPoint();

                ep.EndOfDocument();

                var length = ep.AbsoluteCharOffset;
                ep.StartOfDocument();

                var originalText = ep.GetText(length);

                var namer = new ConstraintNamer(originalText);
                var modifiedText = namer.Go();

                if (originalText != modifiedText)
                {
                    ep.Delete(length);
                    ep.Insert(modifiedText);
                }
            }
            catch (Exception ex)
            {
                OutputPane.WriteMessage("Exception naming constraints, error: {0}", ex.Message);
            }
        }