Example #1
0
        public void OneTimeSetUp()
        {
            try { RamDrive.Unmount('X'); } catch { }
            try { RamDrive.Unmount('Y'); } catch { }

            TestDelegate action = () => RamDrive.Mount(128, FileSystem.NTFS, 'X', "MyDriveName");

            Assert.DoesNotThrow(action);

            Drive = DriveInfo.GetDrives().FirstOrDefault(d => d.Name.ToUpper()[0] == 'X');
        }
Example #2
0
        /// <summary>
        /// Mounts a drive on system memory and creates SQL database there. (drops database if exists first)
        /// </summary>
        /// <param name="connectionString">Connection string to SQL database</param>
        /// <param name="sizeMegaByte">Size of ram drive in mega bytes</param>
        /// <param name="drive"></param>
        /// <returns></returns>
        public static IDisposable Create(string connectionString, int sizeMegaByte = 256, char drive = 'Z')
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            RamDrive.Mount(sizeMegaByte, RamDisk.FileSystem.NTFS, drive, "SqlInMemory");
            SqlHelper.DropDatabaseAndRecreate(connectionString, null, $"{drive}:\\", force: true);

            return(new Releaser(connectionString, drive));
        }
Example #3
0
        public void Another_Drive_Format_Should_Work_Correctly(FileSystem fileSystem)
        {
            TestDelegate action = () => RamDrive.Mount(128, fileSystem, 'Y', "RamDisk");

            Assert.DoesNotThrow(action);

            var drive = DriveInfo.GetDrives().FirstOrDefault(d => d.Name.ToUpper()[0] == 'Y');

            Assert.IsNotNull(drive);

            Assert.AreEqual(drive.DriveFormat, fileSystem.ToString());

            TestDelegate action2 = () => RamDrive.Unmount('Y');

            Assert.DoesNotThrow(action2);

            Thread.Sleep(100);

            var exists = DriveInfo.GetDrives().Any(d => d.Name.ToUpper()[0] == 'Y');

            Assert.IsFalse(exists);
        }
Example #4
0
        public void Null_Drive_Label_Should_Throws_ArgumentNullException()
        {
            TestDelegate action = () => RamDrive.Mount(128, FileSystem.NTFS, 'X', null);

            Assert.Throws <ArgumentNullException>(action);
        }
Example #5
0
        public void Negative_Drive_Size_Should_Throws_ArgumentException()
        {
            TestDelegate action = () => RamDrive.Mount(-128);

            Assert.Throws <ArgumentException>(action);
        }
Example #6
0
        public void Duplicate_Drive_Name_Should_Throws_InvalidOperationException()
        {
            TestDelegate action = () => RamDrive.Mount(128, FileSystem.NTFS, 'X', "MyDriveName");

            Assert.Throws <InvalidOperationException>(action);
        }