Skip to content

Commit 5466886

Browse files
committed
Add xUnit analyzers and take fixer suggestions (2 of 5): System.Web.Helpers.Test to System.Web.Http.SignalR.Test
- part of #65 Few manual changes: - use `Assert.IsAssignableFrom<T>(...)`, `Assert.IsType<T>(...)` and `Assert.Single(...)` return values - suppress xUnit1013, Public method should be marked as test - mark a few methods as `private` for the same reason - work around xUnit1026, `[Theory]` method doesn't use all parameters - add `GC.KeepAlive(...)`
1 parent 64806c4 commit 5466886

File tree

51 files changed

+316
-291
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+316
-291
lines changed

test/System.Web.Helpers.Test/ChartTest.cs

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public void BuildChartAddsDefaultArea()
2626
var chart = new Chart(GetContext(), GetVirtualPathProvider(), 100, 100);
2727
AssertBuiltChartAction(chart, c =>
2828
{
29-
Assert.Equal(1, c.ChartAreas.Count);
30-
Assert.Equal("Default", c.ChartAreas[0].Name);
29+
ChartArea chartArea = Assert.Single(c.ChartAreas);
30+
Assert.Equal("Default", chartArea.Name);
3131
});
3232
}
3333

@@ -38,10 +38,10 @@ public void XAxisOverrides()
3838
.SetXAxis("AxisX", 1, 100);
3939
AssertBuiltChartAction(chart, c =>
4040
{
41-
Assert.Equal(1, c.ChartAreas.Count);
42-
Assert.Equal("AxisX", c.ChartAreas[0].AxisX.Title);
43-
Assert.Equal(1, c.ChartAreas[0].AxisX.Minimum);
44-
Assert.Equal(100, c.ChartAreas[0].AxisX.Maximum);
41+
ChartArea chartArea = Assert.Single(c.ChartAreas);
42+
Assert.Equal("AxisX", chartArea.AxisX.Title);
43+
Assert.Equal(1, chartArea.AxisX.Minimum);
44+
Assert.Equal(100, chartArea.AxisX.Maximum);
4545
});
4646
}
4747

@@ -52,10 +52,10 @@ public void YAxisOverrides()
5252
.SetYAxis("AxisY", 1, 100);
5353
AssertBuiltChartAction(chart, c =>
5454
{
55-
Assert.Equal(1, c.ChartAreas.Count);
56-
Assert.Equal("AxisY", c.ChartAreas[0].AxisY.Title);
57-
Assert.Equal(1, c.ChartAreas[0].AxisY.Minimum);
58-
Assert.Equal(100, c.ChartAreas[0].AxisY.Maximum);
55+
ChartArea chartArea = Assert.Single(c.ChartAreas);
56+
Assert.Equal("AxisY", chartArea.AxisY.Title);
57+
Assert.Equal(1, chartArea.AxisY.Minimum);
58+
Assert.Equal(100, chartArea.AxisY.Maximum);
5959
});
6060
}
6161

@@ -71,7 +71,7 @@ public void ConstructorLoadsTemplate()
7171
public void ConstructorLoadsTheme()
7272
{
7373
//Vanilla theme
74-
/*
74+
/*
7575
* <Chart Palette="SemiTransparent" BorderColor="#000" BorderWidth="2" BorderlineDashStyle="Solid">
7676
<ChartAreas>
7777
<ChartArea _Template_="All" Name="Default">
@@ -90,19 +90,19 @@ public void ConstructorLoadsTheme()
9090
var chart = new Chart(GetContext(), GetVirtualPathProvider(), 100, 100, theme: ChartTheme.Vanilla);
9191
AssertBuiltChartAction(chart, c =>
9292
{
93-
Assert.Equal(c.Palette, ChartColorPalette.SemiTransparent);
93+
Assert.Equal(ChartColorPalette.SemiTransparent, c.Palette);
9494
Assert.Equal(c.BorderColor, Color.FromArgb(0, Color.Black));
95-
Assert.Equal(1, c.ChartAreas.Count);
96-
Assert.False(c.ChartAreas[0].AxisX.MajorGrid.Enabled);
97-
Assert.False(c.ChartAreas[0].AxisY.MinorGrid.Enabled);
95+
ChartArea chartArea = Assert.Single(c.ChartAreas);
96+
Assert.False(chartArea.AxisX.MajorGrid.Enabled);
97+
Assert.False(chartArea.AxisY.MinorGrid.Enabled);
9898
});
9999
}
100100

101101
[Fact]
102102
public void ConstructorLoadsThemeAndTemplate()
103103
{
104104
//Vanilla theme
105-
/*
105+
/*
106106
* <Chart Palette="SemiTransparent" BorderColor="#000" BorderWidth="2" BorderlineDashStyle="Solid">
107107
<ChartAreas>
108108
<ChartArea _Template_="All" Name="Default">
@@ -122,14 +122,14 @@ public void ConstructorLoadsThemeAndTemplate()
122122
var chart = new Chart(GetContext(), GetVirtualPathProvider(), 100, 100, theme: ChartTheme.Vanilla, themePath: template);
123123
AssertBuiltChartAction(chart, c =>
124124
{
125-
Assert.Equal(c.Palette, ChartColorPalette.SemiTransparent);
125+
Assert.Equal(ChartColorPalette.SemiTransparent, c.Palette);
126126
Assert.Equal(c.BorderColor, Color.FromArgb(0, Color.Black));
127-
Assert.Equal(c.BorderlineDashStyle, ChartDashStyle.DashDot);
128-
Assert.Equal(1, c.ChartAreas.Count);
129-
Assert.Equal(c.Legends.Count, 1);
130-
Assert.Equal(c.Legends[0].BackColor, Color.Red);
131-
Assert.False(c.ChartAreas[0].AxisX.MajorGrid.Enabled);
132-
Assert.False(c.ChartAreas[0].AxisY.MinorGrid.Enabled);
127+
Assert.Equal(ChartDashStyle.DashDot, c.BorderlineDashStyle);
128+
Legend legend = Assert.Single(c.Legends);
129+
Assert.Equal(legend.BackColor, Color.Red);
130+
ChartArea chartArea = Assert.Single(c.ChartAreas);
131+
Assert.False(chartArea.AxisX.MajorGrid.Enabled);
132+
Assert.False(chartArea.AxisY.MinorGrid.Enabled);
133133
});
134134
}
135135

@@ -155,14 +155,14 @@ public void ConstructorLoadsThemeAndTemplate_VPPRegistrationChanging()
155155
// Assert
156156
AssertBuiltChartAction(chart, c =>
157157
{
158-
Assert.Equal(c.Palette, ChartColorPalette.SemiTransparent);
158+
Assert.Equal(ChartColorPalette.SemiTransparent, c.Palette);
159159
Assert.Equal(c.BorderColor, Color.FromArgb(0, Color.Black));
160-
Assert.Equal(c.BorderlineDashStyle, ChartDashStyle.DashDot);
161-
Assert.Equal(1, c.ChartAreas.Count);
162-
Assert.Equal(c.Legends.Count, 1);
163-
Assert.Equal(c.Legends[0].BackColor, Color.Red);
164-
Assert.False(c.ChartAreas[0].AxisX.MajorGrid.Enabled);
165-
Assert.False(c.ChartAreas[0].AxisY.MinorGrid.Enabled);
160+
Assert.Equal(ChartDashStyle.DashDot, c.BorderlineDashStyle);
161+
Legend legend = Assert.Single(c.Legends);
162+
Assert.Equal(legend.BackColor, Color.Red);
163+
ChartArea chartArea = Assert.Single(c.ChartAreas);
164+
Assert.False(chartArea.AxisX.MajorGrid.Enabled);
165+
Assert.False(chartArea.AxisY.MinorGrid.Enabled);
166166
});
167167

168168
Assert.Equal(1, provider1.FileExistsCalls);
@@ -221,7 +221,7 @@ public void DataBindCrossTable()
221221
{
222222
Assert.Equal(2, c.Series.Count);
223223
Assert.Equal(2, c.Series[0].Points.Count);
224-
Assert.Equal(1, c.Series[1].Points.Count);
224+
Assert.Single(c.Series[1].Points);
225225
});
226226
}
227227

@@ -281,8 +281,8 @@ public void DataBindTable()
281281
// todo - anything else to verify here?
282282
AssertBuiltChartAction(chart, c =>
283283
{
284-
Assert.Equal(1, c.Series.Count);
285-
Assert.Equal(3, c.Series[0].Points.Count);
284+
var series = Assert.Single(c.Series);
285+
Assert.Equal(3, series.Points.Count);
286286
});
287287
}
288288

@@ -300,8 +300,8 @@ public void DataBindTableWhenXFieldIsNull()
300300
// todo - anything else to verify here?
301301
AssertBuiltChartAction(chart, c =>
302302
{
303-
Assert.Equal(1, c.Series.Count);
304-
Assert.Equal(3, c.Series[0].Points.Count);
303+
var series = Assert.Single(c.Series);
304+
Assert.Equal(3, series.Points.Count);
305305
});
306306
}
307307

@@ -353,10 +353,10 @@ public void LegendDefaults()
353353
var chart = new Chart(GetContext(), GetVirtualPathProvider(), 100, 100).AddLegend();
354354
AssertBuiltChartAction(chart, c =>
355355
{
356-
Assert.Equal(1, c.Legends.Count);
356+
Legend legend = Assert.Single(c.Legends);
357357
// NOTE: Chart.Legends.Add will create default name
358-
Assert.Equal("Legend1", c.Legends[0].Name);
359-
Assert.Equal(1, c.Legends[0].BorderWidth);
358+
Assert.Equal("Legend1", legend.Name);
359+
Assert.Equal(1, legend.BorderWidth);
360360
});
361361
}
362362

@@ -474,7 +474,7 @@ public void SaveXmlWritesToFile()
474474
chart.SaveXml(GetContext(), "SaveXmlWritesToFile.xml");
475475
Assert.True(File.Exists("SaveXmlWritesToFile.xml"));
476476
string result = File.ReadAllText("SaveXmlWritesToFile.xml");
477-
Assert.True(result.Contains("BorderWidth=\"2\""));
477+
Assert.Contains("BorderWidth=\"2\"", result);
478478
}
479479

480480
[Fact]
@@ -531,8 +531,8 @@ public void SeriesOverrides()
531531
.AddSeries(chartType: "Bar");
532532
AssertBuiltChartAction(chart, c =>
533533
{
534-
Assert.Equal(1, c.Series.Count);
535-
Assert.Equal(SeriesChartType.Bar, c.Series[0].ChartType);
534+
var series = Assert.Single(c.Series);
535+
Assert.Equal(SeriesChartType.Bar, series.ChartType);
536536
});
537537
}
538538

@@ -556,11 +556,11 @@ public void TitleDefaults()
556556
var chart = new Chart(GetContext(), GetVirtualPathProvider(), 100, 100).AddTitle();
557557
AssertBuiltChartAction(chart, c =>
558558
{
559-
Assert.Equal(1, c.Titles.Count);
559+
var title = Assert.Single(c.Titles);
560560
// NOTE: Chart.Titles.Add will create default name
561-
Assert.Equal("Title1", c.Titles[0].Name);
562-
Assert.Equal(String.Empty, c.Titles[0].Text);
563-
Assert.Equal(1, c.Titles[0].BorderWidth);
561+
Assert.Equal("Title1", title.Name);
562+
Assert.Equal(String.Empty, title.Text);
563+
Assert.Equal(1, title.BorderWidth);
564564
});
565565
}
566566

test/System.Web.Helpers.Test/DynamicHelperTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void TryGetMemberValueReturnsValueIfBinderIsNotCSharp()
2121
bool result = DynamicHelper.TryGetMemberValue(dynamic, mockMemberBinder, out value);
2222

2323
// Assert
24-
Assert.Equal(value, "Bar");
24+
Assert.Equal("Bar", value);
2525
}
2626

2727
private class MockMemberBinder : GetMemberBinder

0 commit comments

Comments
 (0)