public void SetFullControlPermissionsToEveryone_should_set_the_permission_to_everyone_full_control() { using (var log = new DirectoryInfo(Utility.Log).BeginModifying()) { // Arrange var fixture = new Fixture().Customize(new AutoMoqCustomization()); var dummyLog = new DirectoryInfo(Utility.Log).CreateWithContent(fixture); var envRepos = new EnvironmentRepository(); // Act envRepos.SetFullControlPermissionsToEveryone(Utility.Log); // Assert Assert.IsTrue(dummyLog.HasUsersFullControlAccess()); } }
public void SetFullControlPermissionsToEveryone_should_throw_InvalidOperationException_if_failing_to_set_to_inherit() { using (var log = new DirectoryInfo(Utility.Log).BeginModifying()) { // Arrange var fixture = new Fixture().Customize(new AutoMoqCustomization()); var dummyLog = new DirectoryInfo(Utility.Log).CreateWithContent(fixture); var envRepos = new EnvironmentRepository(); var mocks = new MockRepository(MockBehavior.Default); var inheritedAccessRule = new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow); { var m = mocks.Create <Func <IdentityReference, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType, AccessRule> >(); m.Setup(_ => _(It.IsAny <IdentityReference>(), It.IsAny <FileSystemRights>(), InheritanceFlags.None, PropagationFlags.NoPropagateInherit, It.IsAny <AccessControlType>())); m.Setup(_ => _(It.IsAny <IdentityReference>(), It.IsAny <FileSystemRights>(), InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, It.IsAny <AccessControlType>())). Returns(inheritedAccessRule); envRepos.NewFileSystemAccessRule = m.Object; } var dirSecur = dummyLog.GetAccessControl(AccessControlSections.Access); { var m = mocks.Create <Func <DirectoryInfo, AccessControlSections, DirectorySecurity> >(); m.Setup(_ => _(It.IsAny <DirectoryInfo>(), It.IsAny <AccessControlSections>())).Returns(dirSecur); envRepos.DirectoryInfoGetAccessControl = m.Object; } { var m = mocks.Create <Func <DirectorySecurity, AccessControlModification, AccessRule, bool> >(); m.Setup(_ => _(dirSecur, AccessControlModification.Set, It.IsAny <AccessRule>())).Returns(true); m.Setup(_ => _(dirSecur, AccessControlModification.Add, inheritedAccessRule)).Returns(false); envRepos.DirectorySecurityModifyAccessRule = m.Object; } // Act, Assert Assert.Throws <InvalidOperationException>(() => envRepos.SetFullControlPermissionsToEveryone(Utility.Log)); } }