コード例 #1
0
        public void Execute_Updates_WebConfig_Correctly(string envVariables, int expected)
        {
            string envTemplatePath = Path.GetTempFileName();
            string webConfigPath   = Path.GetTempFileName();
            string tempDir         = Path.GetDirectoryName(envTemplatePath);

            try
            {
                // Arrange
                List <XDocument> locationWebConfigTemplateList = new List <XDocument>()
                {
                    WebConfigTransformTemplates.WebConfigTemplate
                };
                foreach (var locationWebConfigTemplate in locationWebConfigTemplateList)
                {
                    _environmentTransformWithLocationTemplate.Save(envTemplatePath, SaveOptions.None);
                    XDocument webConfigTemplate = locationWebConfigTemplate;
                    webConfigTemplate.Save(webConfigPath);

                    GenerateEnvTransform env = new GenerateEnvTransform()
                    {
                        WebConfigEnvironmentVariables = envVariables,
                        EnvTransformTemplatePaths     = new List <string>()
                        {
                            envTemplatePath
                        }.ToArray(),
                                         PublishTempDirectory = tempDir
                    };


                    // Act
                    bool isSuccess = env.Execute();
                    Assert.True(isSuccess);
                    foreach (var generatedPath in env.GeneratedTransformFullPaths)
                    {
                        Assert.True(File.Exists(generatedPath));

                        TransformXml transformTask = new TransformXml()
                        {
                            Source            = webConfigPath,
                            Destination       = webConfigPath,
                            Transform         = generatedPath,
                            SourceRootPath    = Path.GetTempPath(),
                            TransformRootPath = Path.GetTempPath(),
                            StackTrace        = true
                        };

                        bool success = transformTask.RunXmlTransform(isLoggingEnabled: false);

                        // Assert
                        Assert.Equal(expected, XDocument.Parse(File.ReadAllText(webConfigPath)).Root.Descendants("environmentVariable").Count());
                    }
                }
            }
            finally
            {
                File.Delete(envTemplatePath);
                File.Delete(webConfigPath);
            }
        }
コード例 #2
0
        public void Execute_DoesnotFail_IfEnvVarIsNullOrEmpty(string envVariable, bool expected)
        {
            // Arrange
            GenerateEnvTransform env = new GenerateEnvTransform()
            {
                WebConfigEnvironmentVariables = envVariable
            };

            // Act
            bool isSuccess = env.Execute();

            // Assert
            Assert.Equal(expected, isSuccess);
        }