You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
recyclarr/src/Recyclarr.TestLibrary/AutoFixture/MockFileSystemSpecimenBuild...

31 lines
886 B

using System.IO.Abstractions;
using System.IO.Abstractions.Extensions;
using AutoFixture;
namespace Recyclarr.TestLibrary.AutoFixture;
public class MockFileSystemSpecimenBuilder : ICustomization
{
private static int _mockPathCounter;
public void Customize(IFixture fixture)
{
var fs = new MockFileSystem();
fixture.Inject(fs);
fixture.Customize<IFileInfo>(x => x.FromFactory(() =>
{
var name = $"MockFile-{_mockPathCounter}";
Interlocked.Increment(ref _mockPathCounter);
return fs.CurrentDirectory().File(name);
}));
fixture.Customize<IDirectoryInfo>(x => x.FromFactory(() =>
{
var name = $"MockDirectory-{_mockPathCounter}";
Interlocked.Increment(ref _mockPathCounter);
return fs.CurrentDirectory().SubDirectory(name);
}));
}
}