Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #199 from lindend/master
Implementation of MockFile GetAccessControl and SetAccessControl
- Loading branch information
Showing
5 changed files
with
176 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Security.AccessControl; | ||
|
||
namespace System.IO.Abstractions.TestingHelpers.Tests | ||
{ | ||
using XFS = MockUnixSupport; | ||
|
||
[TestFixture] | ||
public class MockFileGetAccessControlTests | ||
{ | ||
[TestCase(" ")] | ||
[TestCase(" ")] | ||
public void MockFile_GetAccessControl_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path) | ||
{ | ||
// Arrange | ||
var fileSystem = new MockFileSystem(); | ||
|
||
// Act | ||
TestDelegate action = () => fileSystem.File.GetAccessControl(path); | ||
|
||
// Assert | ||
var exception = Assert.Throws<ArgumentException>(action); | ||
Assert.That(exception.ParamName, Is.EqualTo("path")); | ||
} | ||
|
||
[Test] | ||
public void MockFile_GetAccessControl_ShouldThrowFileNotFoundExceptionIfFileDoesNotExistInMockData() | ||
{ | ||
// Arrange | ||
var fileSystem = new MockFileSystem(); | ||
var expectedFileName = XFS.Path(@"c:\a.txt"); | ||
|
||
// Act | ||
TestDelegate action = () => fileSystem.File.GetAccessControl(expectedFileName); | ||
|
||
// Assert | ||
var exception = Assert.Throws<FileNotFoundException>(action); | ||
Assert.That(exception.FileName, Is.EqualTo(expectedFileName)); | ||
} | ||
|
||
[Test] | ||
public void MockFile_GetAccessControl_ShouldReturnAccessControlOfFileData() | ||
{ | ||
// Arrange | ||
var expectedFileSecurity = new FileSecurity(); | ||
expectedFileSecurity.SetAccessRuleProtection(false, false); | ||
|
||
var filePath = XFS.Path(@"c:\a.txt"); | ||
var fileData = new MockFileData("Test content") | ||
{ | ||
AccessControl = expectedFileSecurity, | ||
}; | ||
|
||
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>() | ||
{ | ||
{ filePath, fileData } | ||
}); | ||
|
||
// Act | ||
var fileSecurity = fileSystem.File.GetAccessControl(filePath); | ||
|
||
// Assert | ||
Assert.That(fileSecurity, Is.EqualTo(expectedFileSecurity)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace System.IO.Abstractions.TestingHelpers.Tests | ||
{ | ||
using Security.AccessControl; | ||
using XFS = MockUnixSupport; | ||
|
||
[TestFixture] | ||
public class MockFileSetAccessControlTests | ||
{ | ||
[TestCase(" ")] | ||
[TestCase(" ")] | ||
public void MockFile_SetAccessControl_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path) | ||
{ | ||
// Arrange | ||
var fileSystem = new MockFileSystem(); | ||
var fileSecurity = new FileSecurity(); | ||
|
||
// Act | ||
TestDelegate action = () => fileSystem.File.SetAccessControl(path, fileSecurity); | ||
|
||
// Assert | ||
var exception = Assert.Throws<ArgumentException>(action); | ||
Assert.That(exception.ParamName, Is.EqualTo("path")); | ||
} | ||
|
||
[Test] | ||
public void MockFile_SetAccessControl_ShouldThrowFileNotFoundExceptionIfFileDoesNotExistInMockData() | ||
{ | ||
// Arrange | ||
var fileSystem = new MockFileSystem(); | ||
var expectedFileName = XFS.Path(@"c:\a.txt"); | ||
var fileSecurity = new FileSecurity(); | ||
|
||
// Act | ||
TestDelegate action = () => fileSystem.File.SetAccessControl(expectedFileName, fileSecurity); | ||
|
||
// Assert | ||
var exception = Assert.Throws<FileNotFoundException>(action); | ||
Assert.That(exception.FileName, Is.EqualTo(expectedFileName)); | ||
} | ||
|
||
[Test] | ||
public void MockFile_SetAccessControl_ShouldReturnAccessControlOfFileData() | ||
{ | ||
// Arrange | ||
var filePath = XFS.Path(@"c:\a.txt"); | ||
var fileData = new MockFileData("Test content"); | ||
|
||
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>() | ||
{ | ||
{ filePath, fileData } | ||
}); | ||
|
||
// Act | ||
var expectedAccessControl = new FileSecurity(); | ||
expectedAccessControl.SetAccessRuleProtection(false, false); | ||
fileSystem.File.SetAccessControl(filePath, expectedAccessControl); | ||
|
||
// Assert | ||
var accessControl = fileSystem.File.GetAccessControl(filePath); | ||
Assert.That(accessControl, Is.EqualTo(expectedAccessControl)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters