forked from TestableIO/System.IO.Abstractions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMockDriveInfo.cs
70 lines (61 loc) · 2.33 KB
/
MockDriveInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
namespace System.IO.Abstractions.TestingHelpers
{
[Serializable]
public class MockDriveInfo : DriveInfoBase
{
private readonly IMockFileDataAccessor mockFileDataAccessor;
public MockDriveInfo(IMockFileDataAccessor mockFileDataAccessor, string name)
{
if (mockFileDataAccessor == null)
{
throw new ArgumentNullException("mockFileDataAccessor");
}
if (name == null)
{
throw new ArgumentNullException("name");
}
const string DRIVE_SEPARATOR = @":\";
if (name.Length == 1)
{
name = char.ToUpperInvariant(name[0]) + DRIVE_SEPARATOR;
}
else if (name.Length == 2 && name[1] == ':')
{
name = char.ToUpperInvariant(name[0]) + DRIVE_SEPARATOR;
}
else if (name.Length == 3 && name.EndsWith(DRIVE_SEPARATOR, StringComparison.Ordinal))
{
name = char.ToUpperInvariant(name[0]) + DRIVE_SEPARATOR;
}
else
{
MockPath.CheckInvalidPathChars(name);
name = mockFileDataAccessor.Path.GetPathRoot(name);
if (string.IsNullOrEmpty(name) || name.StartsWith(@"\\", StringComparison.Ordinal))
{
throw new ArgumentException(
@"Object must be a root directory (""C:\"") or a drive letter (""C"").");
}
}
this.mockFileDataAccessor = mockFileDataAccessor;
Name = name;
IsReady = true;
}
public new long AvailableFreeSpace { get; set; }
public new string DriveFormat { get; set; }
public new DriveType DriveType { get; set; }
public new bool IsReady { get; protected set; }
public override string Name { get; protected set; }
public override DirectoryInfoBase RootDirectory
{
get
{
var directory = mockFileDataAccessor.DirectoryInfo.FromDirectoryName(Name);
return directory;
}
}
public new long TotalFreeSpace { get; protected set; }
public new long TotalSize { get; protected set; }
public override string VolumeLabel { get; set; }
}
}