示例#1
0
        public void TestKeyword()
        {
            { // test one keyword
                string keyword  = "keyword1";
                string expected = string.Format(HelpUrlBuilder.HelpUrlPrefix +
                                                "en-US&k=k({0})" + HelpUrlBuilder.HelpUrlSuffix, Uri.EscapeDataString(keyword));

                string actual = HelpUrlBuilder.Build(new Dictionary <string, string[]>
                {
                    { "keyword", new[] { keyword } }
                });

                Assert.AreEqual(expected, actual, ignoreCase: true);
                Assert.IsTrue(Uri.IsWellFormedUriString(actual, UriKind.Absolute));
            }

            { // test multiple keywords
                string[] keywords = new[] { "keyword1", "keyword2" };
                string   expected = HelpUrlBuilder.HelpUrlPrefix + "en-US";
                foreach (var keyword in keywords)
                {
                    expected += string.Format("&k=k({0})", Uri.EscapeDataString(keyword));
                }
                expected += HelpUrlBuilder.HelpUrlSuffix;

                string actual = HelpUrlBuilder.Build(new Dictionary <string, string[]>
                {
                    { "keyword", keywords }
                });

                Assert.AreEqual(expected, actual, ignoreCase: true);
                Assert.IsTrue(Uri.IsWellFormedUriString(actual, UriKind.Absolute));
            }
        }
 internal static Diagnostic Create(SyntaxNode currentNode) =>
 Diagnostic.Create(new DiagnosticDescriptor(
                       NoPropertyMapsFoundDiagnostic.Id, NoPropertyMapsFoundDiagnostic.Title,
                       NoPropertyMapsFoundDiagnostic.Message, DescriptorConstants.Usage, DiagnosticSeverity.Error, true,
                       helpLinkUri: HelpUrlBuilder.Build(
                           NoPropertyMapsFoundDiagnostic.Id, NoPropertyMapsFoundDiagnostic.Title)),
                   currentNode.GetLocation());
示例#3
0
        public void VerifySupportedDiagnostics()
        {
            var analyzer    = new FindSaveAssignmentIssueAnalyzer();
            var diagnostics = analyzer.SupportedDiagnostics;

            Assert.AreEqual(2, diagnostics.Length);

            var saveDiagnostic = diagnostics.Single(_ => _.Id == Constants.AnalyzerIdentifiers.FindSaveAssignmentIssue);

            Assert.AreEqual(FindSaveAssignmentIssueAnalyzerConstants.Title, saveDiagnostic.Title.ToString(),
                            nameof(DiagnosticDescriptor.Title));
            Assert.AreEqual(FindSaveAssignmentIssueAnalyzerConstants.Message, saveDiagnostic.MessageFormat.ToString(),
                            nameof(DiagnosticDescriptor.MessageFormat));
            Assert.AreEqual(Constants.Categories.Usage, saveDiagnostic.Category,
                            nameof(DiagnosticDescriptor.Category));
            Assert.AreEqual(DiagnosticSeverity.Error, saveDiagnostic.DefaultSeverity,
                            nameof(DiagnosticDescriptor.DefaultSeverity));
            Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.FindSaveAssignmentIssue, nameof(FindSaveAssignmentIssueAnalyzer)),
                            saveDiagnostic.HelpLinkUri,
                            nameof(DiagnosticDescriptor.HelpLinkUri));

            var saveAsyncDiagnostic = diagnostics.Single(_ => _.Id == Constants.AnalyzerIdentifiers.FindSaveAsyncAssignmentIssue);

            Assert.AreEqual(FindSaveAsyncAssignmentIssueAnalyzerConstants.Title, saveAsyncDiagnostic.Title.ToString(),
                            nameof(DiagnosticDescriptor.Title));
            Assert.AreEqual(FindSaveAsyncAssignmentIssueAnalyzerConstants.Message, saveAsyncDiagnostic.MessageFormat.ToString(),
                            nameof(DiagnosticDescriptor.MessageFormat));
            Assert.AreEqual(Constants.Categories.Usage, saveAsyncDiagnostic.Category,
                            nameof(DiagnosticDescriptor.Category));
            Assert.AreEqual(DiagnosticSeverity.Error, saveAsyncDiagnostic.DefaultSeverity,
                            nameof(DiagnosticDescriptor.DefaultSeverity));
            Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.FindSaveAsyncAssignmentIssue, nameof(FindSaveAssignmentIssueAnalyzer)),
                            saveAsyncDiagnostic.HelpLinkUri,
                            nameof(DiagnosticDescriptor.HelpLinkUri));
        }
        public void VerifySupportedDiagnostics()
        {
            var analyzer    = new IsOperationMethodPublicAnalyzer();
            var diagnostics = analyzer.SupportedDiagnostics;

            Assert.AreEqual(2, diagnostics.Length);

            var diagnostic = diagnostics.Single(_ => _.Id == Constants.AnalyzerIdentifiers.IsOperationMethodPublic);

            Assert.AreEqual(IsOperationMethodPublicAnalyzerConstants.Title, diagnostic.Title.ToString(),
                            nameof(DiagnosticDescriptor.Title));
            Assert.AreEqual(IsOperationMethodPublicAnalyzerConstants.Message, diagnostic.MessageFormat.ToString(),
                            nameof(DiagnosticDescriptor.MessageFormat));
            Assert.AreEqual(Constants.Categories.Design, diagnostic.Category,
                            nameof(DiagnosticDescriptor.Category));
            Assert.AreEqual(DiagnosticSeverity.Warning, diagnostic.DefaultSeverity,
                            nameof(DiagnosticDescriptor.DefaultSeverity));
            Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.IsOperationMethodPublic, nameof(IsOperationMethodPublicAnalyzer)),
                            diagnostic.HelpLinkUri,
                            nameof(DiagnosticDescriptor.HelpLinkUri));

            var diagnosticForInterface = diagnostics.Single(_ => _.Id == Constants.AnalyzerIdentifiers.IsOperationMethodPublicForInterface);

            Assert.AreEqual(IsOperationMethodPublicAnalyzerConstants.Title, diagnosticForInterface.Title.ToString(),
                            nameof(DiagnosticDescriptor.Title));
            Assert.AreEqual(IsOperationMethodPublicAnalyzerConstants.Message, diagnosticForInterface.MessageFormat.ToString(),
                            nameof(DiagnosticDescriptor.MessageFormat));
            Assert.AreEqual(Constants.Categories.Design, diagnosticForInterface.Category,
                            nameof(DiagnosticDescriptor.Category));
            Assert.AreEqual(DiagnosticSeverity.Warning, diagnosticForInterface.DefaultSeverity,
                            nameof(DiagnosticDescriptor.DefaultSeverity));
            Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.IsOperationMethodPublicForInterface, nameof(IsOperationMethodPublicAnalyzer)),
                            diagnosticForInterface.HelpLinkUri,
                            nameof(DiagnosticDescriptor.HelpLinkUri));
        }
 internal static Diagnostic Create(IPropertySymbol property, string targetName, INamedTypeSymbol target) =>
 Diagnostic.Create(new DiagnosticDescriptor(
                       NoMatchDiagnostic.Id, NoMatchDiagnostic.Title,
                       string.Format(CultureInfo.CurrentCulture, NoMatchDiagnostic.Message, property.Name, targetName, target.Name),
                       DescriptorConstants.Usage, DiagnosticSeverity.Info, true,
                       helpLinkUri: HelpUrlBuilder.Build(
                           NoMatchDiagnostic.Id, NoMatchDiagnostic.Title)), null);
示例#6
0
 public static Diagnostic Create(SyntaxNode currentNode) =>
 Diagnostic.Create(new DiagnosticDescriptor(
                       NoArgumentConstructorDiagnostic.Id, NoArgumentConstructorDiagnostic.Title,
                       NoArgumentConstructorDiagnostic.Message, DescriptorConstants.Usage, DiagnosticSeverity.Error, true,
                       helpLinkUri: HelpUrlBuilder.Build(
                           NoArgumentConstructorDiagnostic.Id, NoArgumentConstructorDiagnostic.Title)),
                   currentNode.GetLocation());
示例#7
0
        public void VerifySupportedDiagnostics()
        {
            var analyzer    = new CheckConstructorsAnalyzer();
            var diagnostics = analyzer.SupportedDiagnostics;

            Assert.AreEqual(2, diagnostics.Length);

            var ctorHasParametersDiagnostic = diagnostics.Single(_ => _.Id == Constants.AnalyzerIdentifiers.ConstructorHasParameters);

            Assert.AreEqual(ConstructorHasParametersConstants.Title, ctorHasParametersDiagnostic.Title.ToString(),
                            nameof(DiagnosticDescriptor.Title));
            Assert.AreEqual(ConstructorHasParametersConstants.Message, ctorHasParametersDiagnostic.MessageFormat.ToString(),
                            nameof(DiagnosticDescriptor.MessageFormat));
            Assert.AreEqual(Constants.Categories.Usage, ctorHasParametersDiagnostic.Category,
                            nameof(DiagnosticDescriptor.Category));
            Assert.AreEqual(DiagnosticSeverity.Warning, ctorHasParametersDiagnostic.DefaultSeverity,
                            nameof(DiagnosticDescriptor.DefaultSeverity));
            Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.ConstructorHasParameters, nameof(CheckConstructorsAnalyzer)),
                            ctorHasParametersDiagnostic.HelpLinkUri,
                            nameof(DiagnosticDescriptor.HelpLinkUri));

            var publicNoArgsCtorDiagnostic = diagnostics.Single(_ => _.Id == Constants.AnalyzerIdentifiers.PublicNoArgumentConstructorIsMissing);

            Assert.AreEqual(PublicNoArgumentConstructorIsMissingConstants.Title, publicNoArgsCtorDiagnostic.Title.ToString(),
                            nameof(DiagnosticDescriptor.Title));
            Assert.AreEqual(PublicNoArgumentConstructorIsMissingConstants.Message, publicNoArgsCtorDiagnostic.MessageFormat.ToString(),
                            nameof(DiagnosticDescriptor.MessageFormat));
            Assert.AreEqual(Constants.Categories.Usage, publicNoArgsCtorDiagnostic.Category,
                            nameof(DiagnosticDescriptor.Category));
            Assert.AreEqual(DiagnosticSeverity.Error, publicNoArgsCtorDiagnostic.DefaultSeverity,
                            nameof(DiagnosticDescriptor.DefaultSeverity));
            Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.PublicNoArgumentConstructorIsMissing, nameof(CheckConstructorsAnalyzer)),
                            publicNoArgsCtorDiagnostic.HelpLinkUri,
                            nameof(DiagnosticDescriptor.HelpLinkUri));
        }
 internal static Diagnostic Create(SyntaxNode currentNode, SyntaxNode previousNode) =>
 Diagnostic.Create(new DiagnosticDescriptor(
                       DuplicatedAttributeDiagnostic.Id, DuplicatedAttributeDiagnostic.Title,
                       DuplicatedAttributeDiagnostic.Message, DescriptorConstants.Usage, DiagnosticSeverity.Warning, true,
                       helpLinkUri: HelpUrlBuilder.Build(
                           DuplicatedAttributeDiagnostic.Id, DuplicatedAttributeDiagnostic.Title)),
                   currentNode.GetLocation(), new[] { previousNode });
示例#9
0
        public void TestDefault()
        {
            // default culture is en-US
            string expected = HelpUrlBuilder.HelpUrlPrefix + "en-US" + HelpUrlBuilder.HelpUrlSuffix;

            string actual = HelpUrlBuilder.Build(new Dictionary <string, string[]>());

            Assert.AreEqual(expected, actual, ignoreCase: true);
            Assert.IsTrue(Uri.IsWellFormedUriString(actual, UriKind.Absolute));
        }
示例#10
0
        public void TestFrameworkMoniker()
        {
            string expected = string.Format(HelpUrlBuilder.HelpUrlPrefix + "en-US;k(TargetFrameworkMoniker-{0})" + HelpUrlBuilder.HelpUrlSuffix,
                                            Uri.EscapeDataString(".NETFramework,Version=v4.5.2"));

            string actual = HelpUrlBuilder.Build(new Dictionary <string, string[]>(StringComparer.CurrentCultureIgnoreCase)
            {
                { "TargetFrameworkMoniker", new[] { ".NETFramework,Version=v4.5.2" } }
            });

            Assert.AreEqual(expected, actual, ignoreCase: true);
            Assert.IsTrue(Uri.IsWellFormedUriString(actual, UriKind.Absolute));
        }
示例#11
0
        public void TestDevLang()
        {
            string expected = string.Format(HelpUrlBuilder.HelpUrlPrefix + "en-US;k(DevLang-{0})" + HelpUrlBuilder.HelpUrlSuffix,
                                            Uri.EscapeDataString("csharp"));

            string actual = HelpUrlBuilder.Build(new Dictionary <string, string[]>(StringComparer.CurrentCultureIgnoreCase)
            {
                { "devlang", new[] { "csharp" } }
            });

            Assert.AreEqual(expected, actual, ignoreCase: true);
            Assert.IsTrue(Uri.IsWellFormedUriString(actual, UriKind.Absolute));
        }
示例#12
0
        public void VerifySupportedDiagnostics()
        {
            var analyzer    = new EvaluateOperationAttributeUsageAnalyzer();
            var diagnostics = analyzer.SupportedDiagnostics;

            Assert.AreEqual(1, diagnostics.Length);

            var diagnostic = diagnostics.Single(_ => _.Id == Constants.AnalyzerIdentifiers.IsOperationAttributeUsageCorrect);

            Assert.AreEqual(EvaluateOperationAttributeUsageAnalyzerConstants.Title, diagnostic.Title.ToString(),
                            nameof(DiagnosticDescriptor.Title));
            Assert.AreEqual(EvaluateOperationAttributeUsageAnalyzerConstants.Message, diagnostic.MessageFormat.ToString(),
                            nameof(DiagnosticDescriptor.MessageFormat));
            Assert.AreEqual(Constants.Categories.Usage, diagnostic.Category,
                            nameof(DiagnosticDescriptor.Category));
            Assert.AreEqual(DiagnosticSeverity.Error, diagnostic.DefaultSeverity,
                            nameof(DiagnosticDescriptor.DefaultSeverity));
            Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.IsOperationAttributeUsageCorrect, nameof(EvaluateOperationAttributeUsageAnalyzer)),
                            diagnostic.HelpLinkUri,
                            nameof(DiagnosticDescriptor.HelpLinkUri));
        }
        public void VerifySupportedDiagnostics()
        {
            var analyzer    = new EvaluatePropertiesForSimplicityAnalyzer();
            var diagnostics = analyzer.SupportedDiagnostics;

            Assert.AreEqual(1, diagnostics.Length);

            var ctorHasParametersDiagnostic = diagnostics.Single(_ => _.Id == Constants.AnalyzerIdentifiers.OnlyUseCslaPropertyMethodsInGetSetRule);

            Assert.AreEqual(OnlyUseCslaPropertyMethodsInGetSetRuleConstants.Title, ctorHasParametersDiagnostic.Title.ToString(),
                            nameof(DiagnosticDescriptor.Title));
            Assert.AreEqual(OnlyUseCslaPropertyMethodsInGetSetRuleConstants.Message, ctorHasParametersDiagnostic.MessageFormat.ToString(),
                            nameof(DiagnosticDescriptor.MessageFormat));
            Assert.AreEqual(Constants.Categories.Usage, ctorHasParametersDiagnostic.Category,
                            nameof(DiagnosticDescriptor.Category));
            Assert.AreEqual(DiagnosticSeverity.Warning, ctorHasParametersDiagnostic.DefaultSeverity,
                            nameof(DiagnosticDescriptor.DefaultSeverity));
            Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.OnlyUseCslaPropertyMethodsInGetSetRule, nameof(EvaluatePropertiesForSimplicityAnalyzer)),
                            ctorHasParametersDiagnostic.HelpLinkUri,
                            nameof(DiagnosticDescriptor.HelpLinkUri));
        }
        public void VerifySupportedDiagnostics()
        {
            var analyzer    = new AsynchronousBusinessRuleInheritingFromBusinessRuleAnalyzer();
            var diagnostics = analyzer.SupportedDiagnostics;

            Assert.AreEqual(1, diagnostics.Length);

            var diagnostic = diagnostics[0];

            Assert.AreEqual(Constants.AnalyzerIdentifiers.AsynchronousBusinessRuleInheritance, diagnostic.Id,
                            nameof(DiagnosticDescriptor.Id));
            Assert.AreEqual(AsynchronousBusinessRuleInheritingFromBusinessRuleAnalyzerConstants.Title, diagnostic.Title.ToString(),
                            nameof(DiagnosticDescriptor.Title));
            Assert.AreEqual(AsynchronousBusinessRuleInheritingFromBusinessRuleAnalyzerConstants.Message, diagnostic.MessageFormat.ToString(),
                            nameof(DiagnosticDescriptor.MessageFormat));
            Assert.AreEqual(Constants.Categories.Usage, diagnostic.Category,
                            nameof(DiagnosticDescriptor.Category));
            Assert.AreEqual(DiagnosticSeverity.Error, diagnostic.DefaultSeverity,
                            nameof(DiagnosticDescriptor.DefaultSeverity));
            Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.AsynchronousBusinessRuleInheritance, nameof(AsynchronousBusinessRuleInheritingFromBusinessRuleAnalyzer)),
                            diagnostic.HelpLinkUri,
                            nameof(DiagnosticDescriptor.HelpLinkUri));
        }
        public void VerifySupportedDiagnostics()
        {
            var analyzer    = new BusinessRuleDoesNotUseAddMethodsOnContextAnalyzer();
            var diagnostics = analyzer.SupportedDiagnostics;

            Assert.AreEqual(1, diagnostics.Length);

            var diagnostic = diagnostics[0];

            Assert.AreEqual(Constants.AnalyzerIdentifiers.BusinessRuleContextUsage, diagnostic.Id,
                            nameof(DiagnosticDescriptor.Id));
            Assert.AreEqual(BusinessRuleDoesNotUseAddMethodsOnContextAnalyzerConstants.Title, diagnostic.Title.ToString(),
                            nameof(DiagnosticDescriptor.Title));
            Assert.AreEqual(BusinessRuleDoesNotUseAddMethodsOnContextAnalyzerConstants.Message, diagnostic.MessageFormat.ToString(),
                            nameof(DiagnosticDescriptor.MessageFormat));
            Assert.AreEqual(Constants.Categories.Usage, diagnostic.Category,
                            nameof(DiagnosticDescriptor.Category));
            Assert.AreEqual(DiagnosticSeverity.Warning, diagnostic.DefaultSeverity,
                            nameof(DiagnosticDescriptor.DefaultSeverity));
            Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.BusinessRuleContextUsage, nameof(BusinessRuleDoesNotUseAddMethodsOnContextAnalyzer)),
                            diagnostic.HelpLinkUri,
                            nameof(DiagnosticDescriptor.HelpLinkUri));
        }
示例#16
0
        public void VerifySupportedDiagnostics()
        {
            var analyzer    = new FindBusinessObjectCreationAnalyzer();
            var diagnostics = analyzer.SupportedDiagnostics;

            Assert.AreEqual(1, diagnostics.Length);

            var diagnostic = diagnostics[0];

            Assert.AreEqual(Constants.AnalyzerIdentifiers.FindBusinessObjectCreation, diagnostic.Id,
                            nameof(DiagnosticDescriptor.Id));
            Assert.AreEqual(FindBusinessObjectCreationConstants.Title, diagnostic.Title.ToString(),
                            nameof(DiagnosticDescriptor.Title));
            Assert.AreEqual(FindBusinessObjectCreationConstants.Message, diagnostic.MessageFormat.ToString(),
                            nameof(DiagnosticDescriptor.MessageFormat));
            Assert.AreEqual(Constants.Categories.Usage, diagnostic.Category,
                            nameof(DiagnosticDescriptor.Category));
            Assert.AreEqual(DiagnosticSeverity.Error, diagnostic.DefaultSeverity,
                            nameof(DiagnosticDescriptor.DefaultSeverity));
            Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.FindBusinessObjectCreation, nameof(FindBusinessObjectCreationAnalyzer)),
                            diagnostic.HelpLinkUri,
                            nameof(DiagnosticDescriptor.HelpLinkUri));
        }
        public void VerifySupportedDiagnostics()
        {
            var analyzer    = new FindOperationsWithNonSerializableArgumentsAnalyzer();
            var diagnostics = analyzer.SupportedDiagnostics;

            Assert.AreEqual(1, diagnostics.Length);

            var diagnostic = diagnostics[0];

            Assert.AreEqual(Constants.AnalyzerIdentifiers.FindOperationsWithNonSerializableArguments, diagnostic.Id,
                            nameof(DiagnosticDescriptor.Id));
            Assert.AreEqual(FindOperationsWithNonSerializableArgumentsConstants.Title, diagnostic.Title.ToString(),
                            nameof(DiagnosticDescriptor.Title));
            Assert.AreEqual(FindOperationsWithNonSerializableArgumentsConstants.Message, diagnostic.MessageFormat.ToString(),
                            nameof(DiagnosticDescriptor.MessageFormat));
            Assert.AreEqual(Constants.Categories.Design, diagnostic.Category,
                            nameof(DiagnosticDescriptor.Category));
            Assert.AreEqual(DiagnosticSeverity.Warning, diagnostic.DefaultSeverity,
                            nameof(DiagnosticDescriptor.DefaultSeverity));
            Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.FindOperationsWithNonSerializableArguments, nameof(FindOperationsWithNonSerializableArgumentsAnalyzer)),
                            diagnostic.HelpLinkUri,
                            nameof(DiagnosticDescriptor.HelpLinkUri));
        }
        public void VerifySupportedDiagnostics()
        {
            var analyzer    = new DoesOperationHaveAttributeAnalyzer();
            var diagnostics = analyzer.SupportedDiagnostics;

            Assert.AreEqual(1, diagnostics.Length);

            var diagnostic = diagnostics[0];

            Assert.AreEqual(Constants.AnalyzerIdentifiers.DoesOperationHaveAttribute, diagnostic.Id,
                            nameof(DiagnosticDescriptor.Id));
            Assert.AreEqual(DoesOperationHaveAttributeAnalyzerConstants.Title, diagnostic.Title.ToString(),
                            nameof(DiagnosticDescriptor.Title));
            Assert.AreEqual(DoesOperationHaveAttributeAnalyzerConstants.Message, diagnostic.MessageFormat.ToString(),
                            nameof(DiagnosticDescriptor.MessageFormat));
            Assert.AreEqual(Constants.Categories.Usage, diagnostic.Category,
                            nameof(DiagnosticDescriptor.Category));
            Assert.AreEqual(DiagnosticSeverity.Info, diagnostic.DefaultSeverity,
                            nameof(DiagnosticDescriptor.DefaultSeverity));
            Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.DoesOperationHaveAttribute, nameof(DoesOperationHaveAttributeAnalyzer)),
                            diagnostic.HelpLinkUri,
                            nameof(DiagnosticDescriptor.HelpLinkUri));
        }
 public static void Create() =>
 Assert.That(HelpUrlBuilder.Build("a", "b"),
             Is.EqualTo("https://github.com/JasonBock/InlineMapping/tree/main/docs/a-b.md"));
示例#20
0
        public void Build()
        {
            var url = HelpUrlBuilder.Build("a", "b");

            Assert.AreEqual("https://github.com/MarimerLLC/csla/tree/master/docs/analyzers/a-b.md", url);
        }