Exemple #1
0
        public async Task VerifyGetFixes(string operationName, string attributeName, bool includeUsingCsla,
                                         string expectedDescription)
        {
            var code =
                $@"{(includeUsingCsla ? "using Csla;" : string.Empty)}

public class A : Csla.BusinessBase<A>
{{
  private void {operationName}() {{ }}
}}";
            var document = TestHelpers.Create(code);
            var tree     = await document.GetSyntaxTreeAsync();

            var diagnostics = await TestHelpers.GetDiagnosticsAsync(code, new DoesOperationHaveAttributeAnalyzer());

            var sourceSpan = diagnostics[0].Location.SourceSpan;

            var actions = new List <CodeAction>();
            var codeActionRegistration = new Action <CodeAction, ImmutableArray <Diagnostic> >(
                (a, _) => { actions.Add(a); });

            var fix            = new DoesOperationHaveAttributeAddAttributeCodeFix();
            var codeFixContext = new CodeFixContext(document, diagnostics[0],
                                                    codeActionRegistration, new CancellationToken(false));
            await fix.RegisterCodeFixesAsync(codeFixContext);

            Assert.AreEqual(1, actions.Count, nameof(actions.Count));

            var expectedTexts = includeUsingCsla ?
                                new[] { $"[{attributeName}]" } :
            new[] { "using Csla;", $"[{attributeName}]" };

            await TestHelpers.VerifyActionAsync(actions,
                                                expectedDescription, document, tree, expectedTexts);
        }
Exemple #2
0
        public void VerifyGetFixableDiagnosticIds()
        {
            var fix = new DoesOperationHaveAttributeAddAttributeCodeFix();
            var ids = fix.FixableDiagnosticIds.ToList();

            Assert.AreEqual(1, ids.Count, nameof(ids.Count));
            Assert.AreEqual(ids[0], Constants.AnalyzerIdentifiers.DoesOperationHaveAttribute,
                            nameof(Constants.AnalyzerIdentifiers.DoesOperationHaveAttribute));
        }
Exemple #3
0
        public async Task VerifyGetFixes(string operationName, string attributeName, bool includeUsingCsla,
                                         string expectedDescription)
        {
            var code =
                $@"{(includeUsingCsla ? "using Csla;" : string.Empty)}

public class A : Csla.BusinessBase<A>
{{
  private void {operationName}() {{ }}
}}";
            var document = TestHelpers.Create(code);
            var tree     = await document.GetSyntaxTreeAsync();

            var diagnostics = await TestHelpers.GetDiagnosticsAsync(code, new DoesOperationHaveAttributeAnalyzer());

            var sourceSpan = diagnostics[0].Location.SourceSpan;

            var actions = new List <CodeAction>();
            var codeActionRegistration = new Action <CodeAction, ImmutableArray <Diagnostic> >(
                (a, _) => { actions.Add(a); });

            var fix            = new DoesOperationHaveAttributeAddAttributeCodeFix();
            var codeFixContext = new CodeFixContext(document, diagnostics[0],
                                                    codeActionRegistration, new CancellationToken(false));
            await fix.RegisterCodeFixesAsync(codeFixContext);

            Assert.AreEqual(1, actions.Count, nameof(actions.Count));

            await TestHelpers.VerifyChangesAsync(actions,
                                                 expectedDescription, document,
                                                 (model, newRoot) =>
            {
                Assert.IsTrue(newRoot.DescendantNodes(_ => true).OfType <AttributeSyntax>().Any(_ => _.Name.ToString() == attributeName));

                if (includeUsingCsla)
                {
                    Assert.IsTrue(newRoot.DescendantNodes(_ => true).OfType <UsingDirectiveSyntax>().Any(
                                      _ => _.Name.GetText().ToString() == "Csla"));
                }
            });
        }