diff --git a/main/Util/TempFile.cs b/main/Util/TempFile.cs index fa0eaa28b..5981878da 100644 --- a/main/Util/TempFile.cs +++ b/main/Util/TempFile.cs @@ -18,31 +18,38 @@ public class TempFile */ public static FileInfo CreateTempFile(String prefix, String suffix) { - - if (dir == null) + if (string.IsNullOrWhiteSpace(dir)) { - dir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "poifiles")).FullName; + string tempDir = Path.Combine(Path.GetTempPath(), "poifiles"); + dir = Directory.CreateDirectory(tempDir).FullName; } + + if (!Directory.Exists(dir)) + Directory.CreateDirectory(dir); + // Generate a unique new filename string file = Path.Combine(dir, prefix + Guid.NewGuid().ToString() + suffix); while (File.Exists(file)) { file = Path.Combine(dir, prefix + Guid.NewGuid().ToString() + suffix); - Thread.Sleep(1); } - FileStream newFile = new FileStream(file, FileMode.CreateNew, FileAccess.ReadWrite); - newFile.Close(); + + using (FileStream newFile = new FileStream(file, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite)) { }; return new FileInfo(file); } public static string GetTempFilePath(String prefix, String suffix) { - if (dir == null) + if (string.IsNullOrWhiteSpace(dir)) { - dir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "poifiles")).FullName; + string tempDir = Path.Combine(Path.GetTempPath(), "poifiles"); + dir = Directory.CreateDirectory(tempDir).FullName; } + if (!Directory.Exists(dir)) + Directory.CreateDirectory(dir); + Random rnd = new Random(DateTime.Now.Millisecond); rnd.Next(); Thread.Sleep(10); diff --git a/ooxml/XSSF/Streaming/SheetDataWriter.cs b/ooxml/XSSF/Streaming/SheetDataWriter.cs index c8098be2f..270ac1762 100644 --- a/ooxml/XSSF/Streaming/SheetDataWriter.cs +++ b/ooxml/XSSF/Streaming/SheetDataWriter.cs @@ -116,23 +116,13 @@ public void Close() { try { - _outputWriter.Flush(); - OutputStream.Flush(); + _outputWriter.Dispose(); + OutputStream.Dispose(); } catch { } - try - { - OutputStream.Close(); - } - catch - { - - } - - } public FileInfo TempFileInfo @@ -554,6 +544,7 @@ public bool Dispose() bool ret; try { + _outputWriter.Close(); OutputStream.Close(); } finally diff --git a/testcases/main/RunSerialyAndSweepTmpFilesAttribute.cs b/testcases/main/RunSerialyAndSweepTmpFilesAttribute.cs deleted file mode 100644 index 854031fd3..000000000 --- a/testcases/main/RunSerialyAndSweepTmpFilesAttribute.cs +++ /dev/null @@ -1,53 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -using System; -using System.IO; -using System.Threading; -using NUnit.Framework; -using NUnit.Framework.Interfaces; - -namespace TestCases -{ - [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] - public sealed class RunSerialyAndSweepTmpFilesAttribute : Attribute, ITestAction - { - private static object syncSequential = new object(); - - public ActionTargets Targets { get { return ActionTargets.Test; } } - - private static void SweepTemporaryFiles() - { - foreach (var tempFilePath in Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.tmp")) - { - File.Delete(tempFilePath); - } - } - - public void BeforeTest(ITest test) - { - Monitor.Enter(syncSequential); - SweepTemporaryFiles(); - } - - public void AfterTest(ITest test) - { - SweepTemporaryFiles(); - Monitor.Exit(syncSequential); - } - } -} diff --git a/testcases/main/Util/TestTempFile.cs b/testcases/main/Util/TestTempFile.cs new file mode 100644 index 000000000..9ff4df207 --- /dev/null +++ b/testcases/main/Util/TestTempFile.cs @@ -0,0 +1,80 @@ +using NPOI.Util; +using NUnit.Framework; +using System.IO; +using System.Threading; + +namespace TestCases.Util +{ + /// + /// Tests of creating temp files + /// + [TestFixture] + internal class TestTempFile + { + [Test] + public void TestCreateTempFile() + { + FileInfo fileInfo = null; + Assert.DoesNotThrow(() => fileInfo = TempFile.CreateTempFile("test", ".xls")); + + Assert.IsTrue(fileInfo!=null && fileInfo.Exists); + + string tempDirPath = Path.GetDirectoryName(fileInfo.FullName); + + while(Directory.Exists(tempDirPath)) + { + try + { + Directory.Delete(tempDirPath, true); + } + catch + { + Thread.Sleep(5); + } + } + + Assert.IsFalse(Directory.Exists(tempDirPath)); + + if(fileInfo!=null) + { + fileInfo.Refresh(); + Assert.IsFalse(fileInfo.Exists); + } + + FileInfo file = null; + Assert.DoesNotThrow(() => file = TempFile.CreateTempFile("test2", ".xls")); + Assert.IsTrue(Directory.Exists(tempDirPath)); + + if(file !=null && file.Exists) + file.Delete(); + } + + [Test] + public void TestGetTempFilePath() + { + string path = ""; + Assert.DoesNotThrow(() => path = TempFile.GetTempFilePath("test", ".xls")); + + Assert.IsTrue(!string.IsNullOrWhiteSpace(path)); + + string tempDirPath = Path.GetDirectoryName(path); + + while(Directory.Exists(tempDirPath)) + { + try + { + Directory.Delete(tempDirPath, true); + } + catch + { + Thread.Sleep(10); + } + } + + Assert.IsFalse(Directory.Exists(tempDirPath)); + + Assert.DoesNotThrow(() => TempFile.GetTempFilePath("test", ".xls")); + Assert.IsTrue(Directory.Exists(tempDirPath)); + } + } +} diff --git a/testcases/ooxml/XSSF/Streaming/GZIPSheetDataWriterTests.cs b/testcases/ooxml/XSSF/Streaming/GZIPSheetDataWriterTests.cs index ccda284ae..77ffa004d 100644 --- a/testcases/ooxml/XSSF/Streaming/GZIPSheetDataWriterTests.cs +++ b/testcases/ooxml/XSSF/Streaming/GZIPSheetDataWriterTests.cs @@ -31,11 +31,10 @@ public void CleanUp() { if (_objectToTest != null) { + _objectToTest.Dispose(); + if (File.Exists(_objectToTest.TemporaryFilePath())) - { - _objectToTest.Dispose(); File.Delete(_objectToTest.TemporaryFilePath()); - } } } [Test] diff --git a/testcases/ooxml/XSSF/Streaming/SXSSFWorkbookTests.cs b/testcases/ooxml/XSSF/Streaming/SXSSFWorkbookTests.cs index b882c058b..07395bf0f 100644 --- a/testcases/ooxml/XSSF/Streaming/SXSSFWorkbookTests.cs +++ b/testcases/ooxml/XSSF/Streaming/SXSSFWorkbookTests.cs @@ -14,15 +14,12 @@ the License. You may obtain a copy of the License at See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; using NPOI.SS.UserModel; using NPOI.XSSF.Streaming; using NPOI.XSSF.UserModel; using NUnit.Framework; +using System; +using System.IO; namespace TestCases.XSSF.Streaming { @@ -31,6 +28,13 @@ class SXSSFWorkbookTests { private SXSSFWorkbook _objectToTest { get; set; } + [TearDown] + public void CleanUp() + { + if (_objectToTest != null) + _objectToTest.Dispose(); + } + [Test] public void CallingEmptyConstructorShouldInstanstiateNewXssfWorkbookDefaultRowAccessWindowSizeCompressTempFilesAsFalseAndUseSharedStringsTableFalse @@ -76,6 +80,8 @@ public void IfCompressTmpFilesIsSetToTrueShouldReturnGZIPSheetDataWriter() Assert.IsTrue(result is GZIPSheetDataWriter); + if (result != null) + result.Close(); } [Test] @@ -86,6 +92,8 @@ public void IfCompressTmpFilesIsSetToFalseShouldReturnSheetDataWriter() Assert.IsTrue(result is SheetDataWriter); + if (result != null) + result.Close(); } [Test] @@ -111,7 +119,6 @@ public void IfSettingSelectedTabShouldSetSelectedTabOfXssfWorkbook() _objectToTest.SetSelectedTab(0); Assert.IsTrue(_objectToTest.GetSheetAt(0).IsSelected); - } [Test] @@ -124,7 +131,6 @@ public void IfSheetNameByIndexShouldGetSheetNameFromXssfWorkbook() _objectToTest.SetSelectedTab(0); Assert.IsTrue(_objectToTest.GetSheetAt(0).IsSelected); - } [Test] @@ -135,7 +141,6 @@ public void IfSettingSheetNameShouldChangeTheSheetNameAtTheSpecifiedIndex() _objectToTest.SetSheetName(0, "renamed"); Assert.AreEqual("renamed", _objectToTest.GetSheetAt(0).SheetName); - } [Test] @@ -199,10 +204,8 @@ public void IfGivenTheNameOfAnExistingSheetShouldReturnTheSheet() Assert.AreEqual("1", sheet1.SheetName); Assert.AreEqual("2", sheet2.SheetName); - } - [Test] public void IfGivenTheIndexOfAnExistingSheetShouldReturnTheSheet() { @@ -215,7 +218,6 @@ public void IfGivenTheIndexOfAnExistingSheetShouldReturnTheSheet() Assert.AreEqual("1", sheet1.SheetName); Assert.AreEqual("2", sheet2.SheetName); - } [Test] @@ -451,7 +453,6 @@ public void IfWriting20WorksheetsWith10000x100CellsUsingGzipShouldNotThrowOutOfM File.Delete(savePath); } - private void AddCells(IWorkbook wb, int sheets, int rows, int columns, CellType type) { for (int j = 0; j < sheets; j++) @@ -468,7 +469,6 @@ private void AddCells(IWorkbook wb, int sheets, int rows, int columns, CellType } } - private void WriteFile(string saveAsPath, SXSSFWorkbook wb) { //Passing SXSSFWorkbook because IWorkbook does not implement .Dispose which cleans ups temporary files. diff --git a/testcases/ooxml/XSSF/Streaming/SheetDataWriterTests.cs b/testcases/ooxml/XSSF/Streaming/SheetDataWriterTests.cs index ca504036a..b2778ca25 100644 --- a/testcases/ooxml/XSSF/Streaming/SheetDataWriterTests.cs +++ b/testcases/ooxml/XSSF/Streaming/SheetDataWriterTests.cs @@ -45,11 +45,10 @@ public void CleanUp() { if (_objectToTest != null) { + _objectToTest.Dispose(); + if (File.Exists(_objectToTest.TemporaryFilePath())) - { - _objectToTest.Dispose(); File.Delete(_objectToTest.TemporaryFilePath()); - } } } diff --git a/testcases/ooxml/XSSF/Streaming/TestSXSSFWorkbook.cs b/testcases/ooxml/XSSF/Streaming/TestSXSSFWorkbook.cs index d0c37a37b..fbe18d5af 100644 --- a/testcases/ooxml/XSSF/Streaming/TestSXSSFWorkbook.cs +++ b/testcases/ooxml/XSSF/Streaming/TestSXSSFWorkbook.cs @@ -42,15 +42,12 @@ public class TestSXSSFWorkbook : BaseTestXWorkbook public TestSXSSFWorkbook() : base(SXSSFITestDataProvider.instance) { - } - [TearDown] public void TearDown() { //((SXSSFITestDataProvider)_testDataProvider).Cleanup(); } - /** * cloning of sheets is not supported in SXSSF */ @@ -63,7 +60,7 @@ public override void CloneSheet() base.CloneSheet(); Assert.Fail("expected exception"); } - catch (RuntimeException e) + catch(RuntimeException e) { Assert.AreEqual("NotImplemented", e.Message); } @@ -76,7 +73,7 @@ public override void SheetClone() base.SheetClone(); Assert.Fail("expected exception"); } - catch (RuntimeException e) + catch(RuntimeException e) { Assert.AreEqual("NotImplemented", e.Message); } @@ -271,10 +268,10 @@ public void GzipSheetdataWriter() wb.CompressTempFiles = true; int rowNum = 1000; int sheetNum = 5; - for (int i = 0; i < sheetNum; i++) + for(int i = 0; i < sheetNum; i++) { ISheet sh = wb.CreateSheet("sheet" + i); - for (int j = 0; j < rowNum; j++) + for(int j = 0; j < rowNum; j++) { IRow row = sh.CreateRow(j); ICell cell1 = row.CreateCell(0); @@ -289,11 +286,11 @@ public void GzipSheetdataWriter() } XSSFWorkbook xwb = SXSSFITestDataProvider.instance.WriteOutAndReadBack(wb) as XSSFWorkbook; - for (int i = 0; i < sheetNum; i++) + for(int i = 0; i < sheetNum; i++) { ISheet sh = xwb.GetSheetAt(i); Assert.AreEqual("sheet" + i, sh.SheetName); - for (int j = 0; j < rowNum; j++) + for(int j = 0; j < rowNum; j++) { IRow row = sh.GetRow(j); Assert.IsNotNull(row, "row[" + j + "]"); @@ -301,10 +298,10 @@ public void GzipSheetdataWriter() Assert.AreEqual(new CellReference(cell1).FormatAsString(), cell1.StringCellValue); ICell cell2 = row.GetCell(1); - Assert.AreEqual(i, (int)cell2.NumericCellValue); + Assert.AreEqual(i, (int) cell2.NumericCellValue); ICell cell3 = row.GetCell(2); - Assert.AreEqual(j, (int)cell3.NumericCellValue); + Assert.AreEqual(j, (int) cell3.NumericCellValue); } } @@ -317,10 +314,10 @@ protected static void assertWorkbookDispose(SXSSFWorkbook wb) { int rowNum = 1000; int sheetNum = 5; - for (int i = 0; i < sheetNum; i++) + for(int i = 0; i < sheetNum; i++) { ISheet sh = wb.CreateSheet("sheet" + i); - for (int j = 0; j < rowNum; j++) + for(int j = 0; j < rowNum; j++) { IRow row = sh.CreateRow(j); ICell cell1 = row.CreateCell(0); @@ -334,7 +331,7 @@ protected static void assertWorkbookDispose(SXSSFWorkbook wb) } } - foreach (ISheet sheet in wb) + foreach(ISheet sheet in wb) { SXSSFSheet sxSheet = (SXSSFSheet)sheet; Assert.IsTrue(sxSheet.SheetDataWriter.TempFileInfo.Exists); @@ -342,7 +339,7 @@ protected static void assertWorkbookDispose(SXSSFWorkbook wb) Assert.IsTrue(wb.Dispose()); - foreach (ISheet sheet in wb) + foreach(ISheet sheet in wb) { SXSSFSheet sxSheet = (SXSSFSheet)sheet; Assert.IsFalse(sxSheet.SheetDataWriter.TempFileInfo.Exists); @@ -384,14 +381,14 @@ public void Bug53515a() { FileInfo out1 = new FileInfo("Test.xlsx"); out1.Delete(); - for (int i = 0; i < 2; i++) + for(int i = 0; i < 2; i++) { Console.WriteLine("Iteration " + i); SXSSFWorkbook wb; - if (out1.Exists) + if(out1.Exists) { wb = new SXSSFWorkbook( - (XSSFWorkbook)WorkbookFactory.Create(out1.FullName)); + (XSSFWorkbook) WorkbookFactory.Create(out1.FullName)); } else { @@ -401,7 +398,7 @@ public void Bug53515a() try { FileStream outSteam = new FileStream(out1.FullName, FileMode.Create, FileAccess.ReadWrite); - if (i == 0) + if(i == 0) { populateWorkbook(wb); } @@ -431,10 +428,10 @@ public void Bug53515a() private static void populateWorkbook(IWorkbook wb) { ISheet sh = wb.CreateSheet(); - for (int rownum = 0; rownum < 100; rownum++) + for(int rownum = 0; rownum < 100; rownum++) { IRow row = sh.CreateRow(rownum); - for (int cellnum = 0; cellnum < 10; cellnum++) + for(int cellnum = 0; cellnum < 10; cellnum++) { ICell cell = row.CreateCell(cellnum); String Address = new CellReference(cell).FormatAsString(); @@ -445,7 +442,7 @@ private static void populateWorkbook(IWorkbook wb) private static void saveTwice(IWorkbook wb) { - for (int i = 0; i < 2; i++) + for(int i = 0; i < 2; i++) { try { @@ -453,7 +450,7 @@ private static void saveTwice(IWorkbook wb) wb.Write(out1, false); out1.Close(); } - catch (Exception e) + catch(Exception e) { throw new Exception("ERROR: failed on " + (i + 1) + "th time calling " + wb.GetType().Name @@ -469,19 +466,19 @@ public void TestTemplateFile() XSSFWorkbook workBook = XSSFTestDataSamples.OpenSampleWorkbook("sample.xlsx"); SXSSFWorkbook streamingWorkBook = new SXSSFWorkbook(workBook, 10); ISheet sheet = streamingWorkBook.GetSheet("Sheet1"); - for (int rowNum = 10; rowNum < 1000000; rowNum++) + for(int rowNum = 10; rowNum < 1000000; rowNum++) { IRow row = sheet.CreateRow(rowNum); - for (int cellNum = 0; cellNum < 700; cellNum++) + for(int cellNum = 0; cellNum < 700; cellNum++) { ICell cell = row.CreateCell(cellNum); cell.SetCellValue("somEvalue"); } - if (rowNum % 100 == 0) + if(rowNum % 100 == 0) { Console.Write("."); - if (rowNum % 10000 == 0) + if(rowNum % 10000 == 0) { Console.WriteLine(rowNum); } @@ -525,11 +522,11 @@ public void closeDoesNotModifyWorkbook() } finally { - if (xwb != null) + if(xwb != null) { xwb.Close(); } - if (wb != null) + if(wb != null) { wb.Close(); } @@ -555,10 +552,10 @@ public void TestZipBombNotTriggeredOnUselessContent() char[] useless = new char[32767]; Arrays.Fill(useless, ' '); - for (int row = 0; row < 1; row++) + for(int row = 0; row < 1; row++) { IRow r = s.CreateRow(row); - for (int col = 0; col < 10; col++) + for(int col = 0; col < 10; col++) { char[] prefix = HexDump.ToHex(row * 1000 + col).ToCharArray(); Arrays.Fill(useless, 0, 10, ' '); @@ -593,7 +590,7 @@ public void CreateFromReadOnlyWorkbook() String sheetName = "Test SXSSF"; ISheet s = wb.CreateSheet(sheetName); - for (int i = 0; i < 10; i++) + for(int i = 0; i < 10; i++) { IRow r = s.CreateRow(i); r.CreateCell(0).SetCellValue(true); diff --git a/testcases/ooxml/XSSF/UserModel/TestXSSFBugs.cs b/testcases/ooxml/XSSF/UserModel/TestXSSFBugs.cs index 204b750e9..84268cfe2 100644 --- a/testcases/ooxml/XSSF/UserModel/TestXSSFBugs.cs +++ b/testcases/ooxml/XSSF/UserModel/TestXSSFBugs.cs @@ -2707,7 +2707,7 @@ public void Bug57642() * 32,767 must not be -32,768, then -32,767, -32,766 * long time test, run over 1 minute. */ - [Test, RunSerialyAndSweepTmpFiles] + [Test] [Ignore("this test doesn't make sense")] public void Bug57880() { diff --git a/testcases/ooxml/XSSF/UserModel/TestXSSFWorkbook.cs b/testcases/ooxml/XSSF/UserModel/TestXSSFWorkbook.cs index 7bb613037..738b28afd 100644 --- a/testcases/ooxml/XSSF/UserModel/TestXSSFWorkbook.cs +++ b/testcases/ooxml/XSSF/UserModel/TestXSSFWorkbook.cs @@ -51,7 +51,7 @@ public TestXSSFWorkbook() /** * Tests that we can save, and then re-load a new document */ - [Test, RunSerialyAndSweepTmpFiles] + [Test] public void SaveLoadNew() { XSSFWorkbook wb1 = new XSSFWorkbook(); @@ -121,9 +121,8 @@ public void SaveLoadNew() Assert.AreEqual("hello world", sheet1.GetRow(1).GetCell(0).RichStringCellValue.String); pkg.Close(); - - Assert.AreEqual(0, Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.tmp").Length, "At Last: There are no temporary files."); } + [Test] public void Existing() { @@ -912,15 +911,19 @@ public void TestSetVBAProject() allBytes[i] = (byte)(i - 128); } - XSSFWorkbook wb1 = new XSSFWorkbook(); - wb1.CreateSheet(); - wb1.SetVBAProject(new ByteArrayInputStream(allBytes)); - file = TempFile.CreateTempFile("poi-", ".xlsm"); - Stream out1 = new FileStream(file.FullName, FileMode.Open, FileAccess.ReadWrite); - wb1.Write(out1); - out1.Close(); - wb1.Close(); + using(XSSFWorkbook wb1 = new XSSFWorkbook()) + { + wb1.CreateSheet(); + wb1.SetVBAProject(new ByteArrayInputStream(allBytes)); + file = TempFile.CreateTempFile("poi-", ".xlsm"); + using(Stream out1 = new FileStream(file.FullName, FileMode.Open, FileAccess.ReadWrite)) + { + wb1.Write(out1); + } + } + if(file != null) + file.Refresh(); // Check the package contains what we'd expect it to OPCPackage pkg = OPCPackage.Open(file); diff --git a/testcases/openxml4net/OPC/Compliance/TestOPCComplianceCoreProperties.cs b/testcases/openxml4net/OPC/Compliance/TestOPCComplianceCoreProperties.cs index 6f6d68326..9d91b479e 100644 --- a/testcases/openxml4net/OPC/Compliance/TestOPCComplianceCoreProperties.cs +++ b/testcases/openxml4net/OPC/Compliance/TestOPCComplianceCoreProperties.cs @@ -287,7 +287,7 @@ public void TestNoCoreProperties_saveNew() * Document with no core properties - testing at the OPC level, * from a temp-file, saving in-place */ - [Test, RunSerialyAndSweepTmpFiles] + [Test] public void TestNoCoreProperties_saveInPlace() { String sampleFileName = "OPCCompliance_NoCoreProperties.xlsx"; @@ -328,8 +328,7 @@ public void TestNoCoreProperties_saveInPlace() pkg.Revert(); tmp.Delete(); - Assert.AreEqual(0, Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.tmp").Length, "At Last: There are no temporary files."); + Assert.IsFalse(File.Exists(tmp.FullName), $"{tmp.FullName} file exists!"); } - } } \ No newline at end of file diff --git a/testcases/openxml4net/TestPackage.cs b/testcases/openxml4net/TestPackage.cs index a921e6779..5bd3d73c1 100644 --- a/testcases/openxml4net/TestPackage.cs +++ b/testcases/openxml4net/TestPackage.cs @@ -166,7 +166,7 @@ public void TestCreatePackageAddPart() * document and another part, save and re-load and * have everything Setup as expected */ - [Test, RunSerialyAndSweepTmpFiles] + [Test] //[Ignore("add relation Uri #Sheet1!A1")] public void TestCreatePackageWithCoreDocument() { @@ -256,8 +256,6 @@ public void TestCreatePackageWithCoreDocument() { pkg.Close(); } - - Assert.AreEqual(0, Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.tmp").Length, "At Last: There are no temporary files."); } private void assertMSCompatibility(OPCPackage pkg) @@ -282,7 +280,7 @@ private void assertMSCompatibility(OPCPackage pkg) /** * Test namespace opening. */ - [Test, RunSerialyAndSweepTmpFiles] + [Test] public void TestOpenPackage() { FileInfo targetFile = OpenXml4NetTestDataSamples.GetOutputFile("TestOpenPackageTMP.docx"); @@ -344,7 +342,7 @@ public void TestOpenPackage() ZipFileAssert.AssertEqual(expectedFile, targetFile); File.Delete(targetFile.FullName); - Assert.AreEqual(0, Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.tmp").Length, "At Last: There are no temporary files."); + Assert.IsFalse(File.Exists(targetFile.FullName), $"{targetFile.FullName} file exists!"); } /** @@ -531,7 +529,7 @@ public void TestDeletePartRecursive() * Test that we can open a file by path, and then * write Changes to it. */ - [Test, RunSerialyAndSweepTmpFiles, Platform("Win")] + [Test, Platform("Win")] public void TestOpenFileThenOverWrite() { string tempFile = TempFile.GetTempFilePath("poiTesting", "tmp"); @@ -568,13 +566,13 @@ public void TestOpenFileThenOverWrite() p.Close(); File.Delete(tempFile); - Assert.AreEqual(0, Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.tmp").Length, "At Last: There are no temporary files."); + Assert.IsFalse(File.Exists(tempFile), $"{tempFile} file exists!"); } /** * Test that we can open a file by path, save it * to another file, then delete both */ - [Test, RunSerialyAndSweepTmpFiles] + [Test] public void TestOpenFileThenSaveDelete() { string tempFile = TempFile.GetTempFilePath("poiTesting", "tmp"); @@ -593,7 +591,8 @@ public void TestOpenFileThenSaveDelete() File.Delete(tempFile); File.Delete(tempFile2); - Assert.AreEqual(0, Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.tmp").Length, "At Last: There are no temporary files."); + Assert.IsFalse(File.Exists(tempFile), $"{tempFile} file exists!"); + Assert.IsFalse(File.Exists(tempFile2), $"{tempFile2} file exists!"); } private static ContentTypeManager GetContentTypeManager(OPCPackage pkg)