namespace System.Net.Mail.Tests
{
- public class SmtpClientTest : IDisposable
+ public class SmtpClientTest : FileCleanupTestBase
{
private SmtpClient _smtp;
- private string _tempFolder;
private SmtpClient Smtp
{
{
get
{
- if (_tempFolder == null)
- {
- _tempFolder = Path.Combine(Path.GetTempPath(), GetType().FullName, Guid.NewGuid().ToString());
- if (Directory.Exists(_tempFolder))
- Directory.Delete(_tempFolder, true);
-
- Directory.CreateDirectory(_tempFolder);
- }
-
- return _tempFolder;
+ return TestDirectory;
}
}
- public void Dispose()
+ protected override void Dispose(bool disposing)
{
if (_smtp != null)
{
_smtp.Dispose();
}
-
- if (Directory.Exists(_tempFolder))
- Directory.Delete(_tempFolder, true);
+ base.Dispose(disposing);
}
[Theory]
AppContext.SetSwitch("Switch.System.Xml.AllowDefaultResolver", true);
string expected = @"<?xml version=""1.0"" encoding=""utf-8""?><result>123</result>";
+ string fileName = GetType().Name + "_" + Path.GetRandomFileName();
+ string testFile = Path.Combine(Path.GetTempPath(), fileName);
+ string xmlFile = FullFilePath(fileName);
// copy file on the local machine
try
{
- string tempPath = Path.GetTempPath();
- string testFile = Path.Combine(tempPath, "xmlResolver_document_function.xml");
- if (File.Exists(testFile))
- {
- File.SetAttributes(testFile, FileAttributes.Normal);
- File.Delete(testFile);
- }
- string xmlFile = FullFilePath("xmlResolver_document_function.xml");
File.Copy(xmlFile, testFile, true);
}
catch (Exception e)
_output.WriteLine("Could not copy file to local. Some other issues prevented this test from running");
return; //TEST_SKIPPED;
}
+ finally
+ {
+ if (File.Exists(testFile))
+ {
+ File.SetAttributes(testFile, FileAttributes.Normal);
+ File.Delete(testFile);
+ }
+ }
// copy file on the local machine (this is now done with createAPItestfiles.js, see Oasys scenario.)
if (LoadXSL("xmlResolver_document_function_absolute_uri.xsl", xslInputType, readerType) == 1)
AppContext.SetSwitch("Switch.System.Xml.AllowDefaultResolver", true);
string expected = @"<?xml version=""1.0"" encoding=""utf-8""?><result>123</result>";
+ string fileName = GetType().Name + "_" + Path.GetRandomFileName();
+ string testFile = Path.Combine(Path.GetTempPath(), fileName);
+ string xmlFile = FullFilePath(fileName);
// copy file on the local machine
try
{
- string tempPath = Path.GetTempPath();
- string testFile = Path.Combine(tempPath, "xmlResolver_document_function.xml");
- if (File.Exists(testFile))
- {
- File.SetAttributes(testFile, FileAttributes.Normal);
- File.Delete(testFile);
- }
- string xmlFile = FullFilePath("xmlResolver_document_function.xml");
File.Copy(xmlFile, testFile, true);
}
catch (Exception e)
_output.WriteLine("Could not copy file to local. Some other issues prevented this test from running");
return; //TEST_SKIPPED;
}
+ finally
+ {
+ if (File.Exists(testFile))
+ {
+ File.SetAttributes(testFile, FileAttributes.Normal);
+ File.Delete(testFile);
+ }
+ }
if (LoadXSL("xmlResolver_document_function_absolute_uri.xsl", xslInputType, readerType) == 1)
{
static XsltApiTestCaseBase2()
{
// Replace absolute URI in xmlResolver_document_function.xml based on the environment
- string targetFile = Path.Combine(Path.GetTempPath(), "xmlResolver_document_function.xml");
+ string targetFile = Path.Combine(Path.GetTempPath(), typeof(XsltApiTestCaseBase2) + "_" + Path.GetRandomFileName());
string xslFile = Path.Combine("TestFiles", FilePathUtil.GetTestDataPath(), "XsltApiV2", "xmlResolver_document_function_absolute_uri.xsl");
XmlDocument doc = new XmlDocument();
doc.Load(xslFile);
public class XsltApiTestCaseBase : FileCleanupTestBase
{
private const string XmlResolverDocumentName = "xmlResolver_document_function.xml";
- private static readonly string s_temporaryResolverDocumentFullName = Path.Combine(Path.GetTempPath(), "XslTransformApi", XmlResolverDocumentName);
+ private static readonly string s_temporaryResolverDocumentFullName = Path.Combine(Path.GetTempPath(), typeof(XsltApiTestCaseBase) + "_" + Path.GetRandomFileName());
private static readonly object s_temporaryResolverDocumentLock = new object();
// Generic data for all derived test cases