public async Task VerifyGetFixesWhenUsingSystemExists() { var code = File.ReadAllText( $@"Targets\{nameof(IsBusinessObjectSerializableMakeSerializableCodeFixTests)}.{(nameof(this.VerifyGetFixesWhenUsingSystemExists))}.cs"); var document = TestHelpers.Create(code); var tree = await document.GetSyntaxTreeAsync(); var diagnostics = await TestHelpers.GetDiagnosticsAsync(code, new IsBusinessObjectSerializableAnalyzer()); 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 IsBusinessObjectSerializableMakeSerializableCodeFix(); 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.VerifyActionAsync(actions, IsBusinessObjectSerializableMakeSerializableCodeFixConstants.AddSerializableDescription, document, tree, $"{Environment.NewLine}[Serializable]"); }
public async Task VerifyGetFixesWhenUsingSystemDoesNotExists() { var code = @"using Csla; namespace Csla.Analyzers.Tests.Targets.IsBusinessObjectSerializableMakeSerializableCodeFixTests { public class VerifyGetFixesWhenUsingSystemDoesNotExists : BusinessBase<VerifyGetFixesWhenUsingSystemDoesNotExists> { public void DataPortal_Fetch() { } } }"; var document = TestHelpers.Create(code); var tree = await document.GetSyntaxTreeAsync(); var diagnostics = await TestHelpers.GetDiagnosticsAsync(code, new IsBusinessObjectSerializableAnalyzer()); 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 IsBusinessObjectSerializableMakeSerializableCodeFix(); 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.VerifyActionAsync(actions, IsBusinessObjectSerializableMakeSerializableCodeFixConstants.AddSerializableAndUsingDescription, document, tree, new[] { "using System;", "[Serializable]" }); }
public void VerifyGetFixableDiagnosticIds() { var fix = new IsBusinessObjectSerializableMakeSerializableCodeFix(); var ids = fix.FixableDiagnosticIds.ToList(); Assert.AreEqual(1, ids.Count, nameof(ids.Count)); Assert.AreEqual(IsBusinessObjectSerializableConstants.DiagnosticId, ids[0], nameof(IsBusinessObjectSerializableConstants.DiagnosticId)); }
public void VerifyGetFixableDiagnosticIds() { var fix = new IsBusinessObjectSerializableMakeSerializableCodeFix(); var ids = fix.FixableDiagnosticIds.ToList(); Assert.AreEqual(1, ids.Count, nameof(ids.Count)); Assert.AreEqual(ids[0], Constants.AnalyzerIdentifiers.IsBusinessObjectSerializable, nameof(Constants.AnalyzerIdentifiers.IsBusinessObjectSerializable)); }
public async Task VerifyGetFixesWhenUsingSystemDoesNotExists() { var code = @"using Csla; public class A : BusinessBase<A> { [Fetch] public void Fetch() { } }"; var document = TestHelpers.Create(code); var tree = await document.GetSyntaxTreeAsync(); var diagnostics = await TestHelpers.GetDiagnosticsAsync(code, new IsBusinessObjectSerializableAnalyzer()); 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 IsBusinessObjectSerializableMakeSerializableCodeFix(); 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, IsBusinessObjectSerializableMakeSerializableCodeFixConstants.AddSerializableAndUsingDescription, document, (model, newRoot) => { Assert.IsTrue(newRoot.DescendantNodes(_ => true).OfType <UsingDirectiveSyntax>().Any( _ => _.Name.GetText().ToString() == "System")); Assert.IsTrue(newRoot.DescendantNodes(_ => true).OfType <AttributeSyntax>().Any(_ => _.Name.ToString() == "Serializable")); }); }