Ejemplo n.º 1
0
        public static string ResolvePathName(this string path, IEnvironmentPathNames pathNames)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (pathNames == null)
            {
                throw new ArgumentNullException(nameof(pathNames));
            }

            string resolved       = path;
            Regex  resolvePattern = new Regex(@"{(?<resolvable>\w+)}");
            Match  resolveMatch   = resolvePattern.Match(path);

            while (resolveMatch.Success)
            {
                string key = resolveMatch.Groups["resolvable"].Value;
                if (pathNames.ContainsKey(key))
                {
                    resolved = resolved.Replace(resolveMatch.Value, pathNames[key]);
                }

                resolveMatch = resolvePattern.Match(resolved);
            }

            return(resolved);
        }
        public MockedEnvironmentServiceAbstraction()
        {
            Assembly   assembly = Assembly.GetExecutingAssembly();
            string     codeBase = assembly.CodeBase;
            UriBuilder uri      = new UriBuilder(codeBase);
            string     path     = Uri.UnescapeDataString(uri.Path);

            environmentService.AssemblyVersion.Returns(new Version(2, 0, 0));
            environmentService.AssemblyDirectory.Returns(Path.GetDirectoryName(path));
            environmentService.PlatformName.Returns("linux");
            environmentService.Architecture.Returns("x64");
            environmentService.Platform.Returns(OSPlatform.Linux);
            IEnvironmentPathNames pathNames = Substitute.For <IEnvironmentPathNames>();

            pathNames.ContainsKey("ApplicationData").Returns(true);
            pathNames["ApplicationData"].Returns(Path.GetDirectoryName(path));
            pathNames.ContainsKey("ApplicationName").Returns(true);
            pathNames["ApplicationName"].Returns(assembly.GetName().Name);
            environmentService.PathNames.Returns(pathNames);
        }