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

Commit 83bd481

Browse files
authored
Merge pull request #66 from cake-contrib/feature/gh-44
(GH-44) HtmlDxDataGrid: Add possibility to define additional columns
2 parents 7589262 + c3042ca commit 83bd481

11 files changed

+909
-33
lines changed

src/Cake.Issues.Reporting.Generic.Tests/Cake.Issues.Reporting.Generic.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
<ItemGroup>
8686
<Compile Include="ColumnSortOrderExtensionsTests.cs" />
8787
<Compile Include="DevExtremeThemeExtensionsTests.cs" />
88+
<Compile Include="ExceptionAssertExtensions.cs" />
89+
<Compile Include="HtmlDxDataGridColumnDescriptionTests.cs" />
8890
<Compile Include="IIssueExtensionTests.cs" />
8991
<Compile Include="UriExtensionsTests.cs" />
9092
<Compile Include="FileLinkSettingsTests.cs" />
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Cake.Issues.Reporting.Generic.Tests
2+
{
3+
using System;
4+
using Microsoft.CSharp.RuntimeBinder;
5+
using Xunit;
6+
7+
/// <summary>
8+
/// Extensions for asserting exceptions.
9+
/// </summary>
10+
internal static class ExceptionAssertExtensions
11+
{
12+
/// <summary>
13+
/// Checks if an execption is of type <see cref="T:Microsoft.CSharp.RuntimeBinder.RuntimeBinderException" />.
14+
/// </summary>
15+
/// <param name="exception">Exception to check.</param>
16+
/// <param name="message">Expected exception message.</param>
17+
public static void IsRuntimeBinderException(this Exception exception, string message)
18+
{
19+
Assert.IsType<RuntimeBinderException>(exception);
20+
Assert.Equal(message, exception.Message);
21+
}
22+
}
23+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
namespace Cake.Issues.Reporting.Generic.Tests
2+
{
3+
using System;
4+
using Cake.Issues.Testing;
5+
using Shouldly;
6+
using Xunit;
7+
8+
public sealed class HtmlDxDataGridColumnDescriptionTests
9+
{
10+
public sealed class TheCtor
11+
{
12+
[Fact]
13+
public void Should_Throw_If_Id_Is_Null()
14+
{
15+
// Given
16+
string id = null;
17+
object valueRetriever(IIssue issue)
18+
{
19+
return true;
20+
}
21+
22+
// When
23+
var result = Record.Exception(() => new HtmlDxDataGridColumnDescription(id, valueRetriever));
24+
25+
// Then
26+
result.IsArgumentNullException("id");
27+
}
28+
29+
[Fact]
30+
public void Should_Throw_If_Id_Is_Empty()
31+
{
32+
// Given
33+
var id = string.Empty;
34+
object valueRetriever(IIssue issue)
35+
{
36+
return true;
37+
}
38+
39+
// When
40+
var result = Record.Exception(() => new HtmlDxDataGridColumnDescription(id, valueRetriever));
41+
42+
// Then
43+
result.IsArgumentOutOfRangeException("id");
44+
}
45+
46+
[Fact]
47+
public void Should_Throw_If_Id_Is_Whitespace()
48+
{
49+
// Given
50+
var id = " ";
51+
object valueRetriever(IIssue issue)
52+
{
53+
return true;
54+
}
55+
56+
// When
57+
var result = Record.Exception(() => new HtmlDxDataGridColumnDescription(id, valueRetriever));
58+
59+
// Then
60+
result.IsArgumentOutOfRangeException("id");
61+
}
62+
63+
[Fact]
64+
public void Should_Throw_If_ValueRetriever_Is_Null()
65+
{
66+
// Given
67+
var id = "foo";
68+
Func<IIssue, object> valueRetriever = null;
69+
70+
// When
71+
var result = Record.Exception(() => new HtmlDxDataGridColumnDescription(id, valueRetriever));
72+
73+
// Then
74+
result.IsArgumentNullException("valueRetriever");
75+
}
76+
77+
[Fact]
78+
public void Should_Assign_Id()
79+
{
80+
// Given
81+
var id = "foo";
82+
object valueRetriever(IIssue issue)
83+
{
84+
return true;
85+
}
86+
87+
// When
88+
var result = new HtmlDxDataGridColumnDescription(id, valueRetriever);
89+
90+
// Then
91+
result.Id.ShouldBe(id);
92+
}
93+
94+
[Fact]
95+
public void Should_Assign_ValueRetriever()
96+
{
97+
// Given
98+
var id = "foo";
99+
object valueRetriever(IIssue issue)
100+
{
101+
return true;
102+
}
103+
104+
// When
105+
var result = new HtmlDxDataGridColumnDescription(id, valueRetriever);
106+
107+
// Then
108+
result.ValueRetriever.ShouldBe(valueRetriever);
109+
}
110+
}
111+
}
112+
}

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,42 @@ public void Should_Not_Show_Header_If_False()
127127
headingElements.ShouldBeEmpty();
128128
}
129129
}
130+
131+
public sealed class TheAdditionalColumnsOption
132+
{
133+
[Fact]
134+
public void Should_Not_Fail_On_Report_Creation()
135+
{
136+
// Given
137+
var fixture = new GenericIssueReportFixture(GenericIssueReportTemplate.HtmlDxDataGrid);
138+
fixture.GenericIssueReportFormatSettings
139+
.WithOption(
140+
HtmlDxDataGridOption.AdditionalColumns,
141+
new List<HtmlDxDataGridColumnDescription>
142+
{
143+
new HtmlDxDataGridColumnDescription("MyCustomColumn", x => { return "Foo"; })
144+
{
145+
Caption = "Custom Value",
146+
}
147+
});
148+
149+
// When
150+
var result =
151+
fixture.CreateReport(
152+
new List<IIssue>
153+
{
154+
IssueBuilder
155+
.NewIssue("Message Foo", "ProviderType Foo", "ProviderName Foo")
156+
.InFile(@"src\Cake.Issues.Reporting.Generic.Tests\Foo.cs", 10)
157+
.OfRule("Rule Foo")
158+
.WithPriority(IssuePriority.Warning)
159+
.Create(),
160+
});
161+
162+
// Then
163+
// Currently only checks if genertions failed or not without checking actual output.
164+
result.ShouldNotBeNull();
165+
}
166+
}
130167
}
131168
}

0 commit comments

Comments
 (0)