Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Microsoft.NET.Build.Tasks.UnitTests
{
public class GivenAGetDependsOnNETStandardTask
public class GivenAGetDependsOnNETStandardTask(ITestOutputHelper log) : SdkTest(log)
{
[Fact]
public void CanCheckThisAssembly()
Expand Down Expand Up @@ -121,28 +121,37 @@ public void SucceedsOnMissingFileReturnsFalse()
[Fact]
public void SucceedsWithWarningOnLockedFile()
{
var lockedFile = $"{nameof(SucceedsWithWarningOnLockedFile)}.dll";
var testDir = TestAssetsManager.CreateTestDirectory();
var lockedFile = Path.Combine(testDir.Path, $"{nameof(SucceedsWithWarningOnLockedFile)}.dll");

try
// Create file with exclusive lock (no sharing)
using (var fileHandle = new FileStream(lockedFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
{
// Verify the lock is actually held before running the task.
// On some CI machines, antimalware or file system filters can
// interfere with file locking, causing the test to be unreliable.
try
{
using var probe = new FileStream(lockedFile, FileMode.Open, FileAccess.Read, FileShare.Read);
Assert.Fail(
"File lock is not being enforced — the probe open should have thrown IOException. " +
"This may indicate antimalware or file system filter interference on this machine.");
}
catch (IOException)
{
// Expected — the lock is working correctly
}

var task = new GetDependsOnNETStandard()
{
BuildEngine = new MockBuildEngine(),
TaskEnvironment = TaskEnvironmentHelper.CreateForTest(),
References = new[] { new MockTaskItem() { ItemSpec = lockedFile } }
};

// create file with no sharing
using (var fileHandle = new FileStream(lockedFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
{
task.Execute().Should().BeTrue();
task.DependsOnNETStandard.Should().BeFalse();
((MockBuildEngine)task.BuildEngine).Warnings.Count.Should().BeGreaterThan(0);
}
}
finally
{
File.Delete(lockedFile);
task.Execute().Should().BeTrue();
task.DependsOnNETStandard.Should().BeFalse();
((MockBuildEngine)task.BuildEngine).Warnings.Count.Should().BeGreaterThan(0);
}
}
}
Expand Down
Loading