Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Jul 29, 2024
1 parent 21c29e4 commit a05c62d
Showing 1 changed file with 50 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2776,7 +2776,9 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/30886")]
public async Task SerializableConstructor_BaseTypeImplementsISerializable()
{
var code = """
await new VerifyCS.Test
{
FixedCode = """
using System;
using System.Runtime.Serialization;
Expand All @@ -2795,9 +2797,8 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)
{
}
}
""";

await VerifyCS.VerifyCodeFixAsync(code, code);
""",
}.RunAsync();
}

[Theory]
Expand All @@ -2809,23 +2810,26 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)
[InlineData(@"[System.Runtime.InteropServices.ComUnregisterFunctionAttribute]")]
public async Task MethodsWithSpecialAttributes(string attribute)
{
var code = $$"""
await new VerifyCS.Test
{
FixedCode = $$"""
class C
{
{{attribute}}
private void M()
{
}
}
""";

await VerifyCS.VerifyCodeFixAsync(code, code);
""",
}.RunAsync();
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/30887")]
public async Task ShouldSerializePropertyMethod()
{
var code = """
await new VerifyCS.Test
{
FixedCode = """
class C
{
private bool ShouldSerializeData()
Expand All @@ -2835,15 +2839,16 @@ private bool ShouldSerializeData()
public int Data { get; private set; }
}
""";

await VerifyCS.VerifyCodeFixAsync(code, code);
""",
}.RunAsync();
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38491")]
public async Task ResetPropertyMethod()
{
var code = """
await new VerifyCS.Test
{
FixedCode = """
class C
{
private void ResetData()
Expand All @@ -2853,15 +2858,16 @@ private void ResetData()
public int Data { get; private set; }
}
""";

await VerifyCS.VerifyCodeFixAsync(code, code);
""",
}.RunAsync();
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/30377")]
public async Task EventHandlerMethod()
{
var code = """
await new VerifyCS.Test
{
FixedCode = """
using System;
class C
Expand All @@ -2870,15 +2876,16 @@ private void M(object o, EventArgs args)
{
}
}
""";

await VerifyCS.VerifyCodeFixAsync(code, code);
""",
}.RunAsync();
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/32727")]
public async Task NestedStructLayoutTypeWithReference()
{
var code = """
await new VerifyCS.Test
{
FixedCode = """
using System.Runtime.InteropServices;
class Program
Expand All @@ -2892,9 +2899,8 @@ internal struct ProcessEntry32
public string szExeFile;
}
}
""";

await VerifyCS.VerifyCodeFixAsync(code, code);
""",
}.RunAsync();
}

[Fact]
Expand Down Expand Up @@ -3129,44 +3135,47 @@ private static void UsedMethod() { }
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/32842")]
public async Task FieldIsRead_NullCoalesceAssignment()
{
var code = """
await new VerifyCS.Test
{
FixedCode = """
public class MyClass
{
private MyClass _field;
public MyClass Property => _field ??= new MyClass();
}
""";

await VerifyCS.VerifyCodeFixAsync(code, code);
""",
}.RunAsync();
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/32842")]
[WorkItem("https://github.com/dotnet/roslyn/issues/66975")]
public async Task FieldIsNotRead_NullCoalesceAssignment()
{
var code = """
await new VerifyCS.Test
{
FixedCode = """
public class MyClass
{
private MyClass _field;
public void M() => _field ??= new MyClass();
}
""";

await VerifyCS.VerifyCodeFixAsync(code, code);
""",
}.RunAsync();
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37213")]
public async Task UsedPrivateExtensionMethod()
{
var code = """
await new VerifyCS.Test
{
FixedCode = """
public static class B
{
public static void PublicExtensionMethod(this string s) => s.PrivateExtensionMethod();
private static void PrivateExtensionMethod(this string s) { }
}
""";

await VerifyCS.VerifyCodeFixAsync(code, code);
""",
}.RunAsync();
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/30884")]
Expand All @@ -3189,7 +3198,7 @@ class C
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/62856")]
public async Task DoNotWarnForAwaiterMethods()
{
const string code = """
await VerifyCS.VerifyAnalyzerAsync("""
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
Expand All @@ -3207,15 +3216,13 @@ private void GetResult() { }
public void OnCompleted(Action continuation) => Task.Run(continuation);
public void UnsafeOnCompleted(Action continuation) => Task.Run(continuation);
}
""";

await VerifyCS.VerifyAnalyzerAsync(code);
""");
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/62856")]
public async Task WarnForAwaiterMethodsNotImplementingInterface()
{
const string code = """
await VerifyCS.VerifyCodeFixAsync("""
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
Expand All @@ -3228,8 +3235,7 @@ class C
public void OnCompleted(Action continuation) => Task.Run(continuation);
public void UnsafeOnCompleted(Action continuation) => Task.Run(continuation);
}
""";
const string fixedCode = """
""", """
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
Expand All @@ -3239,8 +3245,6 @@ class C
public void OnCompleted(Action continuation) => Task.Run(continuation);
public void UnsafeOnCompleted(Action continuation) => Task.Run(continuation);
}
""";

await VerifyCS.VerifyCodeFixAsync(code, fixedCode);
""");
}
}

0 comments on commit a05c62d

Please sign in to comment.