Example #1
0
        public void TryCreateContentFileWhenFileAlreadyExists()
        {
            var fileSystem = new Models.FileSystem();

            fileSystem.CreateDirectory("/directory");

            fileSystem.CreateContentFile("/directory/test", "Hello.");
            fileSystem.CreateContentFile("/directory/test", "Hello.");
        }
        /// <summary>
        /// Executes the concatenate command.
        /// </summary>
        /// <param name="fileSystem">The file system on which the command is going to be executed.</param>
        public override void Execute(Models.FileSystem fileSystem)
        {
            var hasInputFiles = InputFiles.Any();
            var hasOutputFile = !string.IsNullOrWhiteSpace(OutputFile);

            if (hasInputFiles && hasOutputFile)
            {
                try
                {
                    var concatenatedContent = ConcatenateFiles(fileSystem);
                    fileSystem.CreateContentFile(OutputFile, concatenatedContent);
                }
                catch (InvalidOperationException operationException)
                {
                    Console.WriteLine(operationException.Message);
                }
                catch (ArgumentException argumentException)
                {
                    Console.WriteLine(argumentException.Message);
                }
            }
            else if (hasInputFiles)
            {
                try
                {
                    var concatenatedContent = ConcatenateFiles(fileSystem);
                    Console.Write(concatenatedContent);
                }
                catch (InvalidOperationException operationException)
                {
                    Console.WriteLine(operationException.Message);
                }
            }
            else if (hasOutputFile)
            {
                var userInput = ReadUserInput();

                try
                {
                    fileSystem.CreateContentFile(OutputFile, userInput);
                }
                catch (InvalidOperationException operationException)
                {
                    Console.WriteLine(operationException.Message);
                }
                catch (ArgumentException argumentException)
                {
                    Console.WriteLine(argumentException.Message);
                }
            }
            else
            {
                Console.WriteLine("Couldn't execute cat command. Please check the validity of the passed parameters.");
            }
        }
Example #3
0
        public void TryCreateContentFileIntoMissingDirectory()
        {
            var fileSystem = new Models.FileSystem();

            fileSystem.CreateDirectory("/directory");

            fileSystem.CreateContentFile("/directory1/test", "Hello.");
        }
Example #4
0
        public void CreateContentFile()
        {
            var fileSystem = new Models.FileSystem();

            fileSystem.CreateDirectory("/directory");

            fileSystem.CreateContentFile("/directory/test", "Hello.");

            if (fileSystem.TryGetFile("/directory/test", out File file) && file is ContentFile contentFile)
            {
                Assert.IsTrue(string.Equals("Hello.", contentFile.Content));
            }
            else
            {
                Assert.Fail();
            }
        }