Skip to content

Commit 5b0dc82

Browse files
committed
Add new tests
1 parent aea0359 commit 5b0dc82

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveAttributeCompletionItemProviderTest.AttributeNames.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,32 @@ public void GetCompletionItems_OnDirectiveAttributeName_bind_ReturnsCompletions(
6969
AssertContains(completions, "bind", "@bind", ["="]);
7070
}
7171

72+
[Fact]
73+
public void GetCompletionItems_OnDirectiveAttributeName_bind_ReturnsParameterCompletions()
74+
{
75+
// Arrange
76+
var context = CreateRazorCompletionContext("<input @$$ />");
77+
78+
// Act
79+
var completions = _provider.GetCompletionItems(context);
80+
81+
// Assert
82+
AssertContainsParameter(completions, "bind-value:format", "@bind-value:format", ["="]);
83+
}
84+
85+
[Fact]
86+
public void GetCompletionItems_OnDirectiveAttributeName_bind_ReturnsParameterSnippetCompletions()
87+
{
88+
// Arrange
89+
var context = CreateRazorCompletionContext("<input @$$ />");
90+
91+
// Act
92+
var completions = _provider.GetCompletionItems(context);
93+
94+
// Assert
95+
AssertContainsParameter(completions, "bind-value:format", "@bind-value:format", ["="]);
96+
}
97+
7298
[Fact]
7399
public void GetCompletionItems_OnDirectiveAttributeName_attributes_ReturnsCompletions()
74100
{
@@ -195,6 +221,19 @@ public void GetAttributeCompletions_SelectedDirectiveAttribute_IsIncludedInCompl
195221
AssertContains(completions, "bind=\"$0\"", "@bind", ["="]);
196222
}
197223

224+
[Fact]
225+
public void GetAttributeCompletions_Parameter_IsIncludedInCompletions()
226+
{
227+
// Arrange
228+
var context = GetDefaultDirectivateAttributeCompletionContext("@bind");
229+
230+
// Act
231+
var completions = DirectiveAttributeCompletionItemProvider.GetAttributeCompletions("input", context, _defaultTagHelperContext);
232+
233+
// Assert
234+
AssertContains(completions, "bind-value=\"$0\"", "@bind-value", ["="]);
235+
}
236+
198237
[Fact]
199238
public void GetAttributeCompletions_NonIndexer_ReturnsCompletion()
200239
{

src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveAttributeCompletionItemProviderTest.ParameterNames.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,43 @@ public void GetAttributeParameterCompletions_ReturnsCompletion()
9292
AssertContains(completions, "format");
9393
}
9494

95+
[Fact]
96+
public void GetAttributeParameterCompletions_ReturnsSnippetCompletion()
97+
{
98+
// Arrange
99+
var context = GetDefaultDirectiveAttributeCompletionContext("@bind") with
100+
{
101+
UseSnippets = true,
102+
};
103+
104+
// Act
105+
var completions = DirectiveAttributeCompletionItemProvider.GetAttributeCompletions("input", context, _defaultTagHelperContext);
106+
107+
// Assert
108+
AssertContains(completions, "format=\"$0\"", "format");
109+
}
110+
111+
[Fact]
112+
public void GetCompletionItems_OnDirectiveAttributeName_bind_ReturnsSameParameterCompletions()
113+
{
114+
// Arrange
115+
var contextAttributeName = CreateRazorCompletionContext("<input @$$ />");
116+
var contextParameterName = CreateRazorCompletionContext("<input @bind-value:$$ />");
117+
118+
// Act
119+
var completionsAttributeName = _provider.GetCompletionItems(contextAttributeName);
120+
var completionsParameterName = _provider.GetCompletionItems(contextParameterName);
121+
122+
// Assert
123+
var parameterNamesFromAttributeCompletions = completionsAttributeName
124+
.Where(c => c.DisplayText.StartsWith("@bind-value:"))
125+
.SelectAsArray(c => c.DisplayText["@bind-Value:".Length..]);
126+
var parameterNamesFromParameterCompletions = completionsParameterName
127+
.SelectAsArray(c => c.DisplayText);
128+
129+
AssertEx.SequenceEqual(parameterNamesFromAttributeCompletions, parameterNamesFromParameterCompletions);
130+
}
131+
95132
[Fact]
96133
public void GetAttributeParameterCompletions_BaseDirectiveAttributeAndParameterVariationsExist_ExcludesCompletion()
97134
{

0 commit comments

Comments
 (0)