Example #1
0
        private int InitializeSources(string[] sourcePaths)
        {
            var sourcePathsExpanded = sourcePaths
                .Union(SourceHelpers.GetDefaultSourceLocations())
                .Select(x => x.ReplaceEnvironmentVariables());

            return _symbols.SetSourcePathWide(string.Join(";", sourcePathsExpanded));
        }
        private static void AnalyzeAttribute(SyntaxNodeAnalysisContext context)
        {
            var attributeInfo = SourceHelpers.GetSourceAttributeInformation(
                context,
                NUnitFrameworkConstants.FullNameOfTypeValueSourceAttribute,
                NUnitFrameworkConstants.NameOfValueSourceAttribute);

            if (attributeInfo is null)
            {
                return;
            }

            var stringConstant = attributeInfo.SourceName;
            var syntaxNode     = attributeInfo.SyntaxNode;

            if (syntaxNode is null || stringConstant is null)
            {
                return;
            }

            var symbol = SourceHelpers.GetMember(attributeInfo);

            if (symbol is null)
            {
                context.ReportDiagnostic(Diagnostic.Create(
                                             missingSourceDescriptor,
                                             syntaxNode.GetLocation(),
                                             stringConstant));
            }
            else
            {
                SourceHelpers.ReportToUseNameOfIfApplicable(
                    context,
                    syntaxNode,
                    attributeInfo,
                    symbol,
                    stringConstant,
                    considerNameOfDescriptor);

                if (!symbol.IsStatic)
                {
                    context.ReportDiagnostic(Diagnostic.Create(
                                                 sourceNotStaticDescriptor,
                                                 syntaxNode.GetLocation(),
                                                 stringConstant));
                }

                ReportIfSymbolNotIEnumerable(context, symbol, syntaxNode);

                if (symbol is IMethodSymbol methodSymbol && methodSymbol.Parameters.Length != 0)
                {
                    context.ReportDiagnostic(Diagnostic.Create(
                                                 methodExpectParameters,
                                                 syntaxNode.GetLocation(),
                                                 methodSymbol.Parameters.Length));
                }
            }
        }
Example #3
0
        /// <summary>
        /// Gets the missing cell.
        /// </summary>
        public bool GetMissingCell(string path, string name)
        {
            var filename = name + ".SRTMGL1.hgt.zip";
            var local    = System.IO.Path.Combine(path, name + ".hgt.zip");

            var Logger = LogProvider.For <SRTMData>();

            Logger.Info("Downloading {0} ...", name);

            return(SourceHelpers.DownloadWithCredentials(_credentials, local, SOURCE + filename));
        }
Example #4
0
        /// <summary>
        /// Gets the missing cell.
        /// </summary>
        public static bool GetMissingCell(string path, string name)
        {
            var filename = name + ".hgt.zip";
            var local    = System.IO.Path.Combine(path, filename);

            Log($"Downloading {name} ...");
            foreach (var continent in CONTINENTS)
            {
                if (SourceHelpers.Download(local, SOURCE + continent + "/" + filename))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #5
0
        /// <summary>
        /// Gets the missing cell.
        /// </summary>
        public static bool GetMissingCell(string path, string name)
        {
            var filename = name + ".hgt.zip";
            var local    = System.IO.Path.Combine(path, filename);

            var Logger = LogProvider.For <SRTMData>();

            Logger.Info("Downloading {0} ...", name);
            foreach (var continent in CONTINENTS)
            {
                if (SourceHelpers.Download(local, SOURCE + continent + "/" + filename))
                {
                    return(true);
                }
            }
            return(false);
        }
        private static void AnalyzeAttribute(SyntaxNodeAnalysisContext context)
        {
            var attributeInfo = SourceHelpers.GetSourceAttributeInformation(
                context,
                NUnitFrameworkConstants.FullNameOfTypeTestCaseSourceAttribute,
                NUnitFrameworkConstants.NameOfTestCaseSourceAttribute);

            if (attributeInfo is null)
            {
                return;
            }

            var attributeNode  = (AttributeSyntax)context.Node;
            var stringConstant = attributeInfo.SourceName;

            if (stringConstant is null && attributeNode.ArgumentList?.Arguments.Count == 1)
            {
                // The Type argument in this form represents the class that provides test cases.
                // It must have a default constructor and implement IEnumerable.
                var  sourceType = attributeInfo.SourceType;
                bool typeImplementsIEnumerable = sourceType.IsIEnumerable(out _);
                bool typeHasDefaultConstructor = sourceType.Constructors.Any(c => c.Parameters.IsEmpty);
                if (!typeImplementsIEnumerable)
                {
                    context.ReportDiagnostic(Diagnostic.Create(
                                                 sourceTypeNotIEnumerableDescriptor,
                                                 attributeNode.ArgumentList.Arguments[0].GetLocation(),
                                                 sourceType.Name));
                }
                else if (!typeHasDefaultConstructor)
                {
                    context.ReportDiagnostic(Diagnostic.Create(
                                                 sourceTypeNoDefaultConstructorDescriptor,
                                                 attributeNode.ArgumentList.Arguments[0].GetLocation(),
                                                 sourceType.Name));
                }

                return;
            }

            var syntaxNode = attributeInfo.SyntaxNode;

            if (syntaxNode is null || stringConstant is null)
            {
                return;
            }

            var symbol = SourceHelpers.GetMember(attributeInfo);

            if (symbol is null)
            {
                context.ReportDiagnostic(Diagnostic.Create(
                                             missingSourceDescriptor,
                                             syntaxNode.GetLocation(),
                                             stringConstant));
            }
            else
            {
                SourceHelpers.ReportToUseNameOfIfApplicable(
                    context,
                    syntaxNode,
                    attributeInfo,
                    symbol,
                    stringConstant,
                    considerNameOfDescriptor);

                if (!symbol.IsStatic)
                {
                    context.ReportDiagnostic(Diagnostic.Create(
                                                 sourceNotStaticDescriptor,
                                                 syntaxNode.GetLocation(),
                                                 stringConstant));
                }

                switch (symbol)
                {
                case IPropertySymbol property:
                    ReportIfSymbolNotIEnumerable(context, syntaxNode, property.Type);
                    ReportIfParametersSupplied(context, syntaxNode, attributeInfo.NumberOfMethodParameters, "properties");
                    break;

                case IFieldSymbol field:
                    ReportIfSymbolNotIEnumerable(context, syntaxNode, field.Type);
                    ReportIfParametersSupplied(context, syntaxNode, attributeInfo.NumberOfMethodParameters, "fields");
                    break;

                case IMethodSymbol method:
                    ReportIfSymbolNotIEnumerable(context, syntaxNode, method.ReturnType);

                    var methodParametersFromAttribute = attributeInfo.NumberOfMethodParameters ?? 0;
                    if (method.Parameters.Length != methodParametersFromAttribute)
                    {
                        context.ReportDiagnostic(Diagnostic.Create(
                                                     mismatchInNumberOfParameters,
                                                     syntaxNode.GetLocation(),
                                                     methodParametersFromAttribute,
                                                     method.Parameters.Length));
                    }

                    break;
                }
            }
        }