public void getThreeFileNames()
        {
            var baseFileName      = "test";
            var fileExtension     = "tmp";
            var baseDirectory     = "D:\\";
            var fileNameBegin     = baseDirectory + baseFileName;
            var fileNameEnd       = "." + fileExtension;
            var fileNameGenerator = new TemporaryFileNameGenerator(baseFileName, fileExtension, baseDirectory);
            var fileExistsChecker = Substitute.For <IFileExistsChecker>();

            fileExistsChecker.FileExists(string.Empty).ReturnsForAnyArgs(
                false, true, false, true, true, false);
            fileNameGenerator.FileExistsChecker = fileExistsChecker;
            var actualFileNames   = new string[3];
            var expectedFileNames = new string[3]
            {
                fileNameBegin + fileNameEnd,
                fileNameBegin + "2" + fileNameEnd,
                fileNameBegin + "3" + fileNameEnd
            };

            for (var i = 0; i < 3; i++)
            {
                actualFileNames[i] = fileNameGenerator.GetNextAvailableName();
            }

            CollectionAssert.AreEqual(expectedFileNames, actualFileNames);
        }
        public void getFileName_ProvidedNameStringsContainIllegalCharacters_IllegalCharactersShouldBeRemoves()
        {
            var fileNameGenerator = new TemporaryFileNameGenerator("T:E?S|t", ".tmp", "D:\\");
            var expectedFilePath  = "D:\\TESt.tmp";

            var actualFilePath = fileNameGenerator.GetNextAvailableName();

            Assert.AreEqual(expectedFilePath, actualFilePath);
        }
Exemplo n.º 3
0
        public static void SwapFileNames(string pathToFile1, string pathToFile2)
        {
            if (pathToFile1 == pathToFile2)
            {
                return;
            }
            var temporaryFileNameGenerator = new TemporaryFileNameGenerator();
            var tempName = "D:\\" + temporaryFileNameGenerator.GetNextAvailableName();

            File.Move(pathToFile1, tempName);
            File.Move(pathToFile2, pathToFile1);
            File.Move(tempName, pathToFile2);
        }
Exemplo n.º 4
0
        protected void initializeFileBasesOfTempFiles()
        {
            fileBases = new IFileIOBase[numberOfFiles];
            var fileNameGenerator = new TemporaryFileNameGenerator("TmpBuffer", "buf",
                                                                   FileParameters.TemporaryBufferFileDirectory);

            for (var i = 0; i < numberOfFiles; i++)
            {
                if (i == indexOfSourceFile)
                {
                    fileBases[i] = new FileIOBasics(FileParameters.SourceFileName, FileParameters.BlockSize);
                }
                else
                {
                    fileBases[i] =
                        new FileIOBasics(fileNameGenerator.GetNextAvailableName(), FileParameters.BlockSize, true);
                }
            }
        }