Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 1509020

Browse files
Enabling more tests
1 parent a1fdeb2 commit 1509020

File tree

4 files changed

+221
-200
lines changed

4 files changed

+221
-200
lines changed

src/GitHub.UI/Controls/AutoCompleteBox/AutoCompleteTextInputExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ public static string GetExpandedText(this IAutoCompleteTextInput textInput, stri
2424
int offset = completionOffset;
2525

2626
var currentText = textInput.Text ?? ""; // Playing it safe
27-
Debug.Assert(offset <= currentText.Length, "The offset can't be larger than the current text length");
28-
Debug.Assert(afterIndex <= currentText.Length, "The afterIndex can't be larger than the current text length");
27+
28+
if(offset <= currentText.Length) throw new InvalidOperationException("The offset can't be larger than the current text length");
29+
if(afterIndex <= currentText.Length) throw new InvalidOperationException("The afterIndex can't be larger than the current text length");
30+
2931
var before = currentText.Substring(0, offset);
3032
var after = currentText.Substring(afterIndex);
3133
string prefix = before + value + " ";
Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
using GitHub.UI;
2-
using GitHub.UI.Controls.AutoCompleteBox;
3-
using Moq;
4-
using Xunit;
1+
using GitHub.UI.Controls.AutoCompleteBox;
2+
using NSubstitute;
3+
using NUnit.Framework;
54

6-
class AutoCompleteTextInputExtensionsTests
5+
namespace GitHub.UI.UnitTests.Controls
76
{
8-
public class TheGetExpandedTextMethod
7+
class AutoCompleteTextInputExtensionsTests
98
{
10-
[Theory]
11-
[InlineData(":", 1, 0, ":apple: ")]
12-
[InlineData(":a", 2, 0, ":apple: ")]
13-
[InlineData(":ap", 3, 0, ":apple: ")]
14-
[InlineData(":a", 1, 0, ":apple: a")]
15-
[InlineData("Test :", 6, 5, "Test :apple: ")]
16-
[InlineData("Test :ap", 8, 5, "Test :apple: ")]
17-
[InlineData("Test :apother stuff", 8, 5, "Test :apple: other stuff")]
18-
public void ReturnsExpandedText(string text, int caretIndex, int completionOffset, string expected)
9+
public class TheGetExpandedTextMethod
1910
{
20-
var textInput = Mock.Of<IAutoCompleteTextInput>(t => t.CaretIndex == caretIndex && t.Text == text);
21-
var expandedText = textInput.GetExpandedText(":apple:", completionOffset);
22-
Assert.Equal(expected, expandedText);
11+
[TestCase(":", 1, 0, ":apple: ")]
12+
[TestCase(":a", 2, 0, ":apple: ")]
13+
[TestCase(":ap", 3, 0, ":apple: ")]
14+
[TestCase(":a", 1, 0, ":apple: a")]
15+
[TestCase("Test :", 6, 5, "Test :apple: ")]
16+
[TestCase("Test :ap", 8, 5, "Test :apple: ")]
17+
[TestCase("Test :apother stuff", 8, 5, "Test :apple: other stuff")]
18+
public void ReturnsExpandedText(string text, int caretIndex, int completionOffset, string expected)
19+
{
20+
var textInput = Substitute.For<IAutoCompleteTextInput>();
21+
textInput.CaretIndex.Returns(caretIndex);
22+
textInput.Text.Returns(text);
23+
24+
var expandedText = textInput.GetExpandedText(":apple:", completionOffset);
25+
Assert.AreEqual(expected, expandedText);
26+
}
2327
}
2428
}
2529
}

test/GitHub.UI.UnitTests/GitHub.UI.UnitTests.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
<TargetFramework>net46</TargetFramework>
44
</PropertyGroup>
55
<ItemGroup>
6-
<Compile Remove="Controls\AutoCompleteTextInputExtensionsTests.cs" />
7-
<Compile Remove="Helpers\AutoCompleteAdvisorTests.cs" />
86
<Compile Remove="Helpers\AutoCompleteSourceTests.cs" />
97
<Compile Remove="Helpers\IssuesAutoCompleteSourceTests.cs" />
108
<Compile Remove="Helpers\MentionsAutoCompleteSourceTests.cs" />
@@ -31,11 +29,6 @@
3129
</ItemGroup>
3230

3331
<ItemGroup>
34-
<None Include="Controls\AutoCompleteTextInputExtensionsTests.cs" />
35-
</ItemGroup>
36-
37-
<ItemGroup>
38-
<None Include="Helpers\AutoCompleteAdvisorTests.cs" />
3932
<None Include="Helpers\AutoCompleteSourceTests.cs" />
4033
<None Include="Helpers\IssuesAutoCompleteSourceTests.cs" />
4134
<None Include="Helpers\MentionsAutoCompleteSourceTests.cs" />

0 commit comments

Comments
 (0)