public void VolumeLabelShouldReturnStringEmptyIfDriveInfoIsNull()
        {
            // Arrange
            var unitLetter   = @"F:\";
            var vcdMountPath = @"C:\tmp";
            VirtualCloneDriveWrapper wrapper = new VirtualCloneDriveWrapper(unitLetter, vcdMountPath, 3, 1000, null, null, null);
            string volumeLabel;

            // Act
            volumeLabel = wrapper.VolumeLabel;

            // Assert
            Assert.AreEqual(string.Empty, volumeLabel);
        }
        public void TotalSizeShouldReturnZeroIfDriveInfoIsNull()
        {
            // Arrange
            var unitLetter   = @"F:\";
            var vcdMountPath = @"C:\tmp";
            VirtualCloneDriveWrapper wrapper = new VirtualCloneDriveWrapper(unitLetter, vcdMountPath, 3, 1000, null, null, null);
            long totalSize;

            // Act
            totalSize = wrapper.TotalSize;

            // Assert
            Assert.AreEqual(0, totalSize);
        }
        public void UnitLetterSetShouldCallDriveInfoSetDriveLetter()
        {
            // Arrange
            var mockDriveInfo = new Mock <IDriveInfo>();
            var driveInfo     = mockDriveInfo.Object;
            var unitLetter    = @"F:\";
            var vcdMountPath  = @"C:\tmp";
            VirtualCloneDriveWrapper wrapper = new VirtualCloneDriveWrapper(unitLetter, vcdMountPath, 3, 1000, driveInfo, null, null);

            // Act
            wrapper.UnitLetter = "C";

            // Assert
            Assert.AreEqual("C", wrapper.UnitLetter);
            mockDriveInfo.Verify(m => m.SetDriveLetter(It.IsAny <string>()), Times.AtLeastOnce);
        }
        public void ConstructorUnitLetterMountPathShouldSetProperties()
        {
            // Arrange
            string unitLetter   = "Z";
            string vcdMountPath = @"C:\Program Files (x86)\Elaborate Bytes\VirtualCloneDrive\VCDMount.exe";
            VirtualCloneDriveWrapper wrapper;

            // Act
            wrapper = new VirtualCloneDriveWrapper(unitLetter, vcdMountPath);

            // Assert
            Assert.AreEqual(unitLetter, wrapper.UnitLetter);
            Assert.AreEqual(vcdMountPath, wrapper.VcdMountPath);
            Assert.AreEqual(5, wrapper.TriesBeforeError);
            Assert.AreEqual(1000, wrapper.WaitTime);
        }
示例#5
0
文件: Main.cs 项目: mamcer/isofinder
        public Main()
        {
            InitializeComponent();

            _unitLetter = ConfigurationManager.AppSettings["UnitLetter"];
            if (string.IsNullOrEmpty(_unitLetter))
            {
                throw new Exception("UnitLetter app setting not found.");
            }

            string vcdMountPath = ConfigurationManager.AppSettings["VCDMountPath"];

            if (string.IsNullOrEmpty(vcdMountPath))
            {
                throw new Exception("VCDMountPath app setting not found.");
            }

            _copyFileFolder = ConfigurationManager.AppSettings["CopyFilesFolder"];
            if (string.IsNullOrEmpty(_copyFileFolder))
            {
                throw new Exception("CopyFileFolder app setting not found.");
            }

            _isoFilesPath = ConfigurationManager.AppSettings["IsoFilesPath"];
            if (string.IsNullOrEmpty(_isoFilesPath))
            {
                throw new Exception("IsoFilesPath app setting not found.");
            }

            var timerInterval = ConfigurationManager.AppSettings["TimerInterval"];

            if (string.IsNullOrEmpty(_isoFilesPath))
            {
                throw new Exception("TimerInterval app setting not found.");
            }

            _virtualCloneDrive = new VirtualCloneDriveWrapper(_unitLetter, vcdMountPath);

            _pendingRequests = new List <IsoRequest>();

            _isoRequestService = new IsoRequestService(new UnitOfWork());
            _isoVolumeService  = new IsoVolumeService(new UnitOfWork());
            timer.Interval     = Convert.ToInt32(timerInterval);
            timer.Enabled      = true;
        }
        public void VolumeLabelShouldReturnDriveInfoVolumeLabel()
        {
            // Arrange
            var mockDriveInfo = new Moq.Mock <IDriveInfo>();
            var label         = "Hello";

            mockDriveInfo.Setup(m => m.VolumeLabel).Returns(label);
            var driveInfo    = mockDriveInfo.Object;
            var unitLetter   = @"F:\";
            var vcdMountPath = @"C:\tmp";
            VirtualCloneDriveWrapper wrapper = new VirtualCloneDriveWrapper(unitLetter, vcdMountPath, 3, 1000, driveInfo, null, null);
            string volumeLabel;

            // Act
            volumeLabel = wrapper.VolumeLabel;

            // Assert
            Assert.AreEqual(label, volumeLabel);
        }
        public void TotalSizeShouldReturnDriveInfoTotalSize()
        {
            // Arrange
            var mockDriveInfo = new Mock <IDriveInfo>();
            var size          = 100;

            mockDriveInfo.Setup(m => m.TotalSize).Returns(size);
            var driveInfo    = mockDriveInfo.Object;
            var unitLetter   = @"F:\";
            var vcdMountPath = @"C:\tmp";
            VirtualCloneDriveWrapper wrapper = new VirtualCloneDriveWrapper(unitLetter, vcdMountPath, 3, 1000, driveInfo, null, null);
            long totalSize;

            // Act
            totalSize = wrapper.TotalSize;

            // Assert
            Assert.AreEqual(size, totalSize);
        }
示例#8
0
        public Main()
        {
            InitializeComponent();

            UnitLetter = ConfigurationManager.AppSettings["UnitLetter"];
            var vcdMountExePath = ConfigurationManager.AppSettings["IsoMountPath"];

            if (!File.Exists(vcdMountExePath))
            {
                MessageBox.Show(Resources.VCDMountExeNotFound, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
            }

            var driveInfo = DriveInfo.GetDrives();

            foreach (var info in driveInfo)
            {
                if (info.DriveType == DriveType.CDRom)
                {
                    cmbUnit.Items.Add(info.Name);
                }
            }

            if (cmbUnit.Items.Count == 0)
            {
                MessageBox.Show(Resources.NoCDRomUnit, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
            }

            cmbUnit.SelectedIndexChanged -= cmbUnit_SelectedIndexChanged;
            if (cmbUnit.Items.Contains(UnitLetter + ":\\"))
            {
                cmbUnit.SelectedIndex = cmbUnit.Items.IndexOf(UnitLetter + ":\\");
            }
            else
            {
                cmbUnit.SelectedIndex = 0;
                UnitLetter            = cmbUnit.Items[0].ToString().Substring(0, 1);
            }
            cmbUnit.SelectedIndexChanged += cmbUnit_SelectedIndexChanged;

            VirtualDrive = new VirtualCloneDriveWrapper(UnitLetter, vcdMountExePath);
        }
        public void ConstructorAllParametersShouldSetProperties()
        {
            // Arrange
            string     unitLetter       = "Z";
            string     vcdMountPath     = @"C:\Program Files (x86)\Elaborate Bytes\VirtualCloneDrive\VCDMount.exe";
            int        triesBeforeError = 10;
            int        waitTime         = 5000;
            IDriveInfo defaultDriveInfo = new DefaultDriveInfo();

            VirtualCloneDriveWrapper wrapper;

            // Act
            wrapper = new VirtualCloneDriveWrapper(unitLetter, vcdMountPath, triesBeforeError, waitTime, defaultDriveInfo, null, null);

            // Assert
            Assert.AreEqual(unitLetter, wrapper.UnitLetter);
            Assert.AreEqual(vcdMountPath, wrapper.VcdMountPath);
            Assert.AreEqual(triesBeforeError, wrapper.TriesBeforeError);
            Assert.AreEqual(waitTime, wrapper.WaitTime);
        }
        public async Task MountAsyncWithNonExistingIsoShouldReturnError()
        {
            // Arrange
            var unitLetter       = @"F:\";
            var vcdMountPath     = @"C:\tmp";
            var mockDriveInfo    = new Mock <IDriveInfo>();
            var driveInfo        = mockDriveInfo.Object;
            var mockFileProvider = new Mock <IFileProvider>();

            mockFileProvider.Setup(m => m.Exists(It.IsAny <string>())).Returns(false);

            VirtualCloneDriveWrapper wrapper = new VirtualCloneDriveWrapper(unitLetter, vcdMountPath, 3, 1000, driveInfo, mockFileProvider.Object, null);
            DeviceEventArgs          deviceEventArgs;

            // Act
            deviceEventArgs = await wrapper.MountAsync(string.Empty);

            // Assert
            Assert.IsTrue(deviceEventArgs.HasError);
            Assert.IsTrue(deviceEventArgs.ErrorMessage.Contains("doesn't exists or don't have access."));
        }
        public async Task UnMountAsyncWithDriveNotReadyShouldReturnError()
        {
            // Arrange
            var unitLetter          = @"F:\";
            var vcdMountPath        = @"C:\tmp";
            var mockDriveInfo       = new Mock <IDriveInfo>();
            var mockFileProvider    = new Mock <IFileProvider>();
            var mockProcessProvider = new Mock <IProcessProvider>();

            mockDriveInfo.Setup(m => m.IsReady).Returns(true);
            mockProcessProvider.Setup(m => m.Start(It.IsAny <string>(), It.IsAny <string>())).Returns(new System.Diagnostics.Process());

            VirtualCloneDriveWrapper wrapper = new VirtualCloneDriveWrapper(unitLetter, vcdMountPath, 3, 1000, mockDriveInfo.Object, mockFileProvider.Object, mockProcessProvider.Object);
            DeviceEventArgs          deviceEventArgs;

            // Act
            deviceEventArgs = await wrapper.UnMountAsync();

            // Assert
            Assert.IsTrue(deviceEventArgs.HasError);
            Assert.IsTrue(deviceEventArgs.ErrorMessage.Contains("There was an error trying to Unmount file on device"));
            mockProcessProvider.Verify(m => m.Start(It.IsAny <string>(), It.IsAny <string>()), Times.AtLeastOnce);
        }
        public async Task UnmountAsyncShouldCallProcessProviderStart()
        {
            // Arrange
            var unitLetter          = @"F:\";
            var vcdMountPath        = @"C:\tmp";
            var mockDriveInfo       = new Mock <IDriveInfo>();
            var mockFileProvider    = new Mock <IFileProvider>();
            var mockProcessProvider = new Mock <IProcessProvider>();

            mockDriveInfo.Setup(m => m.IsReady).Returns(false);
            mockProcessProvider.Setup(m => m.Start(It.IsAny <string>(), It.IsAny <string>())).Returns(new System.Diagnostics.Process());

            VirtualCloneDriveWrapper wrapper = new VirtualCloneDriveWrapper(unitLetter, vcdMountPath, 3, 1000, mockDriveInfo.Object, mockFileProvider.Object, mockProcessProvider.Object);
            DeviceEventArgs          deviceEventArgs;

            // Act
            deviceEventArgs = await wrapper.UnMountAsync();

            // Assert
            Assert.IsFalse(deviceEventArgs.HasError);
            Assert.AreEqual(string.Empty, deviceEventArgs.ErrorMessage);
            mockProcessProvider.Verify(m => m.Start(It.IsAny <string>(), It.IsAny <string>()), Times.AtLeastOnce);
        }
示例#13
0
        public MainWindow()
        {
            InitializeComponent();

            var unitLetter = ConfigurationManager.AppSettings["UnitLetter"];

            if (string.IsNullOrEmpty(unitLetter))
            {
                throw new InvalidOperationException("Cannot find a 'UnitLetter' configuration key.");
            }

            var vcdMountPath = ConfigurationManager.AppSettings["VCDMountPath"];

            if (string.IsNullOrEmpty(vcdMountPath))
            {
                throw new InvalidOperationException("Cannot find a 'VCDMountPath' configuration key.");
            }

            VirtualCloneDrive = new VirtualCloneDriveWrapper(unitLetter, vcdMountPath);

            var logFolderPath = ConfigurationManager.AppSettings["LogFolderPath"];

            if (!Directory.Exists(logFolderPath))
            {
                try
                {
                    Directory.CreateDirectory(logFolderPath);
                }
                catch
                {
                    logFolderPath = Path.GetTempPath();
                }
            }

            LogFolder = logFolderPath;
        }
示例#14
0
 public VirtualDriveResource(string unitLetter, string vcdMountPath)
 {
     _virtualDrive = new VirtualCloneDriveWrapper(unitLetter, vcdMountPath);
     IsIdle        = true;
 }
示例#15
0
文件: Scan.cs 项目: mamcer/isofinder
 public void Initialize(IsoScannerInfo scannerInfo)
 {
     _isoScannerInfo   = scannerInfo;
     VirtualCloneDrive = new VirtualCloneDriveWrapper(_driveLetter, _vcdmountPath);
     _unitOfWork       = new UnitOfWork();
 }