[v5.6.0.1/vs2022/net8]
Given below code using [Isolated] attribute, shouldn't the dotnet.exe process be terminated once a test completes?
(second test will fail due to dotnet.exe process is still hanging around)
Code:
using System.Reflection;
using NCrunch.Framework;
using NUnit.Framework;
namespace Tests;
[TestFixture]
internal class NCrunchAtomicTest
{
#region Public members
[Test]
[Isolated]
[ExclusivelyUses("File")]
public void LockFileTest1()
{
LockFile();
}
[Test]
[Isolated]
[ExclusivelyUses("File")]
public void LockFileTest2()
{
LockFile();
}
[SetUp]
public void NCrunchAtomicTestSetUp()
{
string assemblyLocation = Assembly.GetExecutingAssembly().Location;
string directory = Path.GetDirectoryName(assemblyLocation);
_filePath = Path.Combine(directory, "file.txt");
Console.WriteLine($"{Environment.ProcessId:D5} Using file {_filePath}.");
}
#endregion
#region Private members
private static FileStream? _fileStream;
private string _filePath;
private void LockFile()
{
_fileStream = new FileStream(_filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite,
FileShare.None);
}
#endregion
}
Output Test1:
Quote:
46056 Using file C:\NC\WC\37432\148\test\...\bin\Debug\net8.0\file.txt.
Output Test2:
Quote:
41524 Using file C:\NC\WC\37432\148\test\...\bin\Debug\net8.0\file.txt.
System.IO.IOException : The process cannot access the file 'C:\NC\WC\37432\148\test\...\bin\Debug\net8.0\file.txt' because it is being used by another process.