Skip to content

Commit

Permalink
Properly handle null values in the test project
Browse files Browse the repository at this point in the history
  • Loading branch information
YVbakker authored and eNeRGy164 committed Jan 29, 2025
1 parent a3f31c6 commit a5cc5d8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 69 deletions.
38 changes: 19 additions & 19 deletions tests/DendroDocs.Tool.Tests/AnalyzerSetup/AnalyzerSetupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,87 +3,87 @@ namespace DendroDocs.Tool.Tests;
[TestClass]
public class AnalyzerSetupTests
{
private static readonly string solutionPath = GetSolutionPath();
private static readonly string SolutionPath = GetSolutionPath();

[TestMethod]
public void SolutionShouldLoadAllProjects()
{
// Arrange
var solutionFile = Path.Combine(solutionPath, "SolutionWithoutTests.sln");
var solutionFile = Path.Combine(SolutionPath, "SolutionWithoutTests.sln");

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

// Assert
analyzerSetup.Projects.Should().HaveCount(3);
analyzerSetup.Projects.Should().Satisfy(
p => p.FilePath.EndsWith("Project.csproj"),
p => p.FilePath.EndsWith("OtherProject.csproj"),
p => p.FilePath.EndsWith("AnotherProject.csproj"));
p => p.FilePath != null && p.FilePath.EndsWith("Project.csproj"),
p => p.FilePath != null && p.FilePath.EndsWith("OtherProject.csproj"),
p => p.FilePath != null && p.FilePath.EndsWith("AnotherProject.csproj"));
}

[TestMethod]
public void SolutionShouldFilterTestProjects()
{
// Arrange
var solutionFile = Path.Combine(solutionPath, "SolutionWithTests.sln");
var solutionFile = Path.Combine(SolutionPath, "SolutionWithTests.sln");

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

// Assert
analyzerSetup.Projects.Should().HaveCount(3);
analyzerSetup.Projects.Should().Satisfy(
p => p.FilePath.EndsWith("Project.csproj"),
p => p.FilePath.EndsWith("OtherProject.csproj"),
p => p.FilePath.EndsWith("AnotherProject.csproj"));
p => p.FilePath != null && p.FilePath.EndsWith("Project.csproj"),
p => p.FilePath != null && p.FilePath.EndsWith("OtherProject.csproj"),
p => p.FilePath != null && p.FilePath.EndsWith("AnotherProject.csproj"));
}

[TestMethod]
public void SolutionShouldFilterExcludedProject()
{
// Arrange
var solutionFile = Path.Combine(solutionPath, "SolutionWithoutTests.sln");
var excludeProjectFile = Path.Combine(solutionPath, "OtherProject", "OtherProject.csproj");
var solutionFile = Path.Combine(SolutionPath, "SolutionWithoutTests.sln");
var excludeProjectFile = Path.Combine(SolutionPath, "OtherProject", "OtherProject.csproj");

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

// Assert
analyzerSetup.Projects.Should().HaveCount(2);
analyzerSetup.Projects.Should().Satisfy(
p => p.FilePath.EndsWith("Project.csproj"),
p => p.FilePath.EndsWith("AnotherProject.csproj"));
p => p.FilePath != null && p.FilePath.EndsWith("Project.csproj"),
p => p.FilePath != null && p.FilePath.EndsWith("AnotherProject.csproj"));
}

[TestMethod]
public void SolutionShouldFilterExcludedProjects()
{
// Arrange
var solutionFile = Path.Combine(solutionPath, "SolutionWithoutTests.sln");
var excludeProjectFile1 = Path.Combine(solutionPath, "OtherProject", "OtherProject.csproj");
var excludeProjectFile2 = Path.Combine(solutionPath, "AnotherProject", "AnotherProject.csproj");
var solutionFile = Path.Combine(SolutionPath, "SolutionWithoutTests.sln");
var excludeProjectFile1 = Path.Combine(SolutionPath, "OtherProject", "OtherProject.csproj");
var excludeProjectFile2 = Path.Combine(SolutionPath, "AnotherProject", "AnotherProject.csproj");

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

// Assert
analyzerSetup.Projects.Should().HaveCount(1);
analyzerSetup.Projects.Should().Satisfy(p => p.FilePath.EndsWith("Project.csproj"));
analyzerSetup.Projects.Should().Satisfy(p => p.FilePath != null && p.FilePath.EndsWith("Project.csproj"));
}

[TestMethod]
public void SolutionShouldLoadProject()
{
// Arrange
var projectFile = Path.Combine(solutionPath, "Project", "Project.csproj");
var projectFile = Path.Combine(SolutionPath, "Project", "Project.csproj");

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

// Assert
analyzerSetup.Projects.Should().HaveCount(1);
analyzerSetup.Projects.Should().Satisfy(p => p.FilePath.EndsWith("Project.csproj"));
analyzerSetup.Projects.Should().Satisfy(p => p.FilePath != null && p.FilePath.EndsWith("Project.csproj"));
}

private static string GetSolutionPath()
Expand Down
100 changes: 50 additions & 50 deletions tests/DendroDocs.Tool.Tests/DocumentationCommentsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class Test
// Assert
using (new AssertionScope())
{
types[0].DocumentationComments.Summary.Should().Be("This is a Test Class.");
types[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
types[0].DocumentationComments.Example.Should().Be("This is an example.");
types[0].DocumentationComments?.Summary.Should().Be("This is a Test Class.");
types[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
types[0].DocumentationComments?.Example.Should().Be("This is an example.");
}
}

Expand Down Expand Up @@ -65,10 +65,10 @@ class Test
// Assert
using (new AssertionScope())
{
types[0].Events[0].DocumentationComments.Summary.Should().Be("This is a Test Event.");
types[0].Events[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
types[0].Events[0].DocumentationComments.Example.Should().Be("This is an example.");
types[0].Events[0].DocumentationComments.Value.Should().Be("This is the value.");
types[0].Events[0].DocumentationComments?.Summary.Should().Be("This is a Test Event.");
types[0].Events[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
types[0].Events[0].DocumentationComments?.Example.Should().Be("This is an example.");
types[0].Events[0].DocumentationComments?.Value.Should().Be("This is the value.");
}
}

Expand Down Expand Up @@ -103,15 +103,15 @@ class Test
// Assert
using (new AssertionScope())
{
types[0].Events[0].DocumentationComments.Summary.Should().Be("These are Test Events.");
types[0].Events[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
types[0].Events[0].DocumentationComments.Example.Should().Be("This is an example.");
types[0].Events[0].DocumentationComments.Value.Should().Be("This is the value.");

types[0].Events[1].DocumentationComments.Summary.Should().Be("These are Test Events.");
types[0].Events[1].DocumentationComments.Remarks.Should().Be("This is a remark.");
types[0].Events[1].DocumentationComments.Example.Should().Be("This is an example.");
types[0].Events[1].DocumentationComments.Value.Should().Be("This is the value.");
types[0].Events[0].DocumentationComments?.Summary.Should().Be("These are Test Events.");
types[0].Events[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
types[0].Events[0].DocumentationComments?.Example.Should().Be("This is an example.");
types[0].Events[0].DocumentationComments?.Value.Should().Be("This is the value.");

types[0].Events[1].DocumentationComments?.Summary.Should().Be("These are Test Events.");
types[0].Events[1].DocumentationComments?.Remarks.Should().Be("This is a remark.");
types[0].Events[1].DocumentationComments?.Example.Should().Be("This is an example.");
types[0].Events[1].DocumentationComments?.Value.Should().Be("This is the value.");
}
}

Expand Down Expand Up @@ -144,10 +144,10 @@ public class Test
// Assert
using (new AssertionScope())
{
types[0].Fields[0].DocumentationComments.Summary.Should().Be("This is a Test Field.");
types[0].Fields[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
types[0].Fields[0].DocumentationComments.Example.Should().Be("This is an example.");
types[0].Fields[0].DocumentationComments.Value.Should().Be("This is the value.");
types[0].Fields[0].DocumentationComments?.Summary.Should().Be("This is a Test Field.");
types[0].Fields[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
types[0].Fields[0].DocumentationComments?.Example.Should().Be("This is an example.");
types[0].Fields[0].DocumentationComments?.Value.Should().Be("This is the value.");
}
}

Expand Down Expand Up @@ -180,15 +180,15 @@ public class Test
// Assert
using (new AssertionScope())
{
types[0].Fields[0].DocumentationComments.Summary.Should().Be("These are Test Fields.");
types[0].Fields[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
types[0].Fields[0].DocumentationComments.Example.Should().Be("This is an example.");
types[0].Fields[0].DocumentationComments.Value.Should().Be("This is the value.");

types[0].Fields[1].DocumentationComments.Summary.Should().Be("These are Test Fields.");
types[0].Fields[1].DocumentationComments.Remarks.Should().Be("This is a remark.");
types[0].Fields[1].DocumentationComments.Example.Should().Be("This is an example.");
types[0].Fields[1].DocumentationComments.Value.Should().Be("This is the value.");
types[0].Fields[0].DocumentationComments?.Summary.Should().Be("These are Test Fields.");
types[0].Fields[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
types[0].Fields[0].DocumentationComments?.Example.Should().Be("This is an example.");
types[0].Fields[0].DocumentationComments?.Value.Should().Be("This is the value.");

types[0].Fields[1].DocumentationComments?.Summary.Should().Be("These are Test Fields.");
types[0].Fields[1].DocumentationComments?.Remarks.Should().Be("This is a remark.");
types[0].Fields[1].DocumentationComments?.Example.Should().Be("This is an example.");
types[0].Fields[1].DocumentationComments?.Value.Should().Be("This is the value.");
}
}

Expand Down Expand Up @@ -217,9 +217,9 @@ interface Test
// Assert
using (new AssertionScope())
{
types[0].DocumentationComments.Summary.Should().Be("This is a Test Interface.");
types[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
types[0].DocumentationComments.Example.Should().Be("This is an example.");
types[0].DocumentationComments?.Summary.Should().Be("This is a Test Interface.");
types[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
types[0].DocumentationComments?.Example.Should().Be("This is an example.");
}
}

Expand Down Expand Up @@ -248,9 +248,9 @@ enum Test
// Assert
using (new AssertionScope())
{
types[0].DocumentationComments.Summary.Should().Be("This is a Test Enum.");
types[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
types[0].DocumentationComments.Example.Should().Be("This is an example.");
types[0].DocumentationComments?.Summary.Should().Be("This is a Test Enum.");
types[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
types[0].DocumentationComments?.Example.Should().Be("This is an example.");
}
}

Expand Down Expand Up @@ -279,9 +279,9 @@ struct Test
// Assert
using (new AssertionScope())
{
types[0].DocumentationComments.Summary.Should().Be("This is a Test Struct.");
types[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
types[0].DocumentationComments.Example.Should().Be("This is an example.");
types[0].DocumentationComments?.Summary.Should().Be("This is a Test Struct.");
types[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
types[0].DocumentationComments?.Example.Should().Be("This is an example.");
}
}

Expand Down Expand Up @@ -314,10 +314,10 @@ class Test
// Assert
using (new AssertionScope())
{
types[0].Methods[0].DocumentationComments.Summary.Should().Be("This is a Test Method.");
types[0].Methods[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
types[0].Methods[0].DocumentationComments.Example.Should().Be("This is an example.");
types[0].Methods[0].DocumentationComments.Returns.Should().Be("Returns a string.");
types[0].Methods[0].DocumentationComments?.Summary.Should().Be("This is a Test Method.");
types[0].Methods[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
types[0].Methods[0].DocumentationComments?.Example.Should().Be("This is an example.");
types[0].Methods[0].DocumentationComments?.Returns.Should().Be("Returns a string.");
}
}

Expand Down Expand Up @@ -350,10 +350,10 @@ class Test
// Assert
using (new AssertionScope())
{
types[0].Constructors[0].DocumentationComments.Summary.Should().Be("This is a Test Constructor.");
types[0].Constructors[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
types[0].Constructors[0].DocumentationComments.Example.Should().Be("This is an example.");
types[0].Constructors[0].DocumentationComments.Returns.Should().Be("Returns a string.");
types[0].Constructors[0].DocumentationComments?.Summary.Should().Be("This is a Test Constructor.");
types[0].Constructors[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
types[0].Constructors[0].DocumentationComments?.Example.Should().Be("This is an example.");
types[0].Constructors[0].DocumentationComments?.Returns.Should().Be("Returns a string.");
}
}

Expand Down Expand Up @@ -386,10 +386,10 @@ class Test
// Assert
using (new AssertionScope())
{
types[0].Properties[0].DocumentationComments.Summary.Should().Be("This is a Test Property.");
types[0].Properties[0].DocumentationComments.Remarks.Should().Be("This is a remark.");
types[0].Properties[0].DocumentationComments.Example.Should().Be("This is an example.");
types[0].Properties[0].DocumentationComments.Value.Should().Be("This is the value.");
types[0].Properties[0].DocumentationComments?.Summary.Should().Be("This is a Test Property.");
types[0].Properties[0].DocumentationComments?.Remarks.Should().Be("This is a remark.");
types[0].Properties[0].DocumentationComments?.Example.Should().Be("This is an example.");
types[0].Properties[0].DocumentationComments?.Value.Should().Be("This is the value.");
}
}
}

0 comments on commit a5cc5d8

Please sign in to comment.