示例#1
0
        public void GetLastesFileWithSameName_TenFilesWithSameNameExist_FileNameWithNumberNine()
        {
            // Arrange
            string fileName = "somefilename";

            File.WriteAllText(Path.Combine(WorkingPath, fileName + ".txt"), "");
            for (int i = 1; i < 10; i++)
            {
                File.WriteAllText(Path.Combine(WorkingPath, fileName + i + ".txt"), "");
            }

            var fileSizeComparatorMock = new Mock <IFileSizeComparator>();
            var fileNameCreatorMock    = new Mock <IFileNameCreator>();
            var directoryWrapper       = new DirectoryWrapper();

            var fileAnalyzer = new FileAnalyzer(fileSizeComparatorMock.Object, fileNameCreatorMock.Object, directoryWrapper)
            {
                LogPath  = WorkingPath,
                FileName = fileName + ".txt"
            };

            // Act
            var result = fileAnalyzer.GetLastesFileWithSameName();

            // Assert
            Assert.AreEqual(fileName + "9" + ".txt", Path.GetFileName(result));
        }
示例#2
0
        public void GetLastesFileWithSameName_ThreeFilesExistWithSameNameButNumberNotOrdered_FileNameWithHigherNumber()
        {
            // Arrange
            string fileName = "somefilename";

            int higherNumber = 25;

            File.WriteAllText(Path.Combine(WorkingPath, fileName + higherNumber + ".txt"), "");
            File.WriteAllText(Path.Combine(WorkingPath, fileName + "5" + ".txt"), "");
            File.WriteAllText(Path.Combine(WorkingPath, fileName + "20" + ".txt"), "");

            var fileSizeComparatorMock = new Mock <IFileSizeComparator>();
            var fileNameCreatorMock    = new Mock <IFileNameCreator>();
            var directoryWrapper       = new DirectoryWrapper();

            var fileAnalyzer = new FileAnalyzer(fileSizeComparatorMock.Object, fileNameCreatorMock.Object, directoryWrapper)
            {
                LogPath  = WorkingPath,
                FileName = fileName + ".txt"
            };

            // Act
            var result = fileAnalyzer.GetLastesFileWithSameName();

            // Assert
            Assert.AreEqual(fileName + higherNumber + ".txt", Path.GetFileName(result));
        }
示例#3
0
        public void GetLastesFileWithSameName_FileWithSameDoesNotExist_Null()
        {
            // Arrange
            string fileName = "somefilename.txt";

            var fileSizeComparatorMock = new Mock <IFileSizeComparator>();
            var fileNameCreatorMock    = new Mock <IFileNameCreator>();
            var directoryWrapper       = new DirectoryWrapper();

            var fileNameAnalyzer = new FileAnalyzer(fileSizeComparatorMock.Object, fileNameCreatorMock.Object, directoryWrapper)
            {
                LogPath  = WorkingPath,
                FileName = fileName
            };

            // Act
            var result = fileNameAnalyzer.GetLastesFileWithSameName();

            // Assert
            Assert.AreEqual(string.Empty, result);
        }
示例#4
0
        public void GetLastesFileWithSameName_FileWithSameNameExistWithoutNumbers_FileName()
        {
            // Arrange
            string fileName = "somefilename.txt";

            File.WriteAllText(Path.Combine(WorkingPath, fileName), "");

            var fileSizeComparatorMock = new Mock <IFileSizeComparator>();
            var fileNameCreatorMock    = new Mock <IFileNameCreator>();
            var directoryWrapper       = new DirectoryWrapper();

            var fileAnalyzer = new FileAnalyzer(fileSizeComparatorMock.Object, fileNameCreatorMock.Object, directoryWrapper)
            {
                LogPath  = WorkingPath,
                FileName = fileName
            };

            // Act
            var result = fileAnalyzer.GetLastesFileWithSameName();

            // Assert
            Assert.AreEqual(fileName, Path.GetFileName(result));
        }