Skip to content

Commit 4f6e373

Browse files
author
Gérald Barré
committed
Add tests
1 parent ebd5183 commit 4f6e373

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

tests/Workleap.DotNet.CodingStandards.Tests/CodingStandardTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ public async Task BannedSymbolsAreReported()
1717
Assert.True(data.HasWarning("RS0030"));
1818
}
1919

20+
[Fact]
21+
public async Task BannedNewtonsoftJsonSymbolsAreReportedWhenPropertyIsSet()
22+
{
23+
using var project = new ProjectBuilder(fixture, testOutputHelper);
24+
project.AddCsprojFile(
25+
properties: new Dictionary<string, string> { { "BanNewtonsoftJsonSymbols", "true" } },
26+
packageReferences: new Dictionary<string, string> { { "Newtonsoft.Json", "13.0.1" } });
27+
project.AddFile("sample.cs", "_ = Newtonsoft.Json.JsonConvert.SerializeObject(new object());");
28+
var data = await project.BuildAndGetOutput();
29+
Assert.True(data.HasWarning("RS0030"));
30+
}
31+
32+
[Fact]
33+
public async Task BannedNewtonsoftJsonSymbolsAreNotReportedWhenPropertyIsNotSet()
34+
{
35+
using var project = new ProjectBuilder(fixture, testOutputHelper);
36+
project.AddCsprojFile(
37+
packageReferences: new Dictionary<string, string> { { "Newtonsoft.Json", "13.0.1" } });
38+
project.AddFile("sample.cs", "_ = Newtonsoft.Json.JsonConvert.SerializeObject(new object());");
39+
var data = await project.BuildAndGetOutput();
40+
Assert.False(data.HasWarning("RS0030"));
41+
}
42+
2043
[Fact]
2144
public async Task WarningsAsErrorOnGitHubActions()
2245
{

tests/Workleap.DotNet.CodingStandards.Tests/Helpers/ProjectBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void AddCsprojFile(Dictionary<string, string>? properties = null, Diction
5656
{
5757
foreach (var prop in properties)
5858
{
59-
propertyElement.Add(new XElement(prop.Key), prop.Value);
59+
propertyElement.Add(new XElement(prop.Key, prop.Value));
6060
}
6161
}
6262

0 commit comments

Comments
 (0)