Exemplo n.º 1
0
 public void Test001BreakoutWithFileAndExtensionOnly()
 {
     var testStr = @"SomefileName.txt";
     var expectedResult = @"SomefileName.txt";
     var filePathDto = new FilePathDto(testStr);
     Assert.IsTrue(filePathDto.FileNameAndExtension == expectedResult);
 }
Exemplo n.º 2
0
        public void Test005ParseFullPath()
        {
            var testStr = @"D:\Level1\Level2\SomefileName.txt";
            var expectedDirPath = @"D:\Level1\Level2\SomefileName.txt";

            var filePathDto = new FilePathDto(testStr);
            Assert.IsTrue(filePathDto.FullPathAndFileName == expectedDirPath);
        }
Exemplo n.º 3
0
        public void Test004ParseDirOnlyNoTrailingSlash()
        {
            var testStr = @"D:\Level1\Level2";
            var expectedDirPath = @"D:\Level1";

            var filePathDto = new FilePathDto(testStr);
            Assert.IsTrue(filePathDto.DirectoryPath == expectedDirPath);
        }
Exemplo n.º 4
0
        public void Test006ParseFullPathOnRelativePath()
        {
            var fInfo = new FileInfo("SomefileName.txt");
            var testStr = @".\SomefileName.txt";
            var expectedDirPath = fInfo.FullName;

            var filePathDto = new FilePathDto(testStr);
            Assert.IsTrue(filePathDto.FullPathAndFileName == expectedDirPath);
        }
Exemplo n.º 5
0
        public ActionResult <string[]> SearchLogsPerDirectory14(FilePathDto file)
        {
            var response = ReadTextFilesService.SearchLogsPerDirectory14(file.filePath);

            if (response is null)
            {
                return(BadRequest());
            }
            return(Ok(response));
        }
Exemplo n.º 6
0
        public ActionResult <List <Duplicate> > ReadFile12(FilePathDto file)
        {
            var response = ReadTextFilesService.ReadFile12(file.filePath);

            if (response is null)
            {
                return(BadRequest());
            }
            return(Ok(response));
        }
        public async System.Threading.Tasks.Task ConvertExcelFileToTextFileTest_FileTestShouldExistAsync()
        {
            string      myPathFromExcelFile = $"..\\..\\..\\FilesTest\\ArchivoCinte2021.xlsx";
            FilePathDto filePath            = new FilePathDto {
                MyPathFromExcelFile = myPathFromExcelFile
            };
            FileService fileService = new FileService();
            bool        response    = await fileService.ConvertExcelFileToTextFile(filePath);

            Assert.AreEqual(true, response);
        }
Exemplo n.º 8
0
 public void Test007ChangeFileNameShouldProcessSuccessfully()
 {
     var testStr = @"D:\Level1\Level2\SomefileName.txt";
     var filePathDto = new FilePathDto(testStr);
     filePathDto.SetFileNameOnly("SomeOtherFileName");
     var expectedDirPath = @"D:\Level1\Level2\SomeOtherFileName.txt";
     Assert.IsTrue(filePathDto.FullPathAndFileName == expectedDirPath);
     Assert.IsTrue(filePathDto.FileNameAndExtension == "SomeOtherFileName.txt");
     Assert.IsTrue(filePathDto.Extension == ".txt");
     Assert.IsTrue(filePathDto.ExtensionWithoutLeadingDot == "txt");
 }
Exemplo n.º 9
0
        public async Task <IActionResult> ConvertExcelFileToTextFile([FromBody] FilePathDto filePath)
        {
            try
            {
                await _fileService.ConvertExcelFileToTextFile(filePath);

                return(Ok("The text file has been created."));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(StatusCode(404, e.Message.ToString()));
            }
        }
Exemplo n.º 10
0
        public void Test002ParseValidFilePathCorrectly()
        {
            var testStr = @"D:\Level1\Level2\SomefileName.txt";
            var expectedFileNameAndExt = @"SomefileName.txt";
            var expectedExt = @".txt";
            var expectedFileNameOnly = @"SomefileName";
            var expectedDirPath = @"D:\Level1\Level2";

            var filePathDto = new FilePathDto(testStr);
            Assert.IsTrue(filePathDto.FileNameAndExtension == expectedFileNameAndExt);
            Assert.IsTrue(filePathDto.DirectoryPath == expectedDirPath);
            Assert.IsTrue(filePathDto.FileNameOnly == expectedFileNameOnly);
            Assert.IsTrue(filePathDto.Extension ==expectedExt);
        }
Exemplo n.º 11
0
        public async Task <bool> ConvertExcelFileToTextFile(FilePathDto filePath)
        {
            Workbook workbook = new Workbook();

            try
            {
                string myDirectoryToTextFile = $"{Directory.GetCurrentDirectory()}\\Files";
                workbook.LoadFromFile(filePath.MyPathFromExcelFile);
                Worksheet sheet = workbook.Worksheets[0];
                string    pathFileTxtWithoutFormat = $"{myDirectoryToTextFile}\\AWSCinte.txt";
                sheet.SaveToFile(pathFileTxtWithoutFormat, "|");
                await FormatFileTxt(myDirectoryToTextFile);

                File.Delete(pathFileTxtWithoutFormat);
            }
            catch (Exception)
            {
                throw;
            }

            return(true);
        }
Exemplo n.º 12
0
        public ActionResult <int> CountDuplicate13(FilePathDto file)
        {
            var response = ReadTextFilesService.CountDuplicate13(file.filePath);

            return(Ok(response));
        }
Exemplo n.º 13
0
        private bool ValidateFileInputString(string fileStr)
        {
            if (string.IsNullOrWhiteSpace(fileStr))
            {
                return false;
            }

            try
            {
                _filePathDto = new FilePathDto(fileStr);

                if (_filePathDto.FileNameAndExtension == string.Empty)
                {
                    return false;
                }

            }
            catch
            {
                return false;
            }

            return true;
        }
Exemplo n.º 14
0
        public FileDto ExtractLogFileDto(string cmdConsoleLogPathFileName,
														string logFileTimeStamp)
        {
            var filePath = new FilePathDto(cmdConsoleLogPathFileName);

            var sb = new StringBuilder();

            if (filePath.HasDirectoryPath)
            {
                sb.Append(Path.Combine(filePath.DirectoryPath, filePath.FileNameOnly));
            }
            else
            {
                sb.Append(filePath.FileNameOnly);
            }

            sb.Append("_" + logFileTimeStamp);

            if (filePath.HasExtension)
            {
                if (filePath.Extension.Contains("."))
                {
                    sb.Append(filePath.Extension);
                }
                else
                {
                    sb.Append(".");
                    sb.Append(filePath.Extension);
                }
            }

            return new FileDto(sb.ToString());
        }