This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
495 additions
and
115 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
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
113 changes: 113 additions & 0 deletions
113
...FS_Directory.Copy/AlphaFS_Directory.Copy_ExistingDirectory_UsingGlobalRootAsSourcePath.cs
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,113 @@ | ||
/* Copyright (C) 2008-2018 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
using System; | ||
using System.Linq; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace AlphaFS.UnitTest | ||
{ | ||
public partial class CopyTest | ||
{ | ||
// Pattern: <class>_<function>_<scenario>_<expected result> | ||
|
||
|
||
[TestMethod] | ||
public void AlphaFS_Directory_Copy_ExistingDirectory_UsingGlobalRootAsSourcePath_LocalAndNetwork_Success() | ||
{ | ||
AlphaFS_Directory_Copy_ExistingDirectory_UsingGlobalRootAsSourcePath(false); | ||
AlphaFS_Directory_Copy_ExistingDirectory_UsingGlobalRootAsSourcePath(true); | ||
} | ||
|
||
|
||
private void AlphaFS_Directory_Copy_ExistingDirectory_UsingGlobalRootAsSourcePath(bool isNetwork) | ||
{ | ||
var testOk = false; | ||
|
||
using (var tempRoot = new TemporaryDirectory(isNetwork)) | ||
{ | ||
var folder = tempRoot.CreateDirectoryRandomizedAttributes(); | ||
|
||
var dosDevices = Alphaleonis.Win32.Filesystem.Volume.QueryAllDosDevices().Where(device => device.StartsWith("HarddiskVolumeShadowCopy", StringComparison.OrdinalIgnoreCase)).ToArray(); | ||
|
||
foreach (var dosDevice in dosDevices) | ||
{ | ||
if (testOk) | ||
break; | ||
|
||
var shadowSource = Alphaleonis.Win32.Filesystem.Path.GlobalRootDevicePrefix + dosDevice; | ||
|
||
var sourceFolder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); | ||
|
||
var drive = System.IO.Directory.GetDirectoryRoot(sourceFolder).TrimEnd('\\'); | ||
|
||
var globalRoot = sourceFolder.Replace(drive, shadowSource); | ||
|
||
|
||
var dirInfo = new Alphaleonis.Win32.Filesystem.DirectoryInfo(globalRoot); | ||
|
||
Console.WriteLine("Input GlobalRoot Path: [{0}]\n", dirInfo.FullName); | ||
|
||
if (!dirInfo.Exists) | ||
UnitTestAssert.InconclusiveBecauseFileNotFound("No volume shadow copy found."); | ||
|
||
|
||
var enumOptions = Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.Recursive | Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.SkipReparsePoints; | ||
var copyOptions = Alphaleonis.Win32.Filesystem.CopyOptions.None; | ||
|
||
var copyCount = 0; | ||
|
||
foreach (var fsi in dirInfo.EnumerateDirectories(enumOptions)) | ||
{ | ||
if (copyCount == 3) | ||
break; | ||
|
||
|
||
// Copy all folders from "\Program Files". | ||
|
||
var folderCopy = System.IO.Path.Combine(folder.FullName, System.IO.Path.GetFileName(fsi.FullName)); | ||
|
||
Console.WriteLine("Copy directory #{0}.", copyCount + 1); | ||
|
||
|
||
var cmr = Alphaleonis.Win32.Filesystem.Directory.Copy(fsi.FullName, folderCopy, copyOptions); | ||
|
||
|
||
UnitTestConstants.Dump(cmr); | ||
Console.WriteLine(); | ||
|
||
|
||
Assert.AreEqual(0, cmr.ErrorCode); | ||
|
||
|
||
testOk = true; | ||
|
||
copyCount++; | ||
} | ||
} | ||
} | ||
|
||
Console.WriteLine(); | ||
|
||
Assert.IsTrue(testOk); | ||
} | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
...ectoryInfo.InitializeInstance_ExistingFileAsDirectoryeName_PropertyExistsShouldbeFalse.cs
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,63 @@ | ||
/* Copyright (C) 2008-2018 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
|
||
namespace AlphaFS.UnitTest | ||
{ | ||
public partial class DirectoryInfoTest | ||
{ | ||
// Pattern: <class>_<function>_<scenario>_<expected result> | ||
|
||
|
||
[TestMethod] | ||
public void DirectoryInfo_InitializeInstance_ExistingFileAsDirectoryeName_PropertyExistsShouldbeFalse_LocalAndNetwork_Success() | ||
{ | ||
DirectoryInfo_InitializeInstance_ExistingFileAsDirectoryeName_PropertyExistsShouldbeFalse(false); | ||
DirectoryInfo_InitializeInstance_ExistingFileAsDirectoryeName_PropertyExistsShouldbeFalse(true); | ||
} | ||
|
||
|
||
private void DirectoryInfo_InitializeInstance_ExistingFileAsDirectoryeName_PropertyExistsShouldbeFalse(bool isNetwork) | ||
{ | ||
using (var tempRoot = new TemporaryDirectory(isNetwork)) | ||
{ | ||
var file = tempRoot.CreateFileRandomizedAttributes(); | ||
|
||
Console.WriteLine("Input File Path: [{0}]", file.FullName); | ||
|
||
var systemIODirInfo = new System.IO.DirectoryInfo(file.FullName); | ||
|
||
var alphaFSDirInfo = new Alphaleonis.Win32.Filesystem.DirectoryInfo(file.FullName); | ||
|
||
UnitTestConstants.Dump(alphaFSDirInfo); | ||
|
||
|
||
Assert.AreEqual(systemIODirInfo.Exists, alphaFSDirInfo.Exists); | ||
|
||
Assert.IsFalse(alphaFSDirInfo.EntryInfo.IsDirectory); | ||
} | ||
|
||
Console.WriteLine(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.