Skip to content

Commit a5cc5d8

Browse files
YVbakkereNeRGy164
authored andcommitted
Properly handle null values in the test project
1 parent a3f31c6 commit a5cc5d8

File tree

2 files changed

+69
-69
lines changed

2 files changed

+69
-69
lines changed

tests/DendroDocs.Tool.Tests/AnalyzerSetup/AnalyzerSetupTests.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,87 +3,87 @@ namespace DendroDocs.Tool.Tests;
33
[TestClass]
44
public class AnalyzerSetupTests
55
{
6-
private static readonly string solutionPath = GetSolutionPath();
6+
private static readonly string SolutionPath = GetSolutionPath();
77

88
[TestMethod]
99
public void SolutionShouldLoadAllProjects()
1010
{
1111
// Arrange
12-
var solutionFile = Path.Combine(solutionPath, "SolutionWithoutTests.sln");
12+
var solutionFile = Path.Combine(SolutionPath, "SolutionWithoutTests.sln");
1313

1414
// Act
1515
using var analyzerSetup = AnalyzerSetup.BuildSolutionAnalyzer(solutionFile);
1616

1717
// Assert
1818
analyzerSetup.Projects.Should().HaveCount(3);
1919
analyzerSetup.Projects.Should().Satisfy(
20-
p => p.FilePath.EndsWith("Project.csproj"),
21-
p => p.FilePath.EndsWith("OtherProject.csproj"),
22-
p => p.FilePath.EndsWith("AnotherProject.csproj"));
20+
p => p.FilePath != null && p.FilePath.EndsWith("Project.csproj"),
21+
p => p.FilePath != null && p.FilePath.EndsWith("OtherProject.csproj"),
22+
p => p.FilePath != null && p.FilePath.EndsWith("AnotherProject.csproj"));
2323
}
2424

2525
[TestMethod]
2626
public void SolutionShouldFilterTestProjects()
2727
{
2828
// Arrange
29-
var solutionFile = Path.Combine(solutionPath, "SolutionWithTests.sln");
29+
var solutionFile = Path.Combine(SolutionPath, "SolutionWithTests.sln");
3030

3131
// Act
3232
using var analyzerSetup = AnalyzerSetup.BuildSolutionAnalyzer(solutionFile);
3333

3434
// Assert
3535
analyzerSetup.Projects.Should().HaveCount(3);
3636
analyzerSetup.Projects.Should().Satisfy(
37-
p => p.FilePath.EndsWith("Project.csproj"),
38-
p => p.FilePath.EndsWith("OtherProject.csproj"),
39-
p => p.FilePath.EndsWith("AnotherProject.csproj"));
37+
p => p.FilePath != null && p.FilePath.EndsWith("Project.csproj"),
38+
p => p.FilePath != null && p.FilePath.EndsWith("OtherProject.csproj"),
39+
p => p.FilePath != null && p.FilePath.EndsWith("AnotherProject.csproj"));
4040
}
4141

4242
[TestMethod]
4343
public void SolutionShouldFilterExcludedProject()
4444
{
4545
// Arrange
46-
var solutionFile = Path.Combine(solutionPath, "SolutionWithoutTests.sln");
47-
var excludeProjectFile = Path.Combine(solutionPath, "OtherProject", "OtherProject.csproj");
46+
var solutionFile = Path.Combine(SolutionPath, "SolutionWithoutTests.sln");
47+
var excludeProjectFile = Path.Combine(SolutionPath, "OtherProject", "OtherProject.csproj");
4848

4949
// Act
5050
using var analyzerSetup = AnalyzerSetup.BuildSolutionAnalyzer(solutionFile, [excludeProjectFile]);
5151

5252
// Assert
5353
analyzerSetup.Projects.Should().HaveCount(2);
5454
analyzerSetup.Projects.Should().Satisfy(
55-
p => p.FilePath.EndsWith("Project.csproj"),
56-
p => p.FilePath.EndsWith("AnotherProject.csproj"));
55+
p => p.FilePath != null && p.FilePath.EndsWith("Project.csproj"),
56+
p => p.FilePath != null && p.FilePath.EndsWith("AnotherProject.csproj"));
5757
}
5858

5959
[TestMethod]
6060
public void SolutionShouldFilterExcludedProjects()
6161
{
6262
// Arrange
63-
var solutionFile = Path.Combine(solutionPath, "SolutionWithoutTests.sln");
64-
var excludeProjectFile1 = Path.Combine(solutionPath, "OtherProject", "OtherProject.csproj");
65-
var excludeProjectFile2 = Path.Combine(solutionPath, "AnotherProject", "AnotherProject.csproj");
63+
var solutionFile = Path.Combine(SolutionPath, "SolutionWithoutTests.sln");
64+
var excludeProjectFile1 = Path.Combine(SolutionPath, "OtherProject", "OtherProject.csproj");
65+
var excludeProjectFile2 = Path.Combine(SolutionPath, "AnotherProject", "AnotherProject.csproj");
6666

6767
// Act
6868
using var analyzerSetup = AnalyzerSetup.BuildSolutionAnalyzer(solutionFile, [excludeProjectFile1, excludeProjectFile2]);
6969

7070
// Assert
7171
analyzerSetup.Projects.Should().HaveCount(1);
72-
analyzerSetup.Projects.Should().Satisfy(p => p.FilePath.EndsWith("Project.csproj"));
72+
analyzerSetup.Projects.Should().Satisfy(p => p.FilePath != null && p.FilePath.EndsWith("Project.csproj"));
7373
}
7474

7575
[TestMethod]
7676
public void SolutionShouldLoadProject()
7777
{
7878
// Arrange
79-
var projectFile = Path.Combine(solutionPath, "Project", "Project.csproj");
79+
var projectFile = Path.Combine(SolutionPath, "Project", "Project.csproj");
8080

8181
// Act
8282
using var analyzerSetup = AnalyzerSetup.BuildProjectAnalyzer(projectFile);
8383

8484
// Assert
8585
analyzerSetup.Projects.Should().HaveCount(1);
86-
analyzerSetup.Projects.Should().Satisfy(p => p.FilePath.EndsWith("Project.csproj"));
86+
analyzerSetup.Projects.Should().Satisfy(p => p.FilePath != null && p.FilePath.EndsWith("Project.csproj"));
8787
}
8888

8989
private static string GetSolutionPath()

tests/DendroDocs.Tool.Tests/DocumentationCommentsTests.cs

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class Test
2828
// Assert
2929
using (new AssertionScope())
3030
{
31-
types[0].DocumentationComments.Summary.Should().Be("This is a Test Class.");
32-
types[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
33-
types[0].DocumentationComments.Example.Should().Be("This is an example.");
31+
types[0].DocumentationComments?.Summary.Should().Be("This is a Test Class.");
32+
types[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
33+
types[0].DocumentationComments?.Example.Should().Be("This is an example.");
3434
}
3535
}
3636

@@ -65,10 +65,10 @@ class Test
6565
// Assert
6666
using (new AssertionScope())
6767
{
68-
types[0].Events[0].DocumentationComments.Summary.Should().Be("This is a Test Event.");
69-
types[0].Events[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
70-
types[0].Events[0].DocumentationComments.Example.Should().Be("This is an example.");
71-
types[0].Events[0].DocumentationComments.Value.Should().Be("This is the value.");
68+
types[0].Events[0].DocumentationComments?.Summary.Should().Be("This is a Test Event.");
69+
types[0].Events[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
70+
types[0].Events[0].DocumentationComments?.Example.Should().Be("This is an example.");
71+
types[0].Events[0].DocumentationComments?.Value.Should().Be("This is the value.");
7272
}
7373
}
7474

@@ -103,15 +103,15 @@ class Test
103103
// Assert
104104
using (new AssertionScope())
105105
{
106-
types[0].Events[0].DocumentationComments.Summary.Should().Be("These are Test Events.");
107-
types[0].Events[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
108-
types[0].Events[0].DocumentationComments.Example.Should().Be("This is an example.");
109-
types[0].Events[0].DocumentationComments.Value.Should().Be("This is the value.");
110-
111-
types[0].Events[1].DocumentationComments.Summary.Should().Be("These are Test Events.");
112-
types[0].Events[1].DocumentationComments.Remarks.Should().Be("This is a remark.");
113-
types[0].Events[1].DocumentationComments.Example.Should().Be("This is an example.");
114-
types[0].Events[1].DocumentationComments.Value.Should().Be("This is the value.");
106+
types[0].Events[0].DocumentationComments?.Summary.Should().Be("These are Test Events.");
107+
types[0].Events[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
108+
types[0].Events[0].DocumentationComments?.Example.Should().Be("This is an example.");
109+
types[0].Events[0].DocumentationComments?.Value.Should().Be("This is the value.");
110+
111+
types[0].Events[1].DocumentationComments?.Summary.Should().Be("These are Test Events.");
112+
types[0].Events[1].DocumentationComments?.Remarks.Should().Be("This is a remark.");
113+
types[0].Events[1].DocumentationComments?.Example.Should().Be("This is an example.");
114+
types[0].Events[1].DocumentationComments?.Value.Should().Be("This is the value.");
115115
}
116116
}
117117

@@ -144,10 +144,10 @@ public class Test
144144
// Assert
145145
using (new AssertionScope())
146146
{
147-
types[0].Fields[0].DocumentationComments.Summary.Should().Be("This is a Test Field.");
148-
types[0].Fields[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
149-
types[0].Fields[0].DocumentationComments.Example.Should().Be("This is an example.");
150-
types[0].Fields[0].DocumentationComments.Value.Should().Be("This is the value.");
147+
types[0].Fields[0].DocumentationComments?.Summary.Should().Be("This is a Test Field.");
148+
types[0].Fields[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
149+
types[0].Fields[0].DocumentationComments?.Example.Should().Be("This is an example.");
150+
types[0].Fields[0].DocumentationComments?.Value.Should().Be("This is the value.");
151151
}
152152
}
153153

@@ -180,15 +180,15 @@ public class Test
180180
// Assert
181181
using (new AssertionScope())
182182
{
183-
types[0].Fields[0].DocumentationComments.Summary.Should().Be("These are Test Fields.");
184-
types[0].Fields[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
185-
types[0].Fields[0].DocumentationComments.Example.Should().Be("This is an example.");
186-
types[0].Fields[0].DocumentationComments.Value.Should().Be("This is the value.");
187-
188-
types[0].Fields[1].DocumentationComments.Summary.Should().Be("These are Test Fields.");
189-
types[0].Fields[1].DocumentationComments.Remarks.Should().Be("This is a remark.");
190-
types[0].Fields[1].DocumentationComments.Example.Should().Be("This is an example.");
191-
types[0].Fields[1].DocumentationComments.Value.Should().Be("This is the value.");
183+
types[0].Fields[0].DocumentationComments?.Summary.Should().Be("These are Test Fields.");
184+
types[0].Fields[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
185+
types[0].Fields[0].DocumentationComments?.Example.Should().Be("This is an example.");
186+
types[0].Fields[0].DocumentationComments?.Value.Should().Be("This is the value.");
187+
188+
types[0].Fields[1].DocumentationComments?.Summary.Should().Be("These are Test Fields.");
189+
types[0].Fields[1].DocumentationComments?.Remarks.Should().Be("This is a remark.");
190+
types[0].Fields[1].DocumentationComments?.Example.Should().Be("This is an example.");
191+
types[0].Fields[1].DocumentationComments?.Value.Should().Be("This is the value.");
192192
}
193193
}
194194

@@ -217,9 +217,9 @@ interface Test
217217
// Assert
218218
using (new AssertionScope())
219219
{
220-
types[0].DocumentationComments.Summary.Should().Be("This is a Test Interface.");
221-
types[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
222-
types[0].DocumentationComments.Example.Should().Be("This is an example.");
220+
types[0].DocumentationComments?.Summary.Should().Be("This is a Test Interface.");
221+
types[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
222+
types[0].DocumentationComments?.Example.Should().Be("This is an example.");
223223
}
224224
}
225225

@@ -248,9 +248,9 @@ enum Test
248248
// Assert
249249
using (new AssertionScope())
250250
{
251-
types[0].DocumentationComments.Summary.Should().Be("This is a Test Enum.");
252-
types[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
253-
types[0].DocumentationComments.Example.Should().Be("This is an example.");
251+
types[0].DocumentationComments?.Summary.Should().Be("This is a Test Enum.");
252+
types[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
253+
types[0].DocumentationComments?.Example.Should().Be("This is an example.");
254254
}
255255
}
256256

@@ -279,9 +279,9 @@ struct Test
279279
// Assert
280280
using (new AssertionScope())
281281
{
282-
types[0].DocumentationComments.Summary.Should().Be("This is a Test Struct.");
283-
types[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
284-
types[0].DocumentationComments.Example.Should().Be("This is an example.");
282+
types[0].DocumentationComments?.Summary.Should().Be("This is a Test Struct.");
283+
types[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
284+
types[0].DocumentationComments?.Example.Should().Be("This is an example.");
285285
}
286286
}
287287

@@ -314,10 +314,10 @@ class Test
314314
// Assert
315315
using (new AssertionScope())
316316
{
317-
types[0].Methods[0].DocumentationComments.Summary.Should().Be("This is a Test Method.");
318-
types[0].Methods[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
319-
types[0].Methods[0].DocumentationComments.Example.Should().Be("This is an example.");
320-
types[0].Methods[0].DocumentationComments.Returns.Should().Be("Returns a string.");
317+
types[0].Methods[0].DocumentationComments?.Summary.Should().Be("This is a Test Method.");
318+
types[0].Methods[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
319+
types[0].Methods[0].DocumentationComments?.Example.Should().Be("This is an example.");
320+
types[0].Methods[0].DocumentationComments?.Returns.Should().Be("Returns a string.");
321321
}
322322
}
323323

@@ -350,10 +350,10 @@ class Test
350350
// Assert
351351
using (new AssertionScope())
352352
{
353-
types[0].Constructors[0].DocumentationComments.Summary.Should().Be("This is a Test Constructor.");
354-
types[0].Constructors[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
355-
types[0].Constructors[0].DocumentationComments.Example.Should().Be("This is an example.");
356-
types[0].Constructors[0].DocumentationComments.Returns.Should().Be("Returns a string.");
353+
types[0].Constructors[0].DocumentationComments?.Summary.Should().Be("This is a Test Constructor.");
354+
types[0].Constructors[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
355+
types[0].Constructors[0].DocumentationComments?.Example.Should().Be("This is an example.");
356+
types[0].Constructors[0].DocumentationComments?.Returns.Should().Be("Returns a string.");
357357
}
358358
}
359359

@@ -386,10 +386,10 @@ class Test
386386
// Assert
387387
using (new AssertionScope())
388388
{
389-
types[0].Properties[0].DocumentationComments.Summary.Should().Be("This is a Test Property.");
390-
types[0].Properties[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
391-
types[0].Properties[0].DocumentationComments.Example.Should().Be("This is an example.");
392-
types[0].Properties[0].DocumentationComments.Value.Should().Be("This is the value.");
389+
types[0].Properties[0].DocumentationComments?.Summary.Should().Be("This is a Test Property.");
390+
types[0].Properties[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
391+
types[0].Properties[0].DocumentationComments?.Example.Should().Be("This is an example.");
392+
types[0].Properties[0].DocumentationComments?.Value.Should().Be("This is the value.");
393393
}
394394
}
395395
}

0 commit comments

Comments
 (0)