Skip to content
This repository was archived by the owner on Apr 6, 2024. It is now read-only.

Commit b6f40b4

Browse files
authored
(GH-277) Add EndLine to templates (#326)
* (GH-277) Add EndLine to HtmlDiagnostic template * (GH-277) Add EndLine to HtmlDataTable template * (GH-277) Add EndLine to HtmlDxDataGrid template
1 parent 742781d commit b6f40b4

13 files changed

+376
-22
lines changed

docs/templates/htmldatatable.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Template for a HTML report containing a rich data table view with sorting and se
1010
# Features
1111

1212
* Separate table for issues of each issue provider.
13-
* Table with `Severity`, `Project`, `Path`, `File`, `Line`, `Rule`, `Message`.
13+
* Table with `Severity`, `Project`, `Path`, `File`, `Location`, `Rule`, `Message`.
1414
* Each column sortable by user.
1515
* Paged table with possibility for user to change number of entries per page.
1616
* Client-side full text search.

docs/templates/htmldxdatagrid.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Template for a HTML report containing a rich data grid with sorting, filtering,
99

1010
# Features
1111

12-
* Table with `Provider`, `Severity`, `Project`, `Path`, `File`, `Line`, `Rule`, `Message` by default.
12+
* Table with `Provider`, `Severity`, `Project`, `Path`, `File`, `Location`, `Rule`, `Message` by default.
1313
* Support for grouping by multiple columns by user.
1414
* Total number of issues by each group level.
1515
* Each column sortable by user.

src/Cake.Issues.Reporting.Generic.Tests/ExpandoObjectExtensionsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void Should_Give_Correct_Result()
4141
var result = expandoObject.SerializeToJsonString();
4242

4343
// Then
44-
result.ShouldBe("{\"ProviderType\":\"providerType\",\"ProviderName\":\"providerName\",\"Run\":null,\"Priority\":null,\"PriorityName\":null,\"ProjectPath\":null,\"ProjectName\":null,\"FilePath\":null,\"FileDirectory\":null,\"FileName\":null,\"FileLink\":null,\"Line\":null,\"Rule\":null,\"RuleUrl\":null,\"MessageText\":\"message\"}");
44+
result.ShouldBe("{\"ProviderType\":\"providerType\",\"ProviderName\":\"providerName\",\"Run\":null,\"Priority\":null,\"PriorityName\":null,\"ProjectPath\":null,\"ProjectName\":null,\"FilePath\":null,\"FileDirectory\":null,\"FileName\":null,\"FileLink\":null,\"Line\":null,\"EndLine\":null,\"Location\":\"\",\"Rule\":null,\"RuleUrl\":null,\"MessageText\":\"message\"}");
4545
}
4646
}
4747

@@ -81,7 +81,7 @@ public void Should_Give_Correct_Result()
8181
var result = expandoObjects.SerializeToJsonString();
8282

8383
// Then
84-
result.ShouldBe("[{\"ProviderType\":\"providerType1\",\"ProviderName\":\"providerName1\",\"Run\":null,\"Priority\":null,\"PriorityName\":null,\"ProjectPath\":null,\"ProjectName\":null,\"FilePath\":null,\"FileDirectory\":null,\"FileName\":null,\"FileLink\":null,\"Line\":null,\"Rule\":null,\"RuleUrl\":null,\"MessageText\":\"message1\"},{\"ProviderType\":\"providerType1\",\"ProviderName\":\"providerName1\",\"Run\":null,\"Priority\":null,\"PriorityName\":null,\"ProjectPath\":null,\"ProjectName\":null,\"FilePath\":null,\"FileDirectory\":null,\"FileName\":null,\"FileLink\":null,\"Line\":null,\"Rule\":null,\"RuleUrl\":null,\"MessageText\":\"message1\"}]");
84+
result.ShouldBe("[{\"ProviderType\":\"providerType1\",\"ProviderName\":\"providerName1\",\"Run\":null,\"Priority\":null,\"PriorityName\":null,\"ProjectPath\":null,\"ProjectName\":null,\"FilePath\":null,\"FileDirectory\":null,\"FileName\":null,\"FileLink\":null,\"Line\":null,\"EndLine\":null,\"Location\":\"\",\"Rule\":null,\"RuleUrl\":null,\"MessageText\":\"message1\"},{\"ProviderType\":\"providerType1\",\"ProviderName\":\"providerName1\",\"Run\":null,\"Priority\":null,\"PriorityName\":null,\"ProjectPath\":null,\"ProjectName\":null,\"FilePath\":null,\"FileDirectory\":null,\"FileName\":null,\"FileLink\":null,\"Line\":null,\"EndLine\":null,\"Location\":\"\",\"Rule\":null,\"RuleUrl\":null,\"MessageText\":\"message1\"}]");
8585
}
8686
}
8787
}

src/Cake.Issues.Reporting.Generic.Tests/HtmlDxDataGridTemplateTests.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,74 @@ public void Should_Not_Fail_On_Report_Creation(ColumnSortOrder value)
549549
}
550550
}
551551

552+
public sealed class TheEndLineVisibleOption
553+
{
554+
[Theory]
555+
[InlineData(true)]
556+
[InlineData(false)]
557+
public void Should_Not_Fail_On_Report_Creation(bool value)
558+
{
559+
// Given
560+
var fixture = new GenericIssueReportFixture(GenericIssueReportTemplate.HtmlDxDataGrid);
561+
562+
// When / Then
563+
fixture.TestReportCreation(
564+
settings =>
565+
settings.WithOption(HtmlDxDataGridOption.EndLineVisible, value));
566+
}
567+
}
568+
569+
public sealed class TheEndLineSortOrderOption
570+
{
571+
[Theory]
572+
[InlineData(ColumnSortOrder.Ascending)]
573+
[InlineData(ColumnSortOrder.Descending)]
574+
public void Should_Not_Fail_On_Report_Creation(ColumnSortOrder value)
575+
{
576+
// Given
577+
var fixture = new GenericIssueReportFixture(GenericIssueReportTemplate.HtmlDxDataGrid);
578+
579+
// When / Then
580+
fixture.TestReportCreation(
581+
settings =>
582+
settings.WithOption(HtmlDxDataGridOption.EndLineSortOrder, value));
583+
}
584+
}
585+
586+
public sealed class TheLocationVisibleOption
587+
{
588+
[Theory]
589+
[InlineData(true)]
590+
[InlineData(false)]
591+
public void Should_Not_Fail_On_Report_Creation(bool value)
592+
{
593+
// Given
594+
var fixture = new GenericIssueReportFixture(GenericIssueReportTemplate.HtmlDxDataGrid);
595+
596+
// When / Then
597+
fixture.TestReportCreation(
598+
settings =>
599+
settings.WithOption(HtmlDxDataGridOption.LocationVisible, value));
600+
}
601+
}
602+
603+
public sealed class TheLocationSortOrderOption
604+
{
605+
[Theory]
606+
[InlineData(ColumnSortOrder.Ascending)]
607+
[InlineData(ColumnSortOrder.Descending)]
608+
public void Should_Not_Fail_On_Report_Creation(ColumnSortOrder value)
609+
{
610+
// Given
611+
var fixture = new GenericIssueReportFixture(GenericIssueReportTemplate.HtmlDxDataGrid);
612+
613+
// When / Then
614+
fixture.TestReportCreation(
615+
settings =>
616+
settings.WithOption(HtmlDxDataGridOption.LocationSortOrder, value));
617+
}
618+
}
619+
552620
public sealed class TheLRuleVisibleOption
553621
{
554622
[Theory]

src/Cake.Issues.Reporting.Generic.Tests/IIssueExtensionsTests.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,80 @@ public void Should_Not_Set_Line_If_Flag_Is_Not_Set()
409409
result.IsRuntimeBinderException("'System.Dynamic.ExpandoObject' does not contain a definition for 'Line'");
410410
}
411411

412+
[Fact]
413+
public void Should_Set_EndLine_If_Flag_Is_Set()
414+
{
415+
// Given
416+
var filePath = @"src\Cake.Issues.Reporting.Generic.Tests\Foo.cs";
417+
var line = 23;
418+
var endLine = 42;
419+
var issue =
420+
IssueBuilder
421+
.NewIssue("Message Foo", "ProviderType Foo", "ProviderName Foo")
422+
.InFile(filePath, line, endLine, null, null)
423+
.Create();
424+
425+
// When
426+
dynamic result = issue.GetExpandoObject(addEndLine: true);
427+
428+
// Then
429+
Assert.Equal(result.EndLine, endLine);
430+
}
431+
432+
[Fact]
433+
public void Should_Not_Set_EndLine_If_Flag_Is_Not_Set()
434+
{
435+
// Given
436+
var issue =
437+
IssueBuilder
438+
.NewIssue("Message Foo", "ProviderType Foo", "ProviderName Foo")
439+
.Create();
440+
441+
// When
442+
dynamic expando = issue.GetExpandoObject(addEndLine: false);
443+
var result = Record.Exception(() => expando.EndLine);
444+
445+
// Then
446+
result.IsRuntimeBinderException("'System.Dynamic.ExpandoObject' does not contain a definition for 'EndLine'");
447+
}
448+
449+
[Fact]
450+
public void Should_Set_Location_If_Flag_Is_Set()
451+
{
452+
// Given
453+
var filePath = @"src\Cake.Issues.Reporting.Generic.Tests\Foo.cs";
454+
var line = 23;
455+
var endLine = 42;
456+
var issue =
457+
IssueBuilder
458+
.NewIssue("Message Foo", "ProviderType Foo", "ProviderName Foo")
459+
.InFile(filePath, line, endLine, null, null)
460+
.Create();
461+
462+
// When
463+
dynamic result = issue.GetExpandoObject(addLocation: true);
464+
465+
// Then
466+
Assert.Equal(result.Location, $"{line}-{endLine}");
467+
}
468+
469+
[Fact]
470+
public void Should_Not_Set_Location_If_Flag_Is_Not_Set()
471+
{
472+
// Given
473+
var issue =
474+
IssueBuilder
475+
.NewIssue("Message Foo", "ProviderType Foo", "ProviderName Foo")
476+
.Create();
477+
478+
// When
479+
dynamic expando = issue.GetExpandoObject(addLocation: false);
480+
var result = Record.Exception(() => expando.Location);
481+
482+
// Then
483+
result.IsRuntimeBinderException("'System.Dynamic.ExpandoObject' does not contain a definition for 'Location'");
484+
}
485+
412486
[Fact]
413487
public void Should_Set_Rule_If_Flag_Is_Set()
414488
{

src/Cake.Issues.Reporting.Generic.Tests/IdeIntegrationSettingsTests.cs

Lines changed: 89 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ public void Should_Throw_If_FilePathExpression_Is_Null()
1818
var ideIntegrationSettings = new IdeIntegrationSettings();
1919
string filePathExpression = null;
2020
var lineExpression = "line";
21+
var endLineExpression = "endLine";
2122

2223
// When
2324
var result = Record.Exception(() =>
24-
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression));
25+
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression, endLineExpression));
2526

2627
// Then
2728
result.IsArgumentNullException("filePathExpression");
@@ -34,10 +35,11 @@ public void Should_Throw_If_FilePathExpression_Is_Empty()
3435
var ideIntegrationSettings = new IdeIntegrationSettings();
3536
var filePathExpression = string.Empty;
3637
var lineExpression = "line";
38+
var endLineExpression = "endLine";
3739

3840
// When
3941
var result = Record.Exception(() =>
40-
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression));
42+
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression, endLineExpression));
4143

4244
// Then
4345
result.IsArgumentOutOfRangeException("filePathExpression");
@@ -50,10 +52,11 @@ public void Should_Throw_If_FilePathExpression_Is_WhiteSpace()
5052
var ideIntegrationSettings = new IdeIntegrationSettings();
5153
var filePathExpression = " ";
5254
var lineExpression = "line";
55+
var endLineExpression = "endLine";
5356

5457
// When
5558
var result = Record.Exception(() =>
56-
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression));
59+
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression, endLineExpression));
5760

5861
// Then
5962
result.IsArgumentOutOfRangeException("filePathExpression");
@@ -66,10 +69,11 @@ public void Should_Throw_If_LineExpression_Is_Null()
6669
var ideIntegrationSettings = new IdeIntegrationSettings();
6770
var filePathExpression = "file";
6871
string lineExpression = null;
72+
var endLineExpression = "endLine";
6973

7074
// When
7175
var result = Record.Exception(() =>
72-
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression));
76+
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression, endLineExpression));
7377

7478
// Then
7579
result.IsArgumentNullException("lineExpression");
@@ -82,10 +86,11 @@ public void Should_Throw_If_LineExpression_Is_Empty()
8286
var ideIntegrationSettings = new IdeIntegrationSettings();
8387
var filePathExpression = "file";
8488
var lineExpression = string.Empty;
89+
var endLineExpression = "endLine";
8590

8691
// When
8792
var result = Record.Exception(() =>
88-
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression));
93+
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression, endLineExpression));
8994

9095
// Then
9196
result.IsArgumentOutOfRangeException("lineExpression");
@@ -98,25 +103,78 @@ public void Should_Throw_If_LineExpression_Is_WhiteSpace()
98103
var ideIntegrationSettings = new IdeIntegrationSettings();
99104
var filePathExpression = "file";
100105
var lineExpression = " ";
106+
var endLineExpression = "endLine";
101107

102108
// When
103109
var result = Record.Exception(() =>
104-
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression));
110+
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression, endLineExpression));
105111

106112
// Then
107113
result.IsArgumentOutOfRangeException("lineExpression");
108114
}
109115

116+
[Fact]
117+
public void Should_Throw_If_EndLineExpression_Is_Null()
118+
{
119+
// Given
120+
var ideIntegrationSettings = new IdeIntegrationSettings();
121+
var filePathExpression = "file";
122+
var lineExpression = "line";
123+
string endLineExpression = null;
124+
125+
// When
126+
var result = Record.Exception(() =>
127+
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression, endLineExpression));
128+
129+
// Then
130+
result.IsArgumentNullException("endLineExpression");
131+
}
132+
133+
[Fact]
134+
public void Should_Throw_If_EndLineExpression_Is_Empty()
135+
{
136+
// Given
137+
var ideIntegrationSettings = new IdeIntegrationSettings();
138+
var filePathExpression = "file";
139+
var lineExpression = "line";
140+
var endLineExpression = string.Empty;
141+
142+
// When
143+
var result = Record.Exception(() =>
144+
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression, endLineExpression));
145+
146+
// Then
147+
result.IsArgumentOutOfRangeException("endLineExpression");
148+
}
149+
150+
[Fact]
151+
public void Should_Throw_If_EndLineExpression_Is_WhiteSpace()
152+
{
153+
// Given
154+
var ideIntegrationSettings = new IdeIntegrationSettings();
155+
var filePathExpression = "file";
156+
var lineExpression = "line";
157+
var endLineExpression = " ";
158+
159+
// When
160+
var result = Record.Exception(() =>
161+
ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression, endLineExpression));
162+
163+
// Then
164+
result.IsArgumentOutOfRangeException("endLineExpression");
165+
}
166+
110167
[Fact]
111168
public void Should_Return_Null_If_OpenInIdeCall_Is_Not_Set()
112169
{
113170
// Given
114171
var ideIntegrationSettings = new IdeIntegrationSettings();
115172
var filePathExpression = "file";
116173
var lineExpression = "line";
174+
var endLineExpression = "endLine";
117175

118176
// When
119-
var result = ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression);
177+
var result = ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression, endLineExpression);
120178

121179
// Then
122180
result.ShouldBeNull();
@@ -133,9 +191,10 @@ public void Should_Replace_FilePath_Token()
133191
};
134192
var filePathExpression = "file";
135193
var lineExpression = "line";
194+
var endLineExpression = "endLine";
136195

137196
// When
138-
var result = ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression);
197+
var result = ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression, endLineExpression);
139198

140199
// Then
141200
result.ShouldBe("FoofileBar");
@@ -152,13 +211,34 @@ public void Should_Replace_Line_Token()
152211
};
153212
var filePathExpression = "file";
154213
var lineExpression = "line";
214+
var endLineExpression = "endLine";
155215

156216
// When
157-
var result = ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression);
217+
var result = ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression, endLineExpression);
158218

159219
// Then
160220
result.ShouldBe("FoolineBar");
161221
}
222+
223+
[Fact]
224+
public void Should_Replace_EndLine_Token()
225+
{
226+
// Given
227+
var ideIntegrationSettings =
228+
new IdeIntegrationSettings
229+
{
230+
OpenInIdeCall = "Foo{EndLine}Bar",
231+
};
232+
var filePathExpression = "file";
233+
var lineExpression = "line";
234+
var endLineExpression = "endLine";
235+
236+
// When
237+
var result = ideIntegrationSettings.GetOpenInIdeCall(filePathExpression, lineExpression, endLineExpression);
238+
239+
// Then
240+
result.ShouldBe("FooendLineBar");
241+
}
162242
}
163243
}
164244
}

0 commit comments

Comments
 (0)