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.
30 lines
845 B
30 lines
845 B
3 years ago
|
using System.IO.Abstractions;
|
||
|
using AutoFixture;
|
||
|
|
||
2 years ago
|
namespace Recyclarr.TestLibrary.AutoFixture;
|
||
3 years ago
|
|
||
|
public class MockFileSystemSpecimenBuilder : ICustomization
|
||
|
{
|
||
2 years ago
|
private static int _mockPathCounter;
|
||
|
|
||
3 years ago
|
public void Customize(IFixture fixture)
|
||
|
{
|
||
|
var fs = new MockFileSystem();
|
||
|
fixture.Inject(fs);
|
||
|
|
||
|
fixture.Customize<IFileInfo>(x => x.FromFactory(() =>
|
||
|
{
|
||
2 years ago
|
var name = $"MockFile-{_mockPathCounter}";
|
||
|
Interlocked.Increment(ref _mockPathCounter);
|
||
3 years ago
|
return fs.CurrentDirectory().File(name);
|
||
|
}));
|
||
|
|
||
|
fixture.Customize<IDirectoryInfo>(x => x.FromFactory(() =>
|
||
|
{
|
||
2 years ago
|
var name = $"MockDirectory-{_mockPathCounter}";
|
||
|
Interlocked.Increment(ref _mockPathCounter);
|
||
3 years ago
|
return fs.CurrentDirectory().SubDirectory(name);
|
||
|
}));
|
||
|
}
|
||
|
}
|