Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
228 lines (205 sloc) 4.84 KB
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Roslynator.Tests;
using Xunit;
namespace Roslynator.CSharp.Refactorings.Tests
{
public class RR0021ChangeMethodReturnTypeToVoidTests : AbstractCSharpRefactoringVerifier
{
private readonly CodeVerificationOptions _options;
public RR0021ChangeMethodReturnTypeToVoidTests()
{
_options = base.Options.AddAllowedCompilerDiagnosticId(CompilerDiagnosticIdentifiers.NotAllCodePathsReturnValue);
}
public override string RefactoringId { get; } = RefactoringIdentifiers.ChangeMethodReturnTypeToVoid;
public override CodeVerificationOptions Options
{
get { return _options; }
}
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.ChangeMethodReturnTypeToVoid)]
public async Task Test_Method()
{
await VerifyRefactoringAsync(@"
class C
{
string M()
{[||]
M();
}
}
", @"
class C
{
void M()
{
M();
}
}
", equivalenceKey: RefactoringId);
}
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.ChangeMethodReturnTypeToVoid)]
public async Task Test_Method_IEnumerableOfT()
{
await VerifyRefactoringAsync(@"
class C
{
System.Collections.Generic.IEnumerable<string> M()
{[||]
M();
}
}
", @"
class C
{
void M()
{
M();
}
}
", equivalenceKey: RefactoringId);
}
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.ChangeMethodReturnTypeToVoid)]
public async Task Test_LocalFunction()
{
await VerifyRefactoringAsync(@"
class C
{
void M()
{
string LF()
{[||]
LF();
}
}
}
", @"
class C
{
void M()
{
void LF()
{
LF();
}
}
}
", equivalenceKey: RefactoringId);
}
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.ChangeMethodReturnTypeToVoid)]
public async Task TestNoRefactoring_MethodWithReturn()
{
await VerifyNoRefactoringAsync(@"
class C
{
string M()
{[||]
return M();
}
}
", equivalenceKey: RefactoringId);
}
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.ChangeMethodReturnTypeToVoid)]
public async Task TestNoRefactoring_VoidMethod()
{
await VerifyNoRefactoringAsync(@"
class C
{
void M()
{[||]
M();
}
}
", equivalenceKey: RefactoringId);
}
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.ChangeMethodReturnTypeToVoid)]
public async Task TestNoRefactoring_Iterator()
{
await VerifyNoRefactoringAsync(@"
using System.Collections.Generic;
class C
{
IEnumerable<string> M()
{[||]
yield return null;
}
}
", equivalenceKey: RefactoringId);
}
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.ChangeMethodReturnTypeToVoid)]
public async Task TestNoRefactoring_Iterator_YieldBreak()
{
await VerifyNoRefactoringAsync(@"
using System.Collections.Generic;
class C
{
IEnumerable<string> M()
{[||]
yield break;
}
}
", equivalenceKey: RefactoringId);
}
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.ChangeMethodReturnTypeToVoid)]
public async Task TestNoRefactoring_ReturnsTask()
{
await VerifyNoRefactoringAsync(@"
using System.Threading.Tasks;
class C
{
async Task M()
{[||]
string x = await Task.FromResult(default(string));
}
}
", equivalenceKey: RefactoringId);
}
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.ChangeMethodReturnTypeToVoid)]
public async Task TestNoRefactoring_Throws()
{
await VerifyNoRefactoringAsync(@"
using System;
class C
{
string M()
{[||]
throw new InvalidOperationException();
}
}
", equivalenceKey: RefactoringId);
}
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.ChangeMethodReturnTypeToVoid)]
public async Task TestNoRefactoring_InterfaceImplementation()
{
await VerifyNoRefactoringAsync(@"
interface IFoo
{
string M();
}
class C : IFoo
{
public string M()
{[||]
M();
}
}
", equivalenceKey: RefactoringId);
}
[Fact, Trait(Traits.Refactoring, RefactoringIdentifiers.ChangeMethodReturnTypeToVoid)]
public async Task TestNoRefactoring_Override()
{
await VerifyNoRefactoringAsync(@"
class B
{
public virtual string M() => null;
}
class C : B
{
public override string M()
{[||]
object x = null;
}
}
", equivalenceKey: RefactoringId);
}
}
}
You can’t perform that action at this time.