public async Task TestOneIterationRequiredForEachOfTwoDocuments(CodeFixTestBehaviors codeFixTestBehaviors) { var testCode1 = @" class TestClass1 { int field = [|4|]; } "; var testCode2 = @" class TestClass2 { int field = [|4|]; } "; var fixedCode1 = @" class TestClass1 { int field = 5; } "; var fixedCode2 = @" class TestClass2 { int field = 5; } "; await new CSharpTest { TestState = { Sources = { testCode1, testCode2 } }, FixedState = { Sources = { fixedCode1, fixedCode2 } }, CodeFixTestBehaviors = codeFixTestBehaviors, }.RunAsync(); }
public override async Task RunAsync(CancellationToken cancellationToken = default) { if (DiagnosticSelector is object) { Assert.True(CodeFixTestBehaviors.HasFlag(Testing.CodeFixTestBehaviors.FixOne), $"'{nameof(DiagnosticSelector)}' can only be used with '{nameof(Testing.CodeFixTestBehaviors)}.{nameof(Testing.CodeFixTestBehaviors.FixOne)}'"); } await base.RunAsync(cancellationToken); }
public async Task TestOneIterationRequiredForEachOfTwoDocumentsButDeclaredForAll(CodeFixTestBehaviors codeFixTestBehaviors, string context) { var testCode1 = @" class TestClass1 { int field = [|4|]; } "; var testCode2 = @" class TestClass2 { int field = [|4|]; } "; var fixedCode1 = @" class TestClass1 { int field = 5; } "; var fixedCode2 = @" class TestClass2 { int field = 5; } "; var exception = await Assert.ThrowsAsync <InvalidOperationException>(async() => { await new CSharpTest { TestState = { Sources = { testCode1, testCode2 } }, FixedState = { Sources = { fixedCode1, fixedCode2 } }, NumberOfFixAllIterations = 2, CodeFixTestBehaviors = codeFixTestBehaviors, }.RunAsync(); }); Assert.Equal($"Context: {context}{Environment.NewLine}Expected '2' iterations but found '1' iterations.", exception.Message); }
public static CodeFixTest <TVerifier> With <TVerifier>(this CodeFixTest <TVerifier> test, CodeFixTestBehaviors behavior) where TVerifier : IVerifier, new() { test.CodeFixTestBehaviors = behavior; return(test); }