private bool IsDestinationDriveFull(string destinationRootPath, long freeSpaceToLeaveOnDestination) { var driveInfo = DriveInfoProvider.GetDriveInfoForPath(destinationRootPath); long availableFreeSpace = driveInfo.AvailableFreeSpace; long freeKb = 0; double freeMb = 0; double freeGb = 0; if (availableFreeSpace > 0) { freeKb = (availableFreeSpace / 1024); } if (freeKb > 0) { freeMb = (freeKb / 1024); } if (freeMb > 0) { freeGb = (freeMb / 1024); } if (freeMb < freeSpaceToLeaveOnDestination) { OnStatusUpdate(string.Format(CultureInfo.InvariantCulture, "Destination drive is full leaving {0:#,0.##} MB free", freeSpaceToLeaveOnDestination)); OnStatusUpdate(string.Format(CultureInfo.InvariantCulture, "Free Space on drive {0} is {1:#,0.##} KB, {2:#,0.##} MB, {3:#,0.##} GB", driveInfo.Name, freeKb, freeMb, freeGb)); return(true); } return(false); }
protected override void When() { try { DriveInfoProvider.GetDriveInfoForPath(@"mtp:\test device\a\b\c"); } catch (Exception exception) { ThrownException = exception; } }
protected override void GivenThat() { base.GivenThat(); SourcePath = @"c:\Source"; DestinationePath = @"d:\Dest"; DestinationDriveInfo = GenerateMock <IDriveInfo>(); DestinationDriveInfo.Stub(i => i.Name).Return("D"); DriveInfoProvider = GenerateMock <IDriveInfoProvider>(); DriveInfoProvider.Stub(p => p.GetDriveInfoForPath(@"d:\Dest")) .Return(DestinationDriveInfo); DriveInfoProvider.Stub(p => p.GetDriveInfoForPath(@"e:\error")) .Throw(new System.ArgumentException(@"Object must be a root directory ('C:\') or a drive letter ('C').")); FileUtilities = GenerateMock <IFileUtilities>(); PathUtilities = GenerateMock <IPathUtilities>(); PathUtilities.Stub(pathUtilities => pathUtilities.GetFullPath(null)) .IgnoreArguments() .WhenCalled(invocation => invocation.ReturnValue = invocation.Arguments[0]) .Return(null); SourceFiles = new List <FileSyncItem> { new FileSyncItem { Source = GenerateMock <IFileInfo>() }, new FileSyncItem { Source = GenerateMock <IFileInfo>() } }; SourceFiles[0].Source.Stub(s => s.FullName).Return(@"c:\Source\A"); SourceFiles[1].Source.Stub(s => s.FullName).Return(@"c:\Source\B"); StatusUpdates = new List <StatusUpdateEventArgs>(); FileCopier = new Copier(DriveInfoProvider, FileUtilities, PathUtilities); FileCopier.StatusUpdate += (sender, e) => StatusUpdates.Add(e); }
protected override void When() { DriveInfo = DriveInfoProvider.GetDriveInfoForPath(@"mtp:\test device\storage\b\c"); }