Exemple #1
0
        public void GetTemplateForSqlScript_Should_Return_Matching_Template()
        {
            // Arrange
            var codeTemplateArrayValues = new List <string>()
            {
                "this is a test", "to see if the lines", "join with return carriage", "###ReplaceMe###"
            };
            var replacmentChars = new List <string> {
                "###ReplaceMe###"
            };
            string name      = "test template";
            string outputDir = "c:\\test\\";

            List <SqlTemplate> testTemplate = new List <SqlTemplate>()
            {
                new SqlTemplate()
                {
                    ExistingCodeTemplateArray = codeTemplateArrayValues,
                    SqlCodeTemplateArray      = codeTemplateArrayValues,
                    Name             = name,
                    OutputDirectory  = outputDir,
                    ReplaceMentChars = replacmentChars
                },
                new SqlTemplate()
                {
                    Name             = "DummyData",
                    OutputDirectory  = "c:\\dummy",
                    ReplaceMentChars = new List <string>()
                    {
                        "##Dummy##"
                    },
                    ExistingCodeTemplateArray = new List <string>()
                    {
                        "Dummy Data"
                    },
                    SqlCodeTemplateArray = new List <string>()
                    {
                        "Dummy Data"
                    },
                },
                new SqlTemplate()
                {
                    OutputDirectory  = "c:\\dummy2",
                    ReplaceMentChars = new List <string>()
                    {
                        "##Dummy2##"
                    },
                    ExistingCodeTemplateArray = new List <string>()
                    {
                        "Dummy Data 2"
                    },
                    SqlCodeTemplateArray = new List <string>()
                    {
                        "Dummy Data 2"
                    },
                }
            };

            _fileAccess.Setup(method => method.LoadJsonFile(_settings.Value.SqlTemplatesFile))
            .Returns(testTemplate);

            var rule = new Rule()
            {
                TemplateName          = name,
                GetScriptNameFromFile = false,
                ScriptIdentifier      = new List <string>()
                {
                    "this is a test"
                },
                Replace = new List <string>()
                {
                    "this is a test:This is another Test"
                }
            };

            // Act
            var result = _processTemplate.GetTemplateForSqlScript(rule);

            //Assert
            string answer = "this is a test\r\nto see if the lines\r\njoin with return carriage\r\n###ReplaceMe###";

            result.SqlCodeTemplate.Should().Be(answer);
            result.ExistingCodeTemplate.Should().Be(answer);
            result.Name.Should().Be(name);
            result.OutputDirectory.Should().Be(outputDir);
            result.ReplaceMentChars.First().Should().Be(replacmentChars.First());
        }