提交 05322fcb 编写于 作者: C Cyrus Najmabadi

Update tests to conformant codestyle behavior

上级 73c7dcef
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Options;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions
{
internal static class UseVarTestExtensions
{
private static readonly CodeStyleOption<bool> onWithNone = new CodeStyleOption<bool>(true, NotificationOption.None);
private static readonly CodeStyleOption<bool> offWithNone = new CodeStyleOption<bool>(false, NotificationOption.None);
private static readonly CodeStyleOption<bool> onWithSilent = new CodeStyleOption<bool>(true, NotificationOption.Silent);
private static readonly CodeStyleOption<bool> offWithSilent = new CodeStyleOption<bool>(false, NotificationOption.Silent);
private static readonly CodeStyleOption<bool> onWithInfo = new CodeStyleOption<bool>(true, NotificationOption.Suggestion);
private static readonly CodeStyleOption<bool> offWithInfo = new CodeStyleOption<bool>(false, NotificationOption.Suggestion);
private static readonly CodeStyleOption<bool> onWithWarning = new CodeStyleOption<bool>(true, NotificationOption.Warning);
private static readonly CodeStyleOption<bool> offWithWarning = new CodeStyleOption<bool>(false, NotificationOption.Warning);
private static readonly CodeStyleOption<bool> offWithError = new CodeStyleOption<bool>(false, NotificationOption.Error);
private static readonly CodeStyleOption<bool> onWithError = new CodeStyleOption<bool>(true, NotificationOption.Error);
public static IDictionary<OptionKey, object> PreferExplicitTypeWithError(this AbstractCodeActionOrUserDiagnosticTest test)
=> AbstractCodeActionOrUserDiagnosticTest.OptionsSet(
test.SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithError),
test.SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithError),
test.SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithError));
public static IDictionary<OptionKey, object> PreferImplicitTypeWithError(this AbstractCodeActionOrUserDiagnosticTest test)
=> AbstractCodeActionOrUserDiagnosticTest.OptionsSet(
test.SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithError),
test.SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithError),
test.SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, onWithError));
public static IDictionary<OptionKey, object> PreferExplicitTypeWithWarning(this AbstractCodeActionOrUserDiagnosticTest test)
=> AbstractCodeActionOrUserDiagnosticTest.OptionsSet(
test.SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithWarning),
test.SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithWarning),
test.SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithWarning));
public static IDictionary<OptionKey, object> PreferImplicitTypeWithWarning(this AbstractCodeActionOrUserDiagnosticTest test)
=> AbstractCodeActionOrUserDiagnosticTest.OptionsSet(
test.SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithWarning),
test.SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithWarning),
test.SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, onWithWarning));
public static IDictionary<OptionKey, object> PreferExplicitTypeWithInfo(this AbstractCodeActionOrUserDiagnosticTest test)
=> AbstractCodeActionOrUserDiagnosticTest.OptionsSet(
test.SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithInfo),
test.SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithInfo),
test.SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithInfo));
public static IDictionary<OptionKey, object> PreferImplicitTypeWithInfo(this AbstractCodeActionOrUserDiagnosticTest test)
=> AbstractCodeActionOrUserDiagnosticTest.OptionsSet(
test.SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithInfo),
test.SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithInfo),
test.SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, onWithInfo));
public static IDictionary<OptionKey, object> PreferExplicitTypeWithSilent(this AbstractCodeActionOrUserDiagnosticTest test)
=> AbstractCodeActionOrUserDiagnosticTest.OptionsSet(
test.SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithSilent),
test.SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithSilent),
test.SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithSilent));
public static IDictionary<OptionKey, object> PreferImplicitTypeWithSilent(this AbstractCodeActionOrUserDiagnosticTest test)
=> AbstractCodeActionOrUserDiagnosticTest.OptionsSet(
test.SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithSilent),
test.SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithSilent),
test.SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, onWithSilent));
public static IDictionary<OptionKey, object> PreferExplicitTypeWithNone(this AbstractCodeActionOrUserDiagnosticTest test)
=> AbstractCodeActionOrUserDiagnosticTest.OptionsSet(
test.SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithNone),
test.SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithNone),
test.SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithNone));
public static IDictionary<OptionKey, object> PreferImplicitTypeWithNone(this AbstractCodeActionOrUserDiagnosticTest test)
=> AbstractCodeActionOrUserDiagnosticTest.OptionsSet(
test.SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithNone),
test.SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithNone),
test.SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, onWithNone));
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
using Microsoft.CodeAnalysis.Options;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings.UseExplicitOrImplicitType
{
public abstract class AbstractUseTypeRefactoringTests : AbstractCSharpCodeActionTest
{
private readonly CodeStyleOption<bool> onWithNone = new CodeStyleOption<bool>(true, NotificationOption.None);
private readonly CodeStyleOption<bool> offWithNone = new CodeStyleOption<bool>(false, NotificationOption.None);
private readonly CodeStyleOption<bool> onWithSilent = new CodeStyleOption<bool>(true, NotificationOption.Silent);
private readonly CodeStyleOption<bool> offWithSilent = new CodeStyleOption<bool>(false, NotificationOption.Silent);
private readonly CodeStyleOption<bool> onWithInfo = new CodeStyleOption<bool>(true, NotificationOption.Suggestion);
private readonly CodeStyleOption<bool> offWithInfo = new CodeStyleOption<bool>(false, NotificationOption.Suggestion);
private readonly CodeStyleOption<bool> onWithWarning = new CodeStyleOption<bool>(true, NotificationOption.Warning);
private readonly CodeStyleOption<bool> offWithWarning = new CodeStyleOption<bool>(false, NotificationOption.Warning);
private readonly CodeStyleOption<bool> offWithError = new CodeStyleOption<bool>(false, NotificationOption.Error);
private readonly CodeStyleOption<bool> onWithError = new CodeStyleOption<bool>(true, NotificationOption.Error);
protected IDictionary<OptionKey, object> PreferExplicitTypeWithError() => OptionsSet(
SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithError),
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithError),
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithError));
protected IDictionary<OptionKey, object> PreferImplicitTypeWithError() => OptionsSet(
SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithError),
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithError),
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, onWithError));
protected IDictionary<OptionKey, object> PreferExplicitTypeWithWarning() => OptionsSet(
SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithWarning),
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithWarning),
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithWarning));
protected IDictionary<OptionKey, object> PreferImplicitTypeWithWarning() => OptionsSet(
SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithWarning),
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithWarning),
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, onWithWarning));
protected IDictionary<OptionKey, object> PreferExplicitTypeWithInfo() => OptionsSet(
SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithInfo),
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithInfo),
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithInfo));
protected IDictionary<OptionKey, object> PreferImplicitTypeWithInfo() => OptionsSet(
SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithInfo),
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithInfo),
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, onWithInfo));
protected IDictionary<OptionKey, object> PreferExplicitTypeWithSilent() => OptionsSet(
SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithSilent),
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithSilent),
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithSilent));
protected IDictionary<OptionKey, object> PreferImplicitTypeWithSilent() => OptionsSet(
SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithSilent),
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithSilent),
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, onWithSilent));
protected IDictionary<OptionKey, object> PreferExplicitTypeWithNone() => OptionsSet(
SingleOption(CSharpCodeStyleOptions.VarElsewhere, offWithNone),
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithNone),
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, offWithNone));
protected IDictionary<OptionKey, object> PreferImplicitTypeWithNone() => OptionsSet(
SingleOption(CSharpCodeStyleOptions.VarElsewhere, onWithNone),
SingleOption(CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithNone),
SingleOption(CSharpCodeStyleOptions.VarForBuiltInTypes, onWithNone));
}
}
......@@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.CSharp.CodeRefactorings.UseExplicitType;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
......@@ -10,7 +11,7 @@
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings.UseExplicitOrImplicitType
{
[Trait(Traits.Feature, Traits.Features.CodeActionsUseExplicitType)]
public class UseExplicitTypeRefactoringTests : AbstractUseTypeRefactoringTests
public class UseExplicitTypeRefactoringTests : AbstractCSharpCodeActionTest
{
protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspace workspace, TestParameters parameters)
=> new UseExplicitTypeCodeRefactoringProvider();
......@@ -424,36 +425,36 @@ static void Main()
private async Task TestInRegularAndScriptWhenDiagnosticNotAppliedAsync(string initialMarkup, string expectedMarkup)
{
// Enabled because the diagnostic is disabled
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: PreferExplicitTypeWithNone());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: this.PreferExplicitTypeWithNone());
// Enabled because the diagnostic is checking for the other direction
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: PreferImplicitTypeWithNone());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: PreferImplicitTypeWithSilent());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: PreferImplicitTypeWithInfo());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: this.PreferImplicitTypeWithNone());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: this.PreferImplicitTypeWithSilent());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: this.PreferImplicitTypeWithInfo());
// Disabled because the diagnostic will report it instead
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferExplicitTypeWithSilent()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferExplicitTypeWithInfo()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferExplicitTypeWithWarning()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferExplicitTypeWithError()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferExplicitTypeWithSilent()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferExplicitTypeWithInfo()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferExplicitTypeWithWarning()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferExplicitTypeWithError()));
// Currently this refactoring is still enabled in cases where it would cause a warning or error
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: PreferImplicitTypeWithWarning());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: PreferImplicitTypeWithError());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: this.PreferImplicitTypeWithWarning());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: this.PreferImplicitTypeWithError());
}
private async Task TestMissingInRegularAndScriptAsync(string initialMarkup)
{
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferImplicitTypeWithNone()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferExplicitTypeWithNone()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferImplicitTypeWithSilent()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferExplicitTypeWithSilent()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferImplicitTypeWithInfo()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferExplicitTypeWithInfo()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferImplicitTypeWithWarning()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferExplicitTypeWithWarning()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferImplicitTypeWithError()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferExplicitTypeWithError()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferImplicitTypeWithNone()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferExplicitTypeWithNone()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferImplicitTypeWithSilent()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferExplicitTypeWithSilent()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferImplicitTypeWithInfo()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferExplicitTypeWithInfo()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferImplicitTypeWithWarning()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferExplicitTypeWithWarning()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferImplicitTypeWithError()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferExplicitTypeWithError()));
}
}
}
......@@ -6,11 +6,12 @@
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings.UseExplicitOrImplicitType
{
[Trait(Traits.Feature, Traits.Features.CodeActionsUseImplicitType)]
public class UseImplicitTypeRefactoringTests : AbstractUseTypeRefactoringTests
public class UseImplicitTypeRefactoringTests : AbstractCSharpCodeActionTest
{
protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspace workspace, TestParameters parameters)
=> new UseImplicitTypeCodeRefactoringProvider();
......@@ -424,36 +425,36 @@ static void Main(string[] args)
private async Task TestInRegularAndScriptWhenDiagnosticNotAppliedAsync(string initialMarkup, string expectedMarkup)
{
// Enabled because the diagnostic is disabled
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: PreferImplicitTypeWithNone());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: this.PreferImplicitTypeWithNone());
// Enabled because the diagnostic is checking for the other direction
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: PreferExplicitTypeWithNone());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: PreferExplicitTypeWithSilent());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: PreferExplicitTypeWithInfo());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: this.PreferExplicitTypeWithNone());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: this.PreferExplicitTypeWithSilent());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: this.PreferExplicitTypeWithInfo());
// Disabled because the diagnostic will report it instead
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferImplicitTypeWithSilent()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferImplicitTypeWithInfo()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferImplicitTypeWithWarning()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferImplicitTypeWithError()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferImplicitTypeWithSilent()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferImplicitTypeWithInfo()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferImplicitTypeWithWarning()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferImplicitTypeWithError()));
// Currently this refactoring is still enabled in cases where it would cause a warning or error
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: PreferExplicitTypeWithWarning());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: PreferExplicitTypeWithError());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: this.PreferExplicitTypeWithWarning());
await TestInRegularAndScriptAsync(initialMarkup, expectedMarkup, options: this.PreferExplicitTypeWithError());
}
private async Task TestMissingInRegularAndScriptAsync(string initialMarkup)
{
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferImplicitTypeWithNone()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferExplicitTypeWithNone()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferImplicitTypeWithSilent()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferExplicitTypeWithSilent()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferImplicitTypeWithInfo()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferExplicitTypeWithInfo()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferImplicitTypeWithWarning()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferExplicitTypeWithWarning()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferImplicitTypeWithError()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: PreferExplicitTypeWithError()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferImplicitTypeWithNone()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferExplicitTypeWithNone()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferImplicitTypeWithSilent()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferExplicitTypeWithSilent()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferImplicitTypeWithInfo()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferExplicitTypeWithInfo()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferImplicitTypeWithWarning()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferExplicitTypeWithWarning()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferImplicitTypeWithError()));
await TestMissingInRegularAndScriptAsync(initialMarkup, parameters: new TestParameters(options: this.PreferExplicitTypeWithError()));
}
}
}
......@@ -4,6 +4,7 @@
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.CSharp.ConvertAnonymousTypeToClass;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
......@@ -61,6 +62,57 @@ public override int GetHashCode()
hashCode = hashCode * -1521134295 + B.GetHashCode();
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[WorkItem(39916, "https://github.com/dotnet/roslyn/issues/39916")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
public async Task ConvertSingleAnonymousType_Explicit()
{
var text = @"
class Test
{
void Method()
{
var t1 = [||]new { a = 1, b = 2 };
}
}
";
var expected = @"
class Test
{
void Method()
{
var t1 = new {|Rename:NewClass|}(1, 2);
}
}
internal class NewClass
{
public int A { get; }
public int B { get; }
public NewClass(int a, int b)
{
A = a;
B = b;
}
public override bool Equals(object obj)
{
return obj is NewClass other &&
A == other.A &&
B == other.B;
}
public override int GetHashCode()
{
int hashCode = -1817952719;
hashCode = hashCode * -1521134295 + A.GetHashCode();
hashCode = hashCode * -1521134295 + B.GetHashCode();
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
}
......@@ -194,7 +246,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -246,7 +298,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -310,7 +362,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -366,7 +418,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -422,7 +474,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -486,7 +538,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -536,7 +588,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -588,7 +640,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -656,7 +708,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -708,7 +760,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -760,7 +812,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -812,7 +864,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -870,7 +922,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -920,7 +972,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -970,7 +1022,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -1032,7 +1084,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -1094,7 +1146,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -1156,7 +1208,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertAnonymousTypeToClass)]
......@@ -1218,7 +1270,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[WorkItem(35180, "https://github.com/dotnet/roslyn/issues/35180")]
......@@ -1269,7 +1321,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[WorkItem(35180, "https://github.com/dotnet/roslyn/issues/35180")]
......@@ -1320,7 +1372,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[WorkItem(35180, "https://github.com/dotnet/roslyn/issues/35180")]
......@@ -1371,7 +1423,7 @@ public override int GetHashCode()
return hashCode;
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
}
}
......@@ -5,8 +5,10 @@
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.CSharp.ConvertTupleToStruct;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ConvertTupleToStruct
......@@ -79,6 +81,73 @@ public static implicit operator (int a, int b)(NewStruct value)
return (value.a, value.b);
}
public static implicit operator NewStruct((int a, int b) value)
{
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[WorkItem(39916, "https://github.com/dotnet/roslyn/issues/39916")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
public async Task ConvertSingleTupleType_Explicit()
{
var text = @"
class Test
{
void Method()
{
var t1 = [||](a: 1, b: 2);
}
}
";
var expected = @"
class Test
{
void Method()
{
var t1 = new {|Rename:NewStruct|}(a: 1, b: 2);
}
}
internal struct NewStruct
{
public int a;
public int b;
public NewStruct(int a, int b)
{
this.a = a;
this.b = b;
}
public override bool Equals(object obj)
{
return obj is NewStruct other &&
a == other.a &&
b == other.b;
}
public override int GetHashCode()
{
int hashCode = 2118541809;
hashCode = hashCode * -1521134295 + a.GetHashCode();
hashCode = hashCode * -1521134295 + b.GetHashCode();
return hashCode;
}
public void Deconstruct(out int a, out int b)
{
a = this.a;
b = this.b;
}
public static implicit operator (int a, int b)(NewStruct value)
{
return (value.a, value.b);
}
public static implicit operator NewStruct((int a, int b) value)
{
return new NewStruct(value.a, value.b);
......@@ -150,7 +219,7 @@ public static implicit operator (int, int)(NewStruct value)
return new NewStruct(value.Item1, value.Item2);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -216,7 +285,7 @@ public static implicit operator (int, int b)(NewStruct value)
return new NewStruct(value.Item1, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -284,7 +353,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -352,7 +421,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -420,7 +489,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -488,7 +557,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -561,7 +630,7 @@ public static implicit operator (int a, int b)(NewStruct value)
}
}
";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -627,7 +696,7 @@ public static implicit operator (object a, object b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -693,7 +762,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -761,7 +830,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -841,7 +910,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -913,7 +982,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -985,7 +1054,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -1065,7 +1134,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -1131,7 +1200,7 @@ public static implicit operator (int a, object)(NewStruct value)
return new NewStruct(value.a, value.Item2);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -1215,7 +1284,7 @@ public static implicit operator (int a, object b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -1283,7 +1352,7 @@ public static implicit operator (int a, object b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -1351,7 +1420,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -1424,7 +1493,7 @@ public static implicit operator (List<X> a, Y[] b)(NewStruct<X, Y> value)
{
FeaturesResources.updating_usages_in_containing_member
});
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -1498,7 +1567,7 @@ public static implicit operator (int a, int b)(NewStruct1 value)
return new NewStruct1(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -1564,7 +1633,7 @@ public static implicit operator (int a, int a)(NewStruct value)
return new NewStruct(value.a, value.a);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -1642,7 +1711,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -1720,7 +1789,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -1798,7 +1867,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -1876,7 +1945,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -1955,7 +2024,7 @@ public static implicit operator (int, int)(NewStruct value)
FeaturesResources.updating_usages_in_containing_member,
FeaturesResources.updating_usages_in_containing_type,
});
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -2034,7 +2103,7 @@ public static implicit operator (int Item1, int Item2)(NewStruct value)
FeaturesResources.updating_usages_in_containing_member,
FeaturesResources.updating_usages_in_containing_type,
});
await TestInRegularAndScriptAsync(text, expected);
await TestInRegularAndScriptAsync(text, expected, options: this.PreferImplicitTypeWithInfo());
}
protected override ParseOptions GetScriptOptions()
......@@ -2140,7 +2209,7 @@ public static implicit operator (T a, int b)(NewStruct<T> value)
FeaturesResources.updating_usages_in_containing_member,
FeaturesResources.updating_usages_in_containing_type
});
await TestInRegularAndScriptAsync(text, expected, index: 1);
await TestInRegularAndScriptAsync(text, expected, index: 1, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -2236,7 +2305,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected, index: 1);
await TestInRegularAndScriptAsync(text, expected, index: 1, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -2338,7 +2407,7 @@ public static implicit operator (int a, int b)(NewStruct value)
return new NewStruct(value.a, value.b);
}
}";
await TestInRegularAndScriptAsync(text, expected, index: 1);
await TestInRegularAndScriptAsync(text, expected, index: 1, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -2473,7 +2542,7 @@ void Goo()
</Document>
</Project>
</Workspace>";
await TestInRegularAndScriptAsync(text, expected, index: 1);
await TestInRegularAndScriptAsync(text, expected, index: 1, options: this.PreferImplicitTypeWithInfo());
}
#endregion update containing project tests
......@@ -2619,7 +2688,7 @@ void Goo()
</Document>
</Project>
</Workspace>";
await TestInRegularAndScriptAsync(text, expected, index: 2);
await TestInRegularAndScriptAsync(text, expected, index: 2, options: this.PreferImplicitTypeWithInfo());
}
#endregion
......@@ -2747,7 +2816,7 @@ void Goo()
</Document>
</Project>
</Workspace>";
await TestInRegularAndScriptAsync(text, expected, index: 3);
await TestInRegularAndScriptAsync(text, expected, index: 3, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
......@@ -2869,7 +2938,7 @@ void Goo()
</Document>
</Project>
</Workspace>";
await TestInRegularAndScriptAsync(text, expected, index: 3);
await TestInRegularAndScriptAsync(text, expected, index: 3, options: this.PreferImplicitTypeWithInfo());
}
#endregion
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
using Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Options;
......
......@@ -6,7 +6,8 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings.UseExplicitOrImplicitType;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings;
using Microsoft.CodeAnalysis.GenerateEqualsAndGetHashCodeFromMembers;
using Microsoft.CodeAnalysis.PickMembers;
using Microsoft.CodeAnalysis.Test.Utilities;
......@@ -17,7 +18,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.GenerateEqualsAndGetHas
{
using static GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider;
public class GenerateEqualsAndGetHashCodeFromMembersTests : AbstractUseTypeRefactoringTests
public class GenerateEqualsAndGetHashCodeFromMembersTests : AbstractCSharpCodeActionTest
{
private static readonly TestParameters CSharp6 =
new TestParameters(parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp6));
......@@ -25,8 +26,8 @@ public class GenerateEqualsAndGetHashCodeFromMembersTests : AbstractUseTypeRefac
protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspace workspace, TestParameters parameters)
=> new GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider((IPickMembersService)parameters.fixProviderData);
private TestParameters CSharp6Implicit => CSharp6.WithOptions(PreferImplicitTypeWithInfo());
private TestParameters CSharp6Explicit => CSharp6.WithOptions(PreferExplicitTypeWithInfo());
private TestParameters CSharp6Implicit => CSharp6.WithOptions(this.PreferImplicitTypeWithInfo());
private TestParameters CSharp6Explicit => CSharp6.WithOptions(this.PreferExplicitTypeWithInfo());
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
public async Task TestEqualsSingleField()
......@@ -151,7 +152,7 @@ public override int GetHashCode()
{
return -1757793268 + EqualityComparer<S?>.Default.GetHashCode(a);
}
}", index: 1, options: PreferImplicitTypeWithInfo());
}", index: 1, options: this.PreferImplicitTypeWithInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
......
......@@ -3,9 +3,11 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.UseSystemHashCode;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UseSystemHashCode
......@@ -1157,8 +1159,9 @@ class C
}");
}
[WorkItem(39916, "https://github.com/dotnet/roslyn/issues/39916")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseSystemHashCode)]
public async Task TestManyFields()
public async Task TestManyFields_ImplicitType()
{
await TestInRegularAndScriptAsync(
@"using System.Collections.Generic;
......@@ -1204,6 +1207,57 @@ public override int GetHashCode()
hash.Add(i);
return hash.ToHashCode();
}
}", options: this.PreferImplicitTypeWithInfo());
}
[WorkItem(39916, "https://github.com/dotnet/roslyn/issues/39916")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseSystemHashCode)]
public async Task TestManyFields_ExplicitType()
{
await TestInRegularAndScriptAsync(
@"using System.Collections.Generic;
namespace System { public struct HashCode { } }
class C
{
int a, b, c, d, e, f, g, h, i;
public override int $$GetHashCode()
{
var hashCode = -538000506;
hashCode = hashCode * -1521134295 + a.GetHashCode();
hashCode = hashCode * -1521134295 + b.GetHashCode();
hashCode = hashCode * -1521134295 + c.GetHashCode();
hashCode = hashCode * -1521134295 + d.GetHashCode();
hashCode = hashCode * -1521134295 + e.GetHashCode();
hashCode = hashCode * -1521134295 + f.GetHashCode();
hashCode = hashCode * -1521134295 + g.GetHashCode();
hashCode = hashCode * -1521134295 + h.GetHashCode();
hashCode = hashCode * -1521134295 + i.GetHashCode();
return hashCode;
}
}",
@"using System.Collections.Generic;
namespace System { public struct HashCode { } }
class C
{
int a, b, c, d, e, f, g, h, i;
public override int GetHashCode()
{
System.HashCode hash = new System.HashCode();
hash.Add(a);
hash.Add(b);
hash.Add(c);
hash.Add(d);
hash.Add(e);
hash.Add(f);
hash.Add(g);
hash.Add(h);
hash.Add(i);
return hash.ToHashCode();
}
}");
}
}
......
......@@ -608,7 +608,7 @@ protected static ImmutableArray<CodeAction> FlattenActions(ImmutableArray<CodeAc
protected static ImmutableArray<CodeAction> GetNestedActions(ImmutableArray<CodeAction> codeActions)
=> codeActions.SelectMany(a => a.NestedCodeActions).ToImmutableArray();
protected (OptionKey, object) SingleOption<T>(Option<T> option, T enabled)
internal (OptionKey, object) SingleOption<T>(Option<T> option, T enabled)
=> (new OptionKey(option), enabled);
protected (OptionKey, object) SingleOption<T>(PerLanguageOption<T> option, T value)
......@@ -644,7 +644,7 @@ protected static (OptionKey, object) SingleOption<T>(PerLanguageOption<CodeStyle
protected IDictionary<OptionKey, object> Option<T>(PerLanguageOption<CodeStyleOption<T>> option, CodeStyleOption<T> codeStyle)
=> OptionsSet(SingleOption(option, codeStyle));
protected static IDictionary<OptionKey, object> OptionsSet(
internal static IDictionary<OptionKey, object> OptionsSet(
params (OptionKey key, object value)[] options)
{
var result = new Dictionary<OptionKey, object>();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册