System.CodeDom.Tests.TempFileCollectionTests.AddFile_MultipleFiles_DeletesAllIfKeepFilesFalse C# (CSharp) Method

AddFile_MultipleFiles_DeletesAllIfKeepFilesFalse() private method

private AddFile_MultipleFiles_DeletesAllIfKeepFilesFalse ( bool keepFiles ) : void
keepFiles bool
return void
        public void AddFile_MultipleFiles_DeletesAllIfKeepFilesFalse(bool keepFiles)
        {
            string directory = TempDirectory();
            string filePath1 = Path.Combine(directory, "file1.extension");
            string filePath2 = Path.Combine(directory, "file2.extension");

            File.Create(filePath1).Dispose();
            File.Create(filePath2).Dispose();

            try
            {
                using (var collection = new TempFileCollection(directory))
                {
                    collection.AddFile(filePath1, keepFiles);
                    collection.AddFile(filePath2, keepFiles);
                }

                Assert.Equal(keepFiles, File.Exists(filePath1));
                Assert.Equal(keepFiles, File.Exists(filePath2));
            }
            finally
            {
                if (File.Exists(filePath1))
                {
                    File.Delete(filePath1);
                }
                if (File.Exists(filePath2))
                {
                    File.Delete(filePath2);
                }
            }
        }