@@ -59,18 +59,46 @@ public void TestGetDrives()
5959 }
6060 }
6161
62+ [ Fact ]
63+ public void TestDriveProperties_AppContainer ( )
64+ {
65+ DriveInfo validDrive = DriveInfo . GetDrives ( ) . Where ( d => d . DriveType == DriveType . Fixed ) . First ( ) ;
66+ bool isReady = validDrive . IsReady ;
67+ Assert . NotNull ( validDrive . Name ) ;
68+ Assert . NotNull ( validDrive . RootDirectory . Name ) ;
69+
70+ if ( PlatformDetection . IsWinRT )
71+ {
72+ Assert . Throws < UnauthorizedAccessException > ( ( ) => validDrive . AvailableFreeSpace ) ;
73+ Assert . Throws < UnauthorizedAccessException > ( ( ) => validDrive . DriveFormat ) ;
74+ Assert . Throws < UnauthorizedAccessException > ( ( ) => validDrive . TotalFreeSpace ) ;
75+ Assert . Throws < UnauthorizedAccessException > ( ( ) => validDrive . TotalSize ) ;
76+ Assert . Throws < UnauthorizedAccessException > ( ( ) => validDrive . VolumeLabel ) ;
77+ }
78+ else
79+ {
80+ Assert . NotNull ( validDrive . DriveFormat ) ;
81+ Assert . True ( validDrive . AvailableFreeSpace > 0 ) ;
82+ Assert . True ( validDrive . TotalFreeSpace > 0 ) ;
83+ Assert . True ( validDrive . TotalSize > 0 ) ;
84+ Assert . NotNull ( validDrive . VolumeLabel ) ;
85+ }
86+ }
87+
6288 [ Fact ]
6389 [ PlatformSpecific ( TestPlatforms . Windows ) ]
90+ [ SkipOnTargetFramework ( TargetFrameworkMonikers . Uap | TargetFrameworkMonikers . UapAot , "Accessing drive format is not permitted inside an AppContainer." ) ]
6491 public void TestDriveFormat ( )
6592 {
66- var validDrive = DriveInfo . GetDrives ( ) . Where ( d => d . DriveType == DriveType . Fixed ) . First ( ) ;
93+ DriveInfo validDrive = DriveInfo . GetDrives ( ) . Where ( d => d . DriveType == DriveType . Fixed ) . First ( ) ;
6794 const int volNameLen = 50 ;
6895 StringBuilder volumeName = new StringBuilder ( volNameLen ) ;
6996 const int fileSystemNameLen = 50 ;
7097 StringBuilder fileSystemName = new StringBuilder ( fileSystemNameLen ) ;
7198 int serialNumber , maxFileNameLen , fileSystemFlags ;
7299 bool r = GetVolumeInformation ( validDrive . Name , volumeName , volNameLen , out serialNumber , out maxFileNameLen , out fileSystemFlags , fileSystemName , fileSystemNameLen ) ;
73100 var fileSystem = fileSystemName . ToString ( ) ;
101+
74102 if ( r )
75103 {
76104 Assert . Equal ( fileSystem , validDrive . DriveFormat ) ;
@@ -191,6 +219,13 @@ void DoDriveCheck()
191219 public void SetVolumeLabel_Roundtrips ( )
192220 {
193221 DriveInfo drive = DriveInfo . GetDrives ( ) . Where ( d => d . DriveType == DriveType . Fixed ) . First ( ) ;
222+ // Inside an AppContainer access to VolumeLabel is denied.
223+ if ( PlatformDetection . IsWinRT )
224+ {
225+ Assert . Throws < UnauthorizedAccessException > ( ( ) => drive . VolumeLabel ) ;
226+ return ;
227+ }
228+
194229 string currentLabel = drive . VolumeLabel ;
195230 try
196231 {
0 commit comments