예제 #1
0
        public void Generate(string rFile, RCodePlacement codePlacement, SqlQuoteType quoteType, string sprocName)
        {
            var fs       = new WindowsFileSystem();
            var settings = new SqlSProcPublishSettings();
            var g        = new SProcProjectFilesGenerator(_pss, fs);

            var targetProjItem  = Substitute.For <EnvDTE.ProjectItem>();
            var targetProjItems = Substitute.For <EnvDTE.ProjectItems>();

            targetProjItem.ProjectItems.Returns(targetProjItems);

            var rootProjItems = Substitute.For <EnvDTE.ProjectItems>();

            rootProjItems.Item("R").Returns((EnvDTE.ProjectItem)null);
            rootProjItems.AddFolder("R").Returns(targetProjItem);
            _project.ProjectItems.Returns(rootProjItems);

            var templateFile = Path.Combine(_files.DestinationPath, Path.GetFileNameWithoutExtension(rFile) + SProcFileExtensions.SProcFileExtension);

            var sprocFiles = new string[] {
                Path.Combine(_files.DestinationPath, rFile),
                Path.Combine(_files.DestinationPath, Path.GetFileNameWithoutExtension(rFile) + SProcFileExtensions.QueryFileExtension),
                templateFile
            };

            settings.CodePlacement = codePlacement;
            settings.QuoteType     = quoteType;

            g.Generate(settings, sprocFiles, _project);
            rootProjItems.Received().AddFolder("R");

            var targetFolder = Path.Combine(_files.DestinationPath, "R\\");
            var rFilePath    = Path.Combine(targetFolder, rFile);
            var sprocFile    = Path.ChangeExtension(Path.Combine(targetFolder, sprocName), ".sql");

            targetProjItem.ProjectItems.Received().AddFromFile(sprocFile);
            if (codePlacement == RCodePlacement.Table)
            {
                targetProjItem.ProjectItems.Received().AddFromFile(Path.Combine(targetFolder, SProcProjectFilesGenerator.PostDeploymentScriptName));
                targetProjItem.ProjectItems.Received().AddFromFile(Path.Combine(targetFolder, SProcProjectFilesGenerator.CreateRCodeTableScriptName));
            }

            var    mode     = codePlacement == RCodePlacement.Inline ? "inline" : "table";
            var    baseline = fs.ReadAllText(Path.Combine(_files.DestinationPath, Invariant($"{Path.GetFileNameWithoutExtension(rFile)}.{mode}.baseline.sql")));
            string actual   = fs.ReadAllText(sprocFile);

            BaselineCompare.CompareStringLines(baseline, actual);
        }
예제 #2
0
        public void Generate(string rFile, RCodePlacement codePlacement, SqlQuoteType quoteType, string sprocName) {
            var fs = new FileSystem();
            var settings = new SqlSProcPublishSettings();
            var g = new SProcProjectFilesGenerator(_pss, fs);

            var targetProjItem = Substitute.For<EnvDTE.ProjectItem>();
            var targetProjItems = Substitute.For<EnvDTE.ProjectItems>();
            targetProjItem.ProjectItems.Returns(targetProjItems);

            var rootProjItems = Substitute.For<EnvDTE.ProjectItems>();
            rootProjItems.Item("R").Returns((EnvDTE.ProjectItem)null);
            rootProjItems.AddFolder("R").Returns(targetProjItem);
            _project.ProjectItems.Returns(rootProjItems);

            var templateFile = Path.Combine(_files.DestinationPath, Path.GetFileNameWithoutExtension(rFile) + SProcFileExtensions.SProcFileExtension);

           var sprocFiles = new string[] {
                Path.Combine(_files.DestinationPath, rFile),
                Path.Combine(_files.DestinationPath, Path.GetFileNameWithoutExtension(rFile) + SProcFileExtensions.QueryFileExtension),
                templateFile };

            settings.CodePlacement = codePlacement;
            settings.QuoteType = quoteType;

            g.Generate(settings, sprocFiles, _project);
            rootProjItems.Received().AddFolder("R");

            var targetFolder = Path.Combine(_files.DestinationPath, "R\\");
            var rFilePath = Path.Combine(targetFolder, rFile);
            var sprocFile = Path.ChangeExtension(Path.Combine(targetFolder, sprocName), ".sql");

            targetProjItem.ProjectItems.Received().AddFromFile(sprocFile);
            if (codePlacement == RCodePlacement.Table) {
                targetProjItem.ProjectItems.Received().AddFromFile(Path.Combine(targetFolder, SProcProjectFilesGenerator.PostDeploymentScriptName));
                targetProjItem.ProjectItems.Received().AddFromFile(Path.Combine(targetFolder, SProcProjectFilesGenerator.CreateRCodeTableScriptName));
            }

            var mode = codePlacement == RCodePlacement.Inline ? "inline" : "table";
            var baseline = fs.ReadAllText(Path.Combine(_files.DestinationPath, Invariant($"{Path.GetFileNameWithoutExtension(rFile)}.{mode}.baseline.sql")));
            string actual = fs.ReadAllText(sprocFile);
            BaselineCompare.CompareStringLines(baseline, actual);
        }