Exemple #1
0
        public void SucceedsFileExists()
        {
            string   outFilename = GetCurrentTestResultsFilePath("out.txt");
            FileInfo file        = GetTestFile("Lipsum.txt");
            PrependOrAppendTextProcessor processor = new PrependOrAppendTextProcessor();

            processor.SetParameter("Text", "foo bar baz");
            processor.SetParameter("FileName", outFilename);
            processor.SetParameter("OverwriteExistingFile", true);
            File.WriteAllBytes(outFilename, new byte[0]);
            processor.Init(RunInfo);
            ProcessingResult result = processor.Process(file, MatchResultType.Yes, new string[0],
                                                        new FileInfo[0], ProcessInput.OriginalFile, CancellationToken.None);

            processor.Cleanup();
            Assert.AreEqual(ProcessingResultType.Success, result.Type);
            Assert.AreEqual(1, result.OutputFiles.Length);
        }
Exemple #2
0
        public void FailsFileInUse()
        {
            string   outFilename = GetCurrentTestResultsFilePath("out.txt");
            FileInfo file        = GetTestFile("Lipsum.txt");
            PrependOrAppendTextProcessor processor = new PrependOrAppendTextProcessor();

            processor.SetParameter("Text", "foo bar baz");
            processor.SetParameter("FileName", outFilename);
            processor.SetParameter("OverwriteExistingFile", true);
            ProcessingResult result;

            using (FileStream fs = File.OpenWrite(outFilename))
            {
                processor.Init(RunInfo);
                result = processor.Process(file, MatchResultType.Yes, new string[0],
                                           new FileInfo[0], ProcessInput.OriginalFile, CancellationToken.None);
                processor.Cleanup();
            }
            Assert.AreEqual(ProcessingResultType.Failure, result.Type);
            Assert.AreEqual(0, result.OutputFiles.Length);
        }
Exemple #3
0
        private void Success(PrependAppend prependAppend, string text, LineEndings lineEndings,
                             OutputEncodingType outputEncoding)
        {
            FileInfo file = GetTestFile("Lipsum.txt");
            PrependOrAppendTextProcessor processor = new PrependOrAppendTextProcessor();

            processor.SetParameter("PrependOrAppend", prependAppend);
            processor.SetParameter("Text", text);
            processor.SetParameter("LineEndings", lineEndings);
            processor.SetParameter("OutputEncoding", outputEncoding);
            processor.SetParameter("FileName", GetCurrentTestResultsFilePath("out.txt"));
            processor.SetParameter("OverwriteExistingFile", false);
            processor.SetParameter("MoveOriginalToRecycleBin", false);
            processor.Init(RunInfo);
            ProcessingResult result = processor.Process(file, MatchResultType.Yes, new string[0],
                                                        new FileInfo[0], ProcessInput.OriginalFile, CancellationToken.None);

            processor.Cleanup();
            Assert.AreEqual(ProcessingResultType.Success, result.Type);
            Assert.AreEqual(1, result.OutputFiles.Length);
        }