Esempio n. 1
0
        private static Dependency HandleDependency(JsonClass dependency, IFilePathMapper pathMapper, NAMESettings configuration, NAMEContext context, int depth = 0)
        {
            if (depth == MAX_DEPENDENCY_DEPTH)
            {
                throw new NAMEException($"Reached the maximum dependency recursion of {MAX_DEPENDENCY_DEPTH}.");
            }

            if (dependency == null)
            {
                return(null);
            }
            var conditionObject = dependency["oneOf"];

            if (conditionObject != null)
            {
                depth++;
                return(new OneOfDependency(HandleDependencyArray(conditionObject.AsArray, pathMapper, configuration, context, depth)));
            }

            var minVersion = dependency["min_version"].Value;
            var maxVersion = dependency["max_version"].Value;
            var name       = dependency["name"]?.Value;
            var type       = dependency["type"]?.Value;
            var osName     = dependency["os_name"]?.Value;

            type = string.IsNullOrEmpty(type) ? SupportedDependencies.Service.ToString() : type;
            SupportedDependencies typedType;

            if (!Enum.TryParse(type, out typedType))
            {
                throw new NAMEException($"The dependency type {type} is not supported.");
            }

            VersionedDependency result;

            if (typedType == SupportedDependencies.OperatingSystem)
            {
                result = new OperatingSystemDependency()
                {
                    OperatingSystemName = osName,
                    MinimumVersion      = ParseVersion(minVersion, osName),
                    MaximumVersion      = ParseVersion(maxVersion, osName)
                };
            }
            else
            {
                var connectionStringProvider = ParseConnectionStringProvider(dependency["connection_string"], pathMapper);
                result = new ConnectedDependency(GetConnectedDependencyVersionResolver(typedType, connectionStringProvider, configuration, context))
                {
                    ConnectionStringProvider   = connectionStringProvider,
                    MinimumVersion             = ParseVersion(minVersion, type),
                    MaximumVersion             = ParseVersion(maxVersion, type),
                    ShowConnectionStringInJson = configuration.ConnectedDependencyShowConnectionString
                };
            }

            result.Name = name;
            result.Type = typedType;
            return(result);
        }
        public async Task WithoutShowingConnectionString()
        {
            var versionResolver            = new StaticVersionResolverMock(new[] { new DependencyVersion(1, 0, 0) });
            ConnectedDependency dependency = new ConnectedDependency(versionResolver)
            {
                MinimumVersion             = new DependencyVersion(0, 0, 1),
                MaximumVersion             = new DependencyVersion(9, 9, 9),
                Name                       = "Test",
                ShowConnectionStringInJson = false,
                Type                       = SupportedDependencies.Service
            };
            var result = await dependency.ToJson();

            Assert.Null(result["value"]);
        }