TransformConfigurationFiles() public method

public TransformConfigurationFiles ( string baseDirectoryPath, string transformationProfileNames ) : IServiceResult
baseDirectoryPath string
transformationProfileNames string
return IServiceResult
        public void TransformConfigurationFiles_BaseDirectoryPathParameterIsInvalid_ArgumentExceptionIsThrown(string baseDirectoryPath)
        {
            // Arrange
            var transformationProfileNames = new string[] { };

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var configurationFileTransformer = new Mock<IConfigurationFileTransformer>();

            var configurationFileTransformationService = new ConfigurationFileTransformationService(
                filesystemAccessor.Object, configurationFileTransformer.Object);

            // Act
            configurationFileTransformationService.TransformConfigurationFiles(baseDirectoryPath, transformationProfileNames);
        }
        public void TransformConfigurationFiles_ConfigurationFilesFound_TransformationFileCleanupFails_ResultIsFalse()
        {
            // Arrange
            string baseDirectoryPath = Environment.CurrentDirectory;
            var transformationProfileNames = new[] { "PROD" };

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var configurationFileTransformer = new Mock<IConfigurationFileTransformer>();

            // prepare filesystem accessor
            var configurationFiles = new List<FileInfo>
                {
                    new FileInfo(Path.Combine(baseDirectoryPath, "websites", "website.A", "web.config")),
                    new FileInfo(Path.Combine(baseDirectoryPath, "webapplications", "webapp", "web.config")),
                    new FileInfo(Path.Combine(baseDirectoryPath, "applications", "some-app", "app.config"))
                };
            filesystemAccessor.Setup(f => f.GetAllFiles(It.Is<string>(folder => folder.StartsWith(baseDirectoryPath)))).Returns(configurationFiles);
            filesystemAccessor.Setup(f => f.DeleteFile(It.IsAny<string>())).Returns(false);
            filesystemAccessor.Setup(f => f.FileExists(It.IsAny<string>())).Returns(true);

            configurationFileTransformer.Setup(t => t.Transform(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(new SuccessResult());

            var transformationFileWebsite = new FileInfo(Path.Combine(baseDirectoryPath, "websites", "website.A", "web.PROD.config"));
            filesystemAccessor.Setup(f => f.GetFiles(It.Is<string>(folder => folder.StartsWith(Path.Combine(baseDirectoryPath, "websites", "website.A"))))).
                Returns(new List<FileInfo> { transformationFileWebsite });

            var transformationFileWebApp = new FileInfo(Path.Combine(baseDirectoryPath, "webapplications", "webapp", "web.PROD.config"));
            filesystemAccessor.Setup(f => f.GetFiles(It.Is<string>(folder => folder.StartsWith(Path.Combine(baseDirectoryPath, "webapplications", "webapp"))))).
                Returns(new List<FileInfo> { transformationFileWebApp });

            var transformationFileApp = new FileInfo(Path.Combine(baseDirectoryPath, "applications", "some-app", "app.PROD.config"));
            filesystemAccessor.Setup(f => f.GetFiles(It.Is<string>(folder => folder.StartsWith(Path.Combine(baseDirectoryPath, "applications", "some-app"))))).
                Returns(new List<FileInfo> { transformationFileApp });

            var configurationFileTransformationService = new ConfigurationFileTransformationService(
                filesystemAccessor.Object, configurationFileTransformer.Object);

            // Act
            var result = configurationFileTransformationService.TransformConfigurationFiles(baseDirectoryPath, transformationProfileNames);

            // Assert
            Assert.AreEqual(ServiceResultType.Failure, result.Status);
        }
        public void TransformConfigurationFiles_TransformationProfileNamesIsNull_ArgumentNullExceptionIsThrown()
        {
            // Arrange
            string baseDirectoryPath = Environment.CurrentDirectory;
            string[] transformationProfileNames = null;

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var configurationFileTransformer = new Mock<IConfigurationFileTransformer>();

            var configurationFileTransformationService = new ConfigurationFileTransformationService(
                filesystemAccessor.Object, configurationFileTransformer.Object);

            // Act
            configurationFileTransformationService.TransformConfigurationFiles(baseDirectoryPath, transformationProfileNames);
        }
        public void TransformConfigurationFiles_TransformationProfileNamesIsEmpty_ResultIsTrue()
        {
            // Arrange
            string baseDirectoryPath = Environment.CurrentDirectory;
            string[] transformationProfileNames = new string[] { };

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var configurationFileTransformer = new Mock<IConfigurationFileTransformer>();

            var configurationFileTransformationService = new ConfigurationFileTransformationService(
                filesystemAccessor.Object, configurationFileTransformer.Object);

            // Act
            var result = configurationFileTransformationService.TransformConfigurationFiles(baseDirectoryPath, transformationProfileNames);

            // Assert
            Assert.AreEqual(ServiceResultType.Success, result.Status);
        }
        public void TransformConfigurationFiles_NoConfigurationFilesFound_TransformIsNotExecuted()
        {
            // Arrange
            string baseDirectoryPath = Environment.CurrentDirectory;
            var transformationProfileNames = new[] { "PROD" };

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var configurationFileTransformer = new Mock<IConfigurationFileTransformer>();

            // prepare filesystem accessor
            var configurationFiles = new List<FileInfo>();
            filesystemAccessor.Setup(f => f.GetAllFiles(It.Is<string>(folder => folder.StartsWith(baseDirectoryPath)))).Returns(configurationFiles);

            var configurationFileTransformationService = new ConfigurationFileTransformationService(
                filesystemAccessor.Object, configurationFileTransformer.Object);

            // Act
            configurationFileTransformationService.TransformConfigurationFiles(baseDirectoryPath, transformationProfileNames);

            // Assert
            configurationFileTransformer.Verify(t => t.Transform(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never());
        }
        public void TransformConfigurationFiles_NoConfigurationFilesFound_ResultIsTrue()
        {
            // Arrange
            string baseDirectoryPath = Environment.CurrentDirectory;
            var transformationProfileNames = new[] { "PROD" };

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var configurationFileTransformer = new Mock<IConfigurationFileTransformer>();

            // prepare filesystem accessor
            var configurationFiles = new List<FileInfo>();
            filesystemAccessor.Setup(f => f.GetAllFiles(It.Is<string>(folder => folder.StartsWith(baseDirectoryPath)))).Returns(configurationFiles);

            var configurationFileTransformationService = new ConfigurationFileTransformationService(
                filesystemAccessor.Object, configurationFileTransformer.Object);

            // Act
            var result = configurationFileTransformationService.TransformConfigurationFiles(baseDirectoryPath, transformationProfileNames);

            // Assert
            Assert.AreEqual(ServiceResultType.Success, result.Status);
        }
        public void TransformConfigurationFiles_ConfigurationFilesFound_TransformIsExecutedForEachFileAndProfile()
        {
            // Arrange
            string baseDirectoryPath = Environment.CurrentDirectory;
            var transformationProfileNames = new[] { "PROD" };

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var configurationFileTransformer = new Mock<IConfigurationFileTransformer>();

            // prepare filesystem accessor
            var configurationFiles = new List<FileInfo>
                {
                    new FileInfo(Path.Combine(baseDirectoryPath, "websites", "website.A", "web.config")),
                    new FileInfo(Path.Combine(baseDirectoryPath, "webapplications", "webapp", "web.config")),
                    new FileInfo(Path.Combine(baseDirectoryPath, "applications", "some-app", "app.config"))
                };
            filesystemAccessor.Setup(f => f.GetAllFiles(It.Is<string>(folder => folder.StartsWith(baseDirectoryPath)))).Returns(configurationFiles);
            filesystemAccessor.Setup(f => f.FileExists(It.IsAny<string>())).Returns(true);

            configurationFileTransformer.Setup(t => t.Transform(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(new SuccessResult());

            var configurationFileTransformationService = new ConfigurationFileTransformationService(
                filesystemAccessor.Object, configurationFileTransformer.Object);

            // Act
            configurationFileTransformationService.TransformConfigurationFiles(baseDirectoryPath, transformationProfileNames);

            // Assert
            foreach (var configurationFile in configurationFiles)
            {
                foreach (var transformationProfileName in transformationProfileNames)
                {
                    string sourceFile = configurationFile.FullName;
                    string profile = transformationProfileName;

                    configurationFileTransformer.Verify(t => t.Transform(sourceFile, It.Is<string>(s => s.Contains(profile)), sourceFile), Times.Once());
                }
            }
        }
        public void TransformConfigurationFiles_ConfigurationFilesFound_TransformationFilesAreDeletedAfterTheTransformation()
        {
            // Arrange
            string baseDirectoryPath = Environment.CurrentDirectory;
            var transformationProfileNames = new[] { "PROD" };

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var configurationFileTransformer = new Mock<IConfigurationFileTransformer>();

            // prepare filesystem accessor
            var configurationFiles = new List<FileInfo>
                {
                    new FileInfo(Path.Combine(baseDirectoryPath, "websites", "website.A", "web.config")),
                    new FileInfo(Path.Combine(baseDirectoryPath, "webapplications", "webapp", "web.config")),
                    new FileInfo(Path.Combine(baseDirectoryPath, "applications", "some-app", "app.config"))
                };
            filesystemAccessor.Setup(f => f.GetAllFiles(It.Is<string>(folder => folder.StartsWith(baseDirectoryPath)))).Returns(configurationFiles);
            filesystemAccessor.Setup(f => f.DeleteFile(It.IsAny<string>())).Returns(true);

            configurationFileTransformer.Setup(t => t.Transform(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(new SuccessResult());

            var transformationFileWebsite = new FileInfo(Path.Combine(baseDirectoryPath, "websites", "website.A", "web.PROD.config"));
            filesystemAccessor.Setup(f => f.GetFiles(It.Is<string>(folder => folder.StartsWith(Path.Combine(baseDirectoryPath, "websites", "website.A"))))).
                Returns(new List<FileInfo> { transformationFileWebsite });

            var transformationFileWebApp = new FileInfo(Path.Combine(baseDirectoryPath, "webapplications", "webapp", "web.PROD.config"));
            filesystemAccessor.Setup(f => f.GetFiles(It.Is<string>(folder => folder.StartsWith(Path.Combine(baseDirectoryPath, "webapplications", "webapp"))))).
                Returns(new List<FileInfo> { transformationFileWebApp });

            var transformationFileApp = new FileInfo(Path.Combine(baseDirectoryPath, "applications", "some-app", "app.PROD.config"));
            filesystemAccessor.Setup(f => f.GetFiles(It.Is<string>(folder => folder.StartsWith(Path.Combine(baseDirectoryPath, "applications", "some-app"))))).
                Returns(new List<FileInfo> { transformationFileApp });

            var transformationFiles = new List<FileInfo> { transformationFileWebsite, transformationFileWebApp, transformationFileApp };

            var configurationFileTransformationService = new ConfigurationFileTransformationService(
                filesystemAccessor.Object, configurationFileTransformer.Object);

            // Act
            configurationFileTransformationService.TransformConfigurationFiles(baseDirectoryPath, transformationProfileNames);

            // Assert
            foreach (var transformationFile in transformationFiles)
            {
                string filePath = transformationFile.FullName;
                filesystemAccessor.Verify(f => f.DeleteFile(It.Is<string>(s => s.Equals(filePath))), Times.Once());
            }
        }