public void GetOwnershipTest2() { // Arrange var tmpDir = Path.Combine(Path.GetTempPath(), "dirtools-test-" + Guid.NewGuid().ToString()); Directory.CreateDirectory(tmpDir); var tmpFile = Path.Combine(tmpDir, "asdf"); var localSystem = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null); var fileSec = new FileSecurity(); fileSec.SetOwner(localSystem); File.Create(tmpFile, 1, FileOptions.None, fileSec).Dispose(); // Act var curIdentity = new NTAccount(Environment.UserDomainName, Environment.UserName); DirectoryTools.GetOwnershipForDirectory(tmpFile, curIdentity); // Assert var curFilesec = new FileSecurity(tmpFile, AccessControlSections.Owner); IdentityReference owner = curFilesec.GetOwner(typeof(NTAccount)); Assert.IsTrue(curIdentity == owner); }