public void TestUnexistingFolder() { string unexistedFolder; do { unexistedFolder = "E:\\" + DateTime.Now.Ticks.ToString(); } while (Directory.Exists(unexistedFolder)); bool wasCreated = ProcessExcel.TryCreateCsv(Path.Combine(Environment.CurrentDirectory, "TestData", "TestExcel2003.xls"), unexistedFolder + "\\"); Assert.AreEqual(wasCreated, false); }
/// <summary> /// Internal method to process excel file with expected worksheets /// </summary> /// <param name="fileName">fileName (note that this file should be placed in TestData folder</param> /// <param name="expectedCsvFiles">the expected count of correct worksheets</param> /// <param name="isExpectedCorrectWorkbook">do we expect that workbook at filename is correct</param> private void TestTryCreateCsv(string fileName, int expectedCsvFiles, bool isExpectedCorrectWorkbook) { string nameForOutputDirectory = Path.Combine(Environment.CurrentDirectory, "TestData", DateTime.Now.Ticks.ToString()); Directory.CreateDirectory(nameForOutputDirectory); // create directory for output csv IProcessWorkbookResult resultProcessing; var wasFileProcessed = ProcessExcel.TryCreateCsv(Path.Combine(Environment.CurrentDirectory, "TestData", fileName), nameForOutputDirectory + "\\"); var filesCollection = Directory.GetFiles(nameForOutputDirectory, "*.csv"); Directory.Delete(nameForOutputDirectory, true); // delete temp data (NOTE, we do this before Assert to avoid dirty folders) Assert.AreEqual(wasFileProcessed, isExpectedCorrectWorkbook); if (wasFileProcessed) { Assert.AreEqual(expectedCsvFiles, filesCollection.Length); } }