提交 d7b717a1 编写于 作者: B Balaji Krishnan

Add Using Tests for Conditional Access Expressions.

tests for AddUsing in Conditional Access Expression cases.
上级 497cfe91
......@@ -186,5 +186,99 @@ public void TestAddUsingForAddExtentionMethod11()
@"using System ; using System . Collections ; using Ext2 ; class X : IEnumerable { public IEnumerator GetEnumerator ( ) { new X { { 1 , 2 , 3 } , { ""Four"" , ""Five"" , ""Six"" } , { '7' , '8' , '9' } } ; return null ; } } namespace Ext { static class Extensions { public static void Add ( this X x , int i ) { } } } namespace Ext2 { static class Extensions { public static void Add ( this X x , object [ ] i ) { } } } ",
null, 1, true, true, null, false, null);
}
[WorkItem(3818, "https://github.com/dotnet/roslyn/issues/3818")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddUsing)]
public void InExtensionMethodUnderConditionalAccessExpression()
{
var initialText =
@"<Workspace>
<Project Language=""C#"" AssemblyName=""CSAssembly"" CommonReferences=""true"">
<Document FilePath = ""Program"">
namespace Sample
{
class Program
{
static void Main(string[] args)
{
string myString = ""Sample"";
var other = myString?[|.StringExtension()|].Substring(0);
}
}
}
</Document>
<Document FilePath = ""Extensions"">
namespace Sample.Extensions
{
public static class StringExtensions
{
public static string StringExtension(this string s)
{
return ""Ok"";
}
}
}
</Document>
</Project>
</Workspace>";
var expectedText =
@"using Sample.Extensions;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
string myString = ""Sample"";
var other = myString?.StringExtension().Substring(0);
}
}
}";
Test(initialText, expectedText, isLine: false);
}
[WorkItem(3818, "https://github.com/dotnet/roslyn/issues/3818")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddUsing)]
public void InExtensionMethodUnderMultipleConditionalAccessExpressions()
{
var initialText =
@"<Workspace>
<Project Language=""C#"" AssemblyName=""CSAssembly"" CommonReferences=""true"">
<Document FilePath = ""Program"">
public class C
{
public T F&lt;T&gt;(T x)
{
return F(new C())?.F(new C())?[|.Extn()|];
}
}
</Document>
<Document FilePath = ""Extensions"">
namespace Sample.Extensions
{
public static class Extensions
{
public static C Extn(this C obj)
{
return obj.F(new C());
}
}
}
</Document>
</Project>
</Workspace>";
var expectedText =
@"using Sample.Extensions;
public class C
{
public T F<T>(T x)
{
return F(new C())?.F(new C())?.Extn();
}
}";
Test(initialText, expectedText, isLine: false);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册