Skip to content

Commit e715094

Browse files
committed
chore: add some missing curlies
1 parent 2b3386b commit e715094

7 files changed

Lines changed: 55 additions & 12 deletions

File tree

src/System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public override void Delete()
4141

4242
public override void Refresh()
4343
{
44+
// Nothing to do here. Mock file system is always up-to-date.
4445
}
4546

4647
public override FileAttributes Attributes

src/System.IO.Abstractions.TestingHelpers/MockFile.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,19 @@ private Stream OpenInternal(
393393
bool exists = mockFileDataAccessor.FileExists(path);
394394

395395
if (mode == FileMode.CreateNew && exists)
396+
{
396397
throw new IOException(string.Format(CultureInfo.InvariantCulture, "The file '{0}' already exists.", path));
398+
}
397399

398400
if ((mode == FileMode.Open || mode == FileMode.Truncate) && !exists)
401+
{
399402
throw CommonExceptions.FileNotFound(path);
403+
}
400404

401405
if (!exists || mode == FileMode.CreateNew)
406+
{
402407
return Create(path);
408+
}
403409

404410
if (mode == FileMode.Create || mode == FileMode.Truncate)
405411
{
@@ -424,8 +430,7 @@ public override StreamReader OpenText(string path)
424430
{
425431
mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path");
426432

427-
return new StreamReader(
428-
OpenRead(path));
433+
return new StreamReader(OpenRead(path));
429434
}
430435

431436
public override Stream OpenWrite(string path) => OpenWriteInternal(path, FileOptions.None);

src/System.IO.Abstractions.TestingHelpers/MockFileData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ public FileSecurity AccessControl
177177
internal void CheckFileAccess(string path, FileAccess access)
178178
{
179179
if (!AllowedFileShare.HasFlag((FileShare)access))
180+
{
180181
throw CommonExceptions.ProcessCannotAccessFileInUse(path);
182+
}
181183
}
182184
}
183185
}

src/System.IO.Abstractions.TestingHelpers/MockFileInfo.cs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,45 @@ public override void Delete()
2929

3030
public override void Refresh()
3131
{
32+
// Nothing to do here. Mock file system is always up-to-date.
3233
}
3334

3435
public override FileAttributes Attributes
3536
{
3637
get
3738
{
38-
if (MockFileData == null) throw CommonExceptions.FileNotFound(path);
39+
if (MockFileData == null)
40+
{
41+
throw CommonExceptions.FileNotFound(path);
42+
}
3943
return MockFileData.Attributes;
4044
}
41-
set { MockFileData.Attributes = value; }
45+
set
46+
{
47+
if (MockFileData == null)
48+
{
49+
throw CommonExceptions.FileNotFound(path);
50+
}
51+
MockFileData.Attributes = value;
52+
}
4253
}
4354

4455
public override DateTime CreationTime
4556
{
4657
get
4758
{
48-
if (MockFileData == null) throw CommonExceptions.FileNotFound(path);
59+
if (MockFileData == null)
60+
{
61+
throw CommonExceptions.FileNotFound(path);
62+
}
4963
return MockFileData.CreationTime.DateTime;
5064
}
5165
set
5266
{
53-
if (MockFileData == null) throw CommonExceptions.FileNotFound(path);
67+
if (MockFileData == null)
68+
{
69+
throw CommonExceptions.FileNotFound(path);
70+
}
5471
MockFileData.CreationTime = value;
5572
}
5673
}
@@ -238,7 +255,7 @@ public override Stream Open(FileMode mode, FileAccess access, FileShare share)
238255

239256
public override StreamReader OpenText() => mockFileSystem.File.OpenText(path);
240257

241-
public override Stream OpenWrite() => mockFileSystem.File.OpenWrite(path);
258+
public override Stream OpenWrite() => mockFileSystem.File.OpenWrite(path);
242259

243260
public override IFileInfo Replace(string destinationFileName, string destinationBackupFileName)
244261
{
@@ -278,24 +295,37 @@ public override bool IsReadOnly
278295
{
279296
get
280297
{
281-
if (MockFileData == null) throw CommonExceptions.FileNotFound(path);
298+
if (MockFileData == null)
299+
{
300+
throw CommonExceptions.FileNotFound(path);
301+
}
282302
return (MockFileData.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
283303
}
284304
set
285305
{
286-
if (MockFileData == null) throw CommonExceptions.FileNotFound(path);
306+
if (MockFileData == null)
307+
{
308+
throw CommonExceptions.FileNotFound(path);
309+
}
287310
if (value)
311+
{
288312
MockFileData.Attributes |= FileAttributes.ReadOnly;
313+
}
289314
else
315+
{
290316
MockFileData.Attributes &= ~FileAttributes.ReadOnly;
317+
}
291318
}
292319
}
293320

294321
public override long Length
295322
{
296323
get
297324
{
298-
if (MockFileData == null || MockFileData.IsDirectory) throw CommonExceptions.FileNotFound(path);
325+
if (MockFileData == null || MockFileData.IsDirectory)
326+
{
327+
throw CommonExceptions.FileNotFound(path);
328+
}
299329
return MockFileData.Contents.Length;
300330
}
301331
}

src/System.IO.Abstractions.TestingHelpers/MockFileSystem.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ public void AddDirectory(string path)
163163
{
164164
if (FileExists(fixedPath) &&
165165
(GetFile(fixedPath).Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
166+
{
166167
throw CommonExceptions.AccessDenied(fixedPath);
167-
168+
}
168169
var lastIndex = 0;
169170
var isUnc =
170171
StringOperations.StartsWith(fixedPath, @"\\") ||
@@ -176,7 +177,9 @@ public void AddDirectory(string path)
176177
lastIndex = StringOperations.IndexOf(fixedPath, separator, 2);
177178

178179
if (lastIndex < 0)
180+
{
179181
throw CommonExceptions.InvalidUncPath(nameof(path));
182+
}
180183

181184
/*
182185
* Although CreateDirectory(@"\\server\share\") is not going to work in real code, we allow it here for the purposes of setting up test doubles.

src/System.IO.Abstractions/DirectoryInfoBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ internal DirectoryInfoBase() { }
100100
public static implicit operator DirectoryInfoBase(DirectoryInfo directoryInfo)
101101
{
102102
if (directoryInfo == null)
103+
{
103104
return null;
105+
}
104106
return new DirectoryInfoWrapper(new FileSystem(), directoryInfo);
105107
}
106108
}

src/System.IO.Abstractions/FileSystemWatcherBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static implicit operator FileSystemWatcherBase(FileSystemWatcher watcher)
6767
{
6868
if (watcher == null)
6969
{
70-
throw new ArgumentNullException(nameof(watcher));
70+
return null;
7171
}
7272

7373
return new FileSystemWatcherWrapper(watcher);

0 commit comments

Comments
 (0)