Example #1
0
        public void ProcessRecord_IfTheDestinationIsAZipFileAndTheSourceIsADirectory_ShouldTransformCorrectly()
        {
            var destination = this.GetOutputPath("Transformed-Package.zip");

            var newPackageTransformCommand = new NewPackageTransformCommand
            {
                Destination             = destination,
                FileToTransformPatterns = new[] { "**/*.config*", "**/*.json", "**/*.xml" },
                PathToDeletePatterns    = new[] { "**/Directory-To-Delete/**", "**/File-To-Delete.*" },
                Source = this.GetTestResourcePath("Package"),
                TransformationNames = new[] { "Release", "Test" }
            };

            this.InvokeCommand(newPackageTransformCommand);

            var extractedDestination = this.GetOutputPath("Extracted-Transformed-Package");

            ZipFile.ExtractToDirectory(destination, extractedDestination);

            var expected = this.GetTestResourcePath("Package-Expected");

            var actualItems   = this.GetFileSystemEntries(extractedDestination).ToArray();
            var expectedItems = this.GetFileSystemEntries(expected).ToArray();

            Assert.IsTrue(actualItems.SequenceEqual(expectedItems, new FileComparer(extractedDestination, expected)));
        }
Example #2
0
        public void ProcessRecord_IfTheSourceIsAnEmptyZipFile_ShouldTransformCorrectly()
        {
            var destination = this.GetOutputPath("Transformed-Package.zip");

            var newPackageTransformCommand = new NewPackageTransformCommand
            {
                Destination             = destination,
                FileToTransformPatterns = new[] { "**/*.config*", "**/*.json", "**/*.xml" },
                PathToDeletePatterns    = new[] { "**/Directory-To-Delete/**/*", "**/File-To-Delete.*" },
                Source = this.GetTestResourcePath("Empty.zip"),
                TransformationNames = new[] { "Release", "Test" }
            };

            this.InvokeCommand(newPackageTransformCommand);

            var extractedDestination = this.GetOutputPath("Extracted-Transformed-Package");

            ZipFile.ExtractToDirectory(destination, extractedDestination);

            // To handle NET 5.0 and NET Core 3.1.
            // Extracting an empty archive does not create an empty directory.
#if !NETFRAMEWORK
            if (!Directory.Exists(extractedDestination))
            {
                Directory.CreateDirectory(extractedDestination);
            }
#endif

            var expected = this.GetTestResourcePath("Empty-directory");

            var actualItems   = this.GetFileSystemEntries(extractedDestination).ToArray();
            var expectedItems = this.GetFileSystemEntries(expected).ToArray();

            Assert.IsTrue(actualItems.SequenceEqual(expectedItems, new FileComparer(extractedDestination, expected)));
        }
Example #3
0
        protected internal virtual void ValidateSourceParameterException <T>(string source) where T : ArgumentException
        {
            this.ValidateArgumentException <T>(() =>
            {
                var newPackageTransformCommand = new NewPackageTransformCommand
                {
                    Destination = this.GetOutputPath("Transformed-Package"),
                    Source      = source
                };

                this.InvokeCommand(newPackageTransformCommand);
            }, "source");
        }
Example #4
0
        protected internal virtual void ValidateDestinationParameterException <T>(string destination) where T : ArgumentException
        {
            this.ValidateArgumentException <T>(() =>
            {
                var newPackageTransformCommand = new NewPackageTransformCommand
                {
                    Destination = destination,
                    Source      = this.GetTestResourcePath("Empty-directory")
                };

                this.InvokeCommand(newPackageTransformCommand);
            }, "destination");
        }
Example #5
0
        public void ProcessRecord_IfTheSourceParameterIsNeitherADirectoryNorAZipFile_ShouldThrowAnArgumentException()
        {
            try
            {
                var newPackageTransformCommand = new NewPackageTransformCommand
                {
                    Destination = this.GetOutputPath("Transformed-Package"),
                    Source      = this.GetTestResourcePath("File.txt")
                };

                this.InvokeCommand(newPackageTransformCommand);
            }
            catch (ArgumentException argumentException)
            {
                if (string.Equals(argumentException.ParamName, "source", StringComparison.Ordinal))
                {
                    throw;
                }
            }
        }
Example #6
0
        public void ProcessRecord_ShouldTransformWithTheTransformationNamesInTheDeclaredOrderAndNotAlphabetically()
        {
            var destination = this.GetOutputPath("Transformed-Package");

            var newPackageTransformCommand = new NewPackageTransformCommand
            {
                Destination             = destination,
                FileToTransformPatterns = new[] { "**/*.config*", "**/*.json", "**/*.xml" },
                Source = this.GetTestResourcePath("Alphabetical-Test"),
                TransformationNames = new[] { "C", "A", "B" }
            };

            this.InvokeCommand(newPackageTransformCommand);

            var expected = this.GetTestResourcePath("Alphabetical-Test-Expected");

            var actualItems   = this.GetFileSystemEntries(destination).ToArray();
            var expectedItems = this.GetFileSystemEntries(expected).ToArray();

            Assert.IsTrue(actualItems.SequenceEqual(expectedItems, new FileComparer(destination, expected)));
        }