Skip to content

Commit 1e46143

Browse files
feat: reformat code, add tests for next case
1 parent 803227c commit 1e46143

File tree

5 files changed

+430
-47
lines changed

5 files changed

+430
-47
lines changed

CodeQualityToGitlab/Transform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private static void Process(
4848
{
4949
var toTransform = match.Path;
5050
Log.Information("Processing: {File}", toTransform);
51-
var cqrs = processFunc(new FileInfo(toTransform), pathRoot);
51+
var cqrs = processFunc(new(toTransform), pathRoot);
5252
allIssues.AddRange(cqrs);
5353
}
5454
}

Test/Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
<Content Include="crash.sarif.json">
7373
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7474
</Content>
75+
<Content Include="codeanalysis.sarif4.json">
76+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
77+
</Content>
7578
<None Update="codeanalysis.sarif21.json">
7679
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7780
</None>

Test/TestSarif.cs

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ namespace Test;
88

99
public class TestSarif
1010
{
11+
private static readonly JsonSerializerOptions JsonSerializerOptions = new()
12+
{
13+
WriteIndented = true,
14+
PropertyNamingPolicy = new LowerCaseNamingPolicy(),
15+
Converters = { new JsonStringEnumConverter() }
16+
};
17+
1118
[Fact]
1219
public void TestSarifWorks()
1320
{
@@ -20,12 +27,7 @@ public void TestSarifWorks()
2027
$"C:{Path.DirectorySeparatorChar}dev" + Path.DirectorySeparatorChar
2128
);
2229

23-
var options = new JsonSerializerOptions
24-
{
25-
WriteIndented = true,
26-
PropertyNamingPolicy = new LowerCaseNamingPolicy(),
27-
Converters = { new JsonStringEnumConverter() }
28-
};
30+
var options = JsonSerializerOptions;
2931

3032
using var r = new StreamReader(target.FullName);
3133
var json = r.ReadToEnd();
@@ -52,12 +54,7 @@ public void TestSarifWorks2()
5254

5355
SarifConverter.ConvertToCodeQuality(source, target);
5456

55-
var options = new JsonSerializerOptions
56-
{
57-
WriteIndented = true,
58-
PropertyNamingPolicy = new LowerCaseNamingPolicy(),
59-
Converters = { new JsonStringEnumConverter() }
60-
};
57+
var options = JsonSerializerOptions;
6158

6259
using var r = new StreamReader(target.FullName);
6360
var json = r.ReadToEnd();
@@ -73,28 +70,6 @@ public void TestSarifWorks2()
7370
codeQuality.Location.Lines.Begin.Should().Be(26);
7471
}
7572

76-
[Fact]
77-
public void TestSarifWorks3()
78-
{
79-
var source = new FileInfo("codeanalysis.sarif3.json");
80-
var target = new FileInfo(Path.GetTempFileName());
81-
82-
SarifConverter.ConvertToCodeQuality(source, target);
83-
84-
var options = new JsonSerializerOptions
85-
{
86-
WriteIndented = true,
87-
PropertyNamingPolicy = new LowerCaseNamingPolicy(),
88-
Converters = { new JsonStringEnumConverter() }
89-
};
90-
91-
using var r = new StreamReader(target.FullName);
92-
var json = r.ReadToEnd();
93-
var result = JsonSerializer.Deserialize<List<CodeQuality>>(json, options);
94-
95-
result.Should().HaveCount(0);
96-
}
97-
9873
[Fact]
9974
public void TestCrashWorks()
10075
{
@@ -103,12 +78,7 @@ public void TestCrashWorks()
10378

10479
SarifConverter.ConvertToCodeQuality(source, target);
10580

106-
var options = new JsonSerializerOptions
107-
{
108-
WriteIndented = true,
109-
PropertyNamingPolicy = new LowerCaseNamingPolicy(),
110-
Converters = { new JsonStringEnumConverter() }
111-
};
81+
var options = JsonSerializerOptions;
11282

11383
using var r = new StreamReader(target.FullName);
11484
var json = r.ReadToEnd();
@@ -125,12 +95,7 @@ public void TestSarif21Works()
12595

12696
SarifConverter.ConvertToCodeQuality(source, target);
12797

128-
var options = new JsonSerializerOptions
129-
{
130-
WriteIndented = true,
131-
PropertyNamingPolicy = new LowerCaseNamingPolicy(),
132-
Converters = { new JsonStringEnumConverter() }
133-
};
98+
var options = JsonSerializerOptions;
13499

135100
using var r = new StreamReader(target.FullName);
136101
var json = r.ReadToEnd();

Test/TestTransform.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,25 @@ public void TestTransformAllWorks()
2727

2828
result.Should().HaveCount(8);
2929
}
30+
31+
[Fact]
32+
public void TestTransformCreatesExpectedPath()
33+
{
34+
var target = new FileInfo(Path.GetTempFileName());
35+
36+
Transform.TransformAll("codeanalysis.sarif4.json", "", target, null, true);
37+
38+
var options = new JsonSerializerOptions
39+
{
40+
WriteIndented = true,
41+
PropertyNamingPolicy = new LowerCaseNamingPolicy(),
42+
Converters = { new JsonStringEnumConverter() }
43+
};
44+
45+
using var r = new StreamReader(target.FullName);
46+
var json = r.ReadToEnd();
47+
var result = JsonSerializer.Deserialize<List<CodeQuality>>(json, options);
48+
49+
result.Should().HaveCount(8);
50+
}
3051
}

0 commit comments

Comments
 (0)