Skip to content

Commit 75c5cbb

Browse files
authored
Fix failing actions test (#993)
1 parent e911dac commit 75c5cbb

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/dotnet-grpc/Commands/ListCommand.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,24 @@ public void List()
104104
Region region;
105105
try
106106
{
107-
// System.Console.WindowWidth can throw an IOException when runnning without a console attached
108-
region = new Region(0, 0, System.Console.WindowWidth, System.Console.WindowHeight);
107+
// Some environments incorrectly report zero width when there is no console
108+
var width = System.Console.WindowWidth;
109+
if (width == 0)
110+
{
111+
width = int.MaxValue;
112+
}
113+
114+
var height = System.Console.WindowHeight;
115+
if (height == 0)
116+
{
117+
height = int.MaxValue;
118+
}
119+
120+
region = new Region(0, 0, width, height);
109121
}
110122
catch (IOException)
111123
{
124+
// System.Console.WindowWidth can throw an IOException when runnning without a console attached
112125
region = new Region(0, 0, int.MaxValue, int.MaxValue);
113126
}
114127
screen.Child?.Render(consoleRenderer, region);

test/dotnet-grpc.Tests/ListCommandTests.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,21 @@ public void List_ListsReferences()
4242
// Act
4343
Directory.SetCurrentDirectory(tempDir);
4444
var command = new ListCommand(testConsole, null);
45+
46+
Assert.IsNotNull(command.Project);
47+
Assert.AreEqual("test.csproj", Path.GetFileName(command.Project.FullPath));
48+
4549
command.List();
4650

4751
// Assert
4852
var output = testConsole.Out.ToString()!;
4953
var lines = output.Split(Environment.NewLine);
5054

5155
// First line is the heading and should conatin Protobuf Reference, Service Type, Source URL, Access
52-
Assert.True(lines[0].Contains("Protobuf Reference"));
53-
Assert.True(lines[0].Contains("Service Type"));
54-
Assert.True(lines[0].Contains("Source URL"));
55-
Assert.True(lines[0].Contains("Access"));
56+
AssertContains(lines[0], "Protobuf Reference");
57+
AssertContains(lines[0], "Service Type");
58+
AssertContains(lines[0], "Source URL");
59+
AssertContains(lines[0], "Access");
5660

5761
// Second line is the reference to
5862
//<Protobuf Include="Proto/a.proto">
@@ -71,5 +75,10 @@ public void List_ListsReferences()
7175
Directory.Delete(tempDir, true);
7276
}
7377
}
78+
79+
private void AssertContains(string source, string s)
80+
{
81+
Assert.True(source.Contains(s), $"Source '{source}' does not contain '{s}'.");
82+
}
7483
}
7584
}

0 commit comments

Comments
 (0)