示例#1
0
    /// <summary>
    /// Creates the temp test directory. If <paramref name="rootDirectory"/> is specified, the directory
    /// will be created as a subdirectory of that root. Otherwise, the base directory of the current
    /// appdomain/appcontest is used.
    /// The directory will automatically be created if <paramref name="automaticallyCreate"/> is true.
    /// </summary>
    public TemporaryTestDirectory(string rootDirectory = null, bool automaticallyCreate = true)
    {
        while (true)
        {
            var number = Interlocked.Increment(ref _counter);

            _directoryPath = Path.Combine(rootDirectory ?? Shims.CurrentBaseDirectory(), $"testdirectory-{number}");

            if (!Directory.Exists(_directoryPath))
            {
                break;
            }
        }

        if (automaticallyCreate)
        {
            try
            {
                Directory.CreateDirectory(_directoryPath);

                Console.WriteLine($"Created test directory {_directoryPath}");
            }
            catch
            {
                if (!Directory.Exists(_directoryPath))
                {
                    throw;
                }
            }
        }
    }
示例#2
0
        /// <summary>
        /// Gets the assembly-qualified name of the type, without any version info etc.
        /// E.g. "System.String, mscorlib"
        /// </summary>
        public static string GetSimpleAssemblyQualifiedName(this Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            return(SimpleAssemblyQualifiedTypeNameCache.GetOrAdd(type,
                                                                 t => Shims.BuildSimpleAssemblyQualifiedName(t, new StringBuilder()).ToString()));
        }