Beispiel #1
0
        public async Task TestNoDiagnostic_AssignedSymbolIsNull()
        {
            await VerifyNoDiagnosticAsync(@"
class C
{
    public string P { get; private set; }

    void M()
    {
        P = null;

        var c2 = new C2();
        c2.P = null;
    }
}

class C2
{
    public string P2 { get; }
}
", options : Options.AddAllowedCompilerDiagnosticId("CS1061"));
        }
Beispiel #2
0
        public async Task Test_Constructor()
        {
            await VerifyRefactoringAsync(@"
class C
{
    public C()
    {
    [||]}
}
", @"
class C
{
    public C()
    {
    }

    public C()
    {
    }
}
", equivalenceKey : RefactoringId, options : Options.AddAllowedCompilerDiagnosticId("CS0111"));
        }
Beispiel #3
0
        public async Task Test_PropertyWithGetterAndInitSetter()
        {
            await VerifyDiagnosticAndFixAsync(@"
class C
{
    string _f;

    public string P
    {
        get
        [|{
            return M(
                null,
                null);
        }|]

        init [|{ _f = value; }|]
    }

    string M(string x, string y) => null;
}
", @"
class C
{
    string _f;

    public string P
    {
        get => M(
            null,
            null);

        init => _f = value;
    }

    string M(string x, string y) => null;
}
", options : Options.AddAllowedCompilerDiagnosticId("CS0518"));
        }
        public async Task Test_InitSetter()
        {
            await VerifyDiagnosticAndFixAsync(@"
class C
{
    string _p;

    string P
    {
        get
        {
            return _p;
        }

        init [|{|] _p = value; }
    }
}
", @"
class C
{
    string _p;

    string P
    {
        get
        {
            return _p;
        }

        init
        {
            _p = value;
        }
    }
}
", options : Options.AddAllowedCompilerDiagnosticId("CS0518")
                                              .AddConfigOption(ConfigOptionKeys.AccessorBracesStyle, ConfigOptionValues.AccessorBracesStyle_MultiLine));
        }
Beispiel #5
0
        public async Task Test_Property_InitSetter()
        {
            await VerifyRefactoringAsync(@"
class C
{
    private string value;

    public string [||]Value { get; init; }
}
", @"
class C
{
    private string value;
    private string value2;

    public string Value
    {
        get { return value2; }
        init { value2 = value; }
    }
}
", equivalenceKey : RefactoringId, options : Options.AddAllowedCompilerDiagnosticId("CS0518"));
        }
Beispiel #6
0
        public async Task Test_InitSetter()
        {
            await VerifyDiagnosticAndFixAsync(@"
class C
{
    string _p;

    string P
    {
        get
        {
            return _p;
        }

        init {[||] _p = value; }
    }
}
", @"
class C
{
    string _p;

    string P
    {
        get
        {
            return _p;
        }

        init
        {
            _p = value;
        }
    }
}
", options : Options.AddAllowedCompilerDiagnosticId("CS0518"));
        }
        public async Task Test_AttributeWithTarget_Multiline()
        {
            await VerifyRefactoringAsync(@"
using System;

namespace N
{
    public record R(
        [||][property: Obsolete] string P,
        object O);
}

namespace System.Runtime.CompilerServices { internal static class IsExternalInit {} }
", @"
using System;

namespace N
{
    public record R
    {
        public R(
            string p,
            object o)
        {
            P = p;
            O = o;
        }

        [Obsolete]
        public string P { get; init; }
        public object O { get; init; }
    }
}

namespace System.Runtime.CompilerServices { internal static class IsExternalInit {} }
", options : Options.AddAllowedCompilerDiagnosticId("CS0612"), equivalenceKey : EquivalenceKey.Create(RefactoringId));
        }
        public async Task Test_AnonymousMethod()
        {
            await VerifyRefactoringAsync(@"
using System;
using System.Threading.Tasks;

class C
{
    Task<object> GetAsync()
    {
        Func<object, Task<object>> func = [||]async delegate (object f)
        {
            return await GetAsync();
        };

        return GetAsync();
    }
}
", @"
using System;
using System.Threading.Tasks;

class C
{
    Task<object> GetAsync()
    {
        Func<object, Task<object>> func = delegate (object f)
        {
            return GetAsync();
        };

        return GetAsync();
    }
}
", options : Options.AddAllowedCompilerDiagnosticId("CS1998"), equivalenceKey : EquivalenceKey.Create(RefactoringId));
        }
        public async Task Test_ParenthesizedLambda_Body()
        {
            await VerifyRefactoringAsync(@"
using System;
using System.Threading.Tasks;

class C
{
    Task<object> GetAsync()
    {
        Func<object, Task<object>> func = [||]async (f) =>
        {
            return await GetAsync();
        };

        return GetAsync();
    }
}
", @"
using System;
using System.Threading.Tasks;

class C
{
    Task<object> GetAsync()
    {
        Func<object, Task<object>> func = (f) =>
        {
            return GetAsync();
        };

        return GetAsync();
    }
}
", options : Options.AddAllowedCompilerDiagnosticId("CS1998"), equivalenceKey : EquivalenceKey.Create(RefactoringId));
        }
Beispiel #10
0
        public async Task Test_Indexer()
        {
            await VerifyRefactoringAsync(@"
class C
{
    void M()
    {
    }

    public string this[int index]
    [||]{
        get { return null; }
        set { }
    }
}
", @"
class C
{
    void M()
    {
    }

    public string this[int index]
    {
        get { return null; }
        set { }
    }

    public string this[int index]
    {
        get { return null; }
        set { }
    }
}
", equivalenceKey : RefactoringId, options : Options.AddAllowedCompilerDiagnosticId("CS0111"));
        }
        public async Task Test_SimpleLambda_Body()
        {
            await VerifyRefactoringAsync(@"
using System;
using System.Threading.Tasks;

class C
{
    Task<object> GetAsync()
    {
        Func<object, Task<object>> func = [||]async f =>
        {
            return await GetAsync();
        };

        return GetAsync();
    }
}
", @"
using System;
using System.Threading.Tasks;

class C
{
    Task<object> GetAsync()
    {
        Func<object, Task<object>> func = f =>
        {
            return GetAsync();
        };

        return GetAsync();
    }
}
", options : Options.AddAllowedCompilerDiagnosticId("CS1998"));
        }
Beispiel #12
0
        public async Task Test_AnonymousMethod()
        {
            await VerifyDiagnosticAndFixAsync(@"
using System;
using System.Threading.Tasks;

class C
{
    Task<object> GetAsync()
    {
        Func<object, Task<object>> func = [|async|] delegate (object f)
        {
            return await GetAsync();
        };

        return GetAsync();
    }
}
", @"
using System;
using System.Threading.Tasks;

class C
{
    Task<object> GetAsync()
    {
        Func<object, Task<object>> func = delegate (object f)
        {
            return GetAsync();
        };

        return GetAsync();
    }
}
", options : Options.AddAllowedCompilerDiagnosticId("CS1998"));
        }
Beispiel #13
0
        public async Task Test_ParenthesizedLambda_Body()
        {
            await VerifyDiagnosticAndFixAsync(@"
using System;
using System.Threading.Tasks;

class C
{
    Task<object> GetAsync()
    {
        Func<object, Task<object>> func = [|async|] (f) =>
        {
            return await GetAsync();
        };

        return GetAsync();
    }
}
", @"
using System;
using System.Threading.Tasks;

class C
{
    Task<object> GetAsync()
    {
        Func<object, Task<object>> func = (f) =>
        {
            return GetAsync();
        };

        return GetAsync();
    }
}
", options : Options.AddAllowedCompilerDiagnosticId("CS1998"));
        }
        public async Task TestNoDiagnostic()
        {
            await VerifyNoDiagnosticAsync(@"
class C
{
    void M(bool f1 = false, bool f2 = false)
    {
        if (f1)
        {
        }
        else
        {
        }

        if (f1)
        {
        }
        else if (f2)
        {
        }

        if (f1)
        {
            M();
        }
        else
        {
            M();
        }

        if (f1)
        {
            M();
        }
        else if (f2)
        {
            M();
        }

        if (f1)
        {
        }
        else if (f2)
        {
            M();
        }
        else
        {
        }

        if ()
        {
        }
        else if (f2)
        {
            M();
        }

        if (f1)
        {
        }
        else if ()
        {
            M();
        }
    }
}
", options : Options.AddAllowedCompilerDiagnosticId("CS1525"));
        }
        public async Task TestNoDiagnostic_Do()
        {
            await VerifyNoDiagnosticAsync(@"
class C
{
    void M(bool f1 = false, bool f2 = false)
    {
        do
        {
            M();

            if (f2)
            {
                break;
            }

        } while (f1);

        do
        {
            M();

            if (f2)
            {
                return;
            }
        }
        while (f1);

        do
        {
            M();

            if (f1)
            {
                break;
            }
        }
        while ();

        do
        {
            M();

            if ()
            {
                break;
            }
        }
        while (f1);

        do
        {
            M();

            if (f2)
            {
                break;
            }

        } while (f1);

        do
        {
            M();

            if (f2)
            {
                return;
            }

        } while (f1);

        do
        {
            M();

            if (f1)
            {
                break;
            }

        } while ();

        do
        {
            M();

            if ()
            {
                break;
            }

        } while (f1);
    }
}
", options : Options.AddAllowedCompilerDiagnosticId("CS1525"));
        }
        public async Task Test_EmptyInterpolatedString()
        {
            await VerifyRefactoringAsync(@"
class C
{
    void M()
    {
        var x = $""[||]"";
    }
}
", @"
class C
{
    void M()
    {
        var x = $""{}"";
    }
}
",
                                         equivalenceKey : EquivalenceKey.Create(RefactoringId), options : Options.AddAllowedCompilerDiagnosticId("CS1733"));
        }