Beispiel #1
0
        public void IntermediateDirectoryCanBeSpecified()
        {
            var intermediateDirectory = RandomString.Next(16);

            using (var t = new TempDirectory(intermediateDirectory))
            {
                var expectedParentOfTempDirectory = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), intermediateDirectory);
                var actualParentOfTempDirectory   = new DirectoryInfo(t.FullPath).Parent.FullName;

                Assert.AreEqual(expectedParentOfTempDirectory, actualParentOfTempDirectory);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates a temporary directory under the user's temp directory (i.e. the TEMP
        /// environment variable).
        ///
        /// Optionally the temporary directory may be created in an intermediate subdirectory
        /// of the user's TEMP directory.
        ///
        /// The temporary directory (but not the intermediate directory) will be automatically
        /// deleted when the TempDirectory object is disposed.
        /// </summary>
        public TempDirectory(string subdirectory = "")
        {
            var userTempDir = Environment.GetEnvironmentVariable("TEMP");

            if (userTempDir == null)
            {
                throw new Exception("TEMP environment variable is not set");
            }

            Name     = DateTime.UtcNow.ToString("yyyyMMdd-HHmmss-") + RandomString.Next();
            FullPath = Path.Combine(userTempDir, subdirectory, Name);

            Directory.CreateDirectory(FullPath);
        }
Beispiel #3
0
 public void ThrowsOnInvalidArgument()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => RandomString.Next(0));
     Assert.Throws <ArgumentOutOfRangeException>(() => RandomString.Next(-1));
     Assert.Throws <ArgumentOutOfRangeException>(() => RandomString.Next(17));
 }