Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Unitverse.Core.Tests/Resources/PrimaryConstructor.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace TestNamespace.SubNameSpace;

public class RequestHandler(string options) { private readonly string _options = options; }
22 changes: 16 additions & 6 deletions src/Unitverse.Core.Tests/TestClasses.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Unitverse.Core.Tests/TestClasses.resx
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@
<data name="PocoInitialization" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\PocoInitialization.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="PrimaryConstructor" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\PrimaryConstructor.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="PropertyChangeTestFile" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\PropertyChangeTestFile.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion src/Unitverse.Core.Tests/UnitTestGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static IEnumerable<object[]> TestClassResourceNames
var mocks = new object[] { MockingFrameworkType.Moq, MockingFrameworkType.NSubstitute, MockingFrameworkType.FakeItEasy, MockingFrameworkType.MoqAutoMock, MockingFrameworkType.JustMock };

#if VS2019
entryKeys = entryKeys.Where(x => x.IndexOf("FileScoped", StringComparison.OrdinalIgnoreCase) < 0).ToList();
entryKeys = entryKeys.Where(x => x.IndexOf("FileScoped", StringComparison.OrdinalIgnoreCase) < 0 && x.IndexOf("PrimaryConstructor", StringComparison.OrdinalIgnoreCase) < 0).ToList();
#endif

var baseSet = entryKeys.Select(x => new List<object> { x });
Expand Down
2 changes: 1 addition & 1 deletion src/Unitverse.Core.Tests/Unitverse.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PropertyGroup>

<ItemGroup Condition="'$(VsTargetVersion)' == 'VS2022'">
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.10.0" />
</ItemGroup>

<ItemGroup Condition="'$(VsTargetVersion)' == 'VS2019'">
Expand Down
3 changes: 2 additions & 1 deletion src/Unitverse.Core/Frameworks/Test/BaseTestFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Unitverse.Core.Helpers;
Expand Down Expand Up @@ -41,7 +42,7 @@ IEnumerable<XmlElementSyntax> Elements()
yield return XmlCommentHelper.Param(parameterName, parameterDescription);
}

if (method.Modifiers.Any(x => x.Kind() == SyntaxKind.AsyncKeyword))
if (method.Modifiers.Any(x => x.IsKind(SyntaxKind.AsyncKeyword)))
{
yield return XmlCommentHelper.Returns("A task that represents the running test.");
}
Expand Down
10 changes: 5 additions & 5 deletions src/Unitverse.Core/Generation/CategorizedUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@
{
var resolvedUsings = new List<UsingDirectiveSyntax>();

resolvedUsings.AddRange(_systemUsings.OrderBy(x => x.Name.ToString()));
resolvedUsings.AddRange(_nonSystemUsings.OrderBy(x => x.Name.ToString()));
resolvedUsings.AddRange(_systemUsings.OrderBy(x => x.Name?.ToString()));
resolvedUsings.AddRange(_nonSystemUsings.OrderBy(x => x.Name?.ToString()));
resolvedUsings.AddRange(_aliasUsings.OrderBy(x => x.Alias?.ToString()));
resolvedUsings.AddRange(_staticSystemUsings.OrderBy(x => x.Name.ToString()));
resolvedUsings.AddRange(_staticNonSystemUsings.OrderBy(x => x.Name.ToString()));
resolvedUsings.AddRange(_staticSystemUsings.OrderBy(x => x.Name?.ToString()));
resolvedUsings.AddRange(_staticNonSystemUsings.OrderBy(x => x.Name?.ToString()));

return resolvedUsings;
}

private static bool IsSystemUsing(UsingDirectiveSyntax usingDirective)
{
var name = usingDirective.Name.ToString();
var name = usingDirective.Name?.ToString();
return string.Equals(name, nameof(System), StringComparison.OrdinalIgnoreCase) ||
name.StartsWith(nameof(System) + ".", StringComparison.OrdinalIgnoreCase);

Check warning on line 80 in src/Unitverse.Core/Generation/CategorizedUsings.cs

View workflow job for this annotation

GitHub Actions / build (VS2022)

Dereference of a possibly null reference.

Check warning on line 80 in src/Unitverse.Core/Generation/CategorizedUsings.cs

View workflow job for this annotation

GitHub Actions / build (VS2019)

Dereference of a possibly null reference.
}
}
}
2 changes: 1 addition & 1 deletion src/Unitverse.Core/Helpers/Generate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public static ExpressionSyntax MethodCall(
throw new ArgumentNullException(nameof(name));
}

if (method.ParameterList.Parameters.Count > 0 && method.ParameterList.Parameters[0].Modifiers.Any(x => x.Kind() == SyntaxKind.ThisKeyword) && arguments.Length > 0 && arguments[0] is ExpressionSyntax expression)
if (method.ParameterList.Parameters.Count > 0 && method.ParameterList.Parameters[0].Modifiers.Any(x => x.IsKind(SyntaxKind.ThisKeyword)) && arguments.Length > 0 && arguments[0] is ExpressionSyntax expression)
{
target = expression;
arguments = arguments.Skip(1).ToArray();
Expand Down
2 changes: 1 addition & 1 deletion src/Unitverse.Core/Helpers/NameExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static string GetClassName(this TypeDeclarationSyntax declaration)
throw new ArgumentNullException(nameof(declaration));
}

var classIdentifierToken = declaration.ChildTokens().FirstOrDefault(n => n.Kind() == SyntaxKind.IdentifierToken);
var classIdentifierToken = declaration.ChildTokens().FirstOrDefault(n => n.IsKind(SyntaxKind.IdentifierToken));
if (classIdentifierToken == default(SyntaxToken))
{
throw new InvalidOperationException(Strings.NameExtractor_GetClassName_Could_not_find_type_identifier_);
Expand Down
11 changes: 10 additions & 1 deletion src/Unitverse.Core/Helpers/TestableItemExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ private ClassModel ExtractClassModel(TypeDeclarationSyntax syntax, SemanticModel
}
}
}
#if VS2022
else if (syntax.ParameterList != null)
{
var constructor = SyntaxFactory.ConstructorDeclaration(model.ClassName).WithParameterList(syntax.ParameterList);
var parameters = ExtractParameters(syntax.ParameterList.Parameters, semanticModel);

model.Constructors.Add(new ConstructorModel(model.ClassName, parameters, constructor));
}
#endif

foreach (var methodModel in syntax.ChildNodes().OfType<MethodDeclarationSyntax>().Where(x => x.ExplicitInterfaceSpecifier != null).Select(x => ExtractMethodModel(x, semanticModel)))
{
Expand All @@ -163,7 +172,7 @@ private ClassModel ExtractClassModel(TypeDeclarationSyntax syntax, SemanticModel

private void CollectRelatedPartialTypeConstructors(TypeDeclarationSyntax syntax, SemanticModel semanticModel, IList<Func<SyntaxTokenList, bool>> allowedModifiers, ClassModel model)
{
if (!syntax.Modifiers.Any(x => x.Kind() == SyntaxKind.PartialKeyword))
if (!syntax.Modifiers.Any(x => x.IsKind(SyntaxKind.PartialKeyword)))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ public bool CanHandle(ClassModel method, ClassModel model)
{
throw new ArgumentNullException(nameof(model));
}

#if VS2022
return !model.Declaration.ChildNodes().OfType<ConstructorDeclarationSyntax>().Any() && !(model.Declaration is RecordDeclarationSyntax) && model.Declaration.ParameterList is null && !model.IsStatic;
#else
return !model.Declaration.ChildNodes().OfType<ConstructorDeclarationSyntax>().Any() && !(model.Declaration is RecordDeclarationSyntax) && !model.IsStatic;
#endif
}

public IEnumerable<SectionedMethodHandler> Create(ClassModel method, ClassModel model, NamingContext namingContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool CanHandle(ClassModel method, ClassModel model)
return false;
}

if (model.Declaration.ChildNodes().OfType<ConstructorDeclarationSyntax>().Count() == 1 && model.DefaultConstructor.Node.Modifiers.Any(x => x.Kind() == SyntaxKind.PublicKeyword))
if (model.Declaration.ChildNodes().OfType<ConstructorDeclarationSyntax>().Count() == 1 && model.DefaultConstructor.Node.Modifiers.Any(x => x.IsKind(SyntaxKind.PublicKeyword)))
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public IEnumerable<SectionedMethodHandler> Create(IMethodModel method, ClassMode

foreach (var parameter in method.Parameters)
{
if (parameter.Node.Modifiers.Any(x => x.Kind() == SyntaxKind.OutKeyword))
if (parameter.Node.Modifiers.Any(x => x.IsKind(SyntaxKind.OutKeyword)))
{
paramExpressions.Add(SyntaxFactory.Argument(SyntaxFactory.DeclarationExpression(SyntaxFactory.IdentifierName("var"), SyntaxFactory.SingleVariableDesignation(parameter.Identifier))).WithRefKindKeyword(SyntaxFactory.Token(SyntaxKind.OutKeyword)));
}
Expand All @@ -89,7 +89,7 @@ public IEnumerable<SectionedMethodHandler> Create(IMethodModel method, ClassMode
generatedMethod.Arrange(Generate.VariableDeclaration(parameter.TypeInfo.Type, _frameworkSet, paramName, defaultAssignmentValue));
}

if (parameter.Node.Modifiers.Any(x => x.Kind() == SyntaxKind.RefKeyword))
if (parameter.Node.Modifiers.Any(x => x.IsKind(SyntaxKind.RefKeyword)))
{
paramExpressions.Add(SyntaxFactory.Argument(paramIdentifier).WithRefKindKeyword(SyntaxFactory.Token(SyntaxKind.RefKeyword)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public IEnumerable<SectionedMethodHandler> Create(IMethodModel method, ClassMode

foreach (var parameter in method.Parameters)
{
if (parameter.Node.Modifiers.Any(x => x.Kind() == SyntaxKind.OutKeyword))
if (parameter.Node.Modifiers.Any(x => x.IsKind(SyntaxKind.OutKeyword)))
{
paramExpressions.Add(SyntaxFactory.Argument(SyntaxFactory.DeclarationExpression(SyntaxFactory.IdentifierName("var"), SyntaxFactory.SingleVariableDesignation(parameter.Identifier))).WithRefKindKeyword(SyntaxFactory.Token(SyntaxKind.OutKeyword)));
}
Expand All @@ -121,7 +121,7 @@ public IEnumerable<SectionedMethodHandler> Create(IMethodModel method, ClassMode
generatedMethod.Arrange(Generate.VariableDeclaration(parameter.TypeInfo.Type, _frameworkSet, parameter.Name, defaultAssignmentValue));
}

if (parameter.Node.Modifiers.Any(x => x.Kind() == SyntaxKind.RefKeyword))
if (parameter.Node.Modifiers.Any(x => x.IsKind(SyntaxKind.RefKeyword)))
{
paramExpressions.Add(SyntaxFactory.Argument(SyntaxFactory.IdentifierName(parameter.Name)).WithRefKindKeyword(SyntaxFactory.Token(SyntaxKind.RefKeyword)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public IEnumerable<SectionedMethodHandler> Create(IMethodModel method, ClassMode
continue;
}

if (currentParam.Node.Modifiers.Any(x => x.Kind() == SyntaxKind.OutKeyword))
if (currentParam.Node.Modifiers.Any(x => x.IsKind(SyntaxKind.OutKeyword)))
{
continue;
}
Expand All @@ -83,7 +83,7 @@ public IEnumerable<SectionedMethodHandler> Create(IMethodModel method, ClassMode
for (var index = 0; index < method.Parameters.Count; index++)
{
var parameter = method.Parameters[index];
if (parameter.Node.Modifiers.Any(x => x.Kind() == SyntaxKind.RefKeyword))
if (parameter.Node.Modifiers.Any(x => x.IsKind(SyntaxKind.RefKeyword)))
{
var defaultAssignmentValue = AssignmentValueHelper.GetDefaultAssignmentValue(parameter.TypeInfo, model.SemanticModel, _frameworkSet);

Expand All @@ -99,7 +99,7 @@ public IEnumerable<SectionedMethodHandler> Create(IMethodModel method, ClassMode

paramList.Add(SyntaxFactory.Argument(SyntaxFactory.IdentifierName(parameter.Name)).WithRefKindKeyword(SyntaxFactory.Token(SyntaxKind.RefKeyword)));
}
else if (parameter.Node.Modifiers.Any(x => x.Kind() == SyntaxKind.OutKeyword))
else if (parameter.Node.Modifiers.Any(x => x.IsKind(SyntaxKind.OutKeyword)))
{
paramList.Add(SyntaxFactory.Argument(SyntaxFactory.IdentifierName("_")).WithRefKindKeyword(SyntaxFactory.Token(SyntaxKind.OutKeyword)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public IEnumerable<SectionedMethodHandler> Create(IMethodModel method, ClassMode
continue;
}

if (currentParam.Node.Modifiers.Any(x => x.Kind() == SyntaxKind.OutKeyword))
if (currentParam.Node.Modifiers.Any(x => x.IsKind(SyntaxKind.OutKeyword)))
{
continue;
}
Expand Down Expand Up @@ -115,7 +115,7 @@ private void AddMethodBody(IMethodModel method, ClassModel model, int parameterI
for (var index = 0; index < method.Parameters.Count; index++)
{
var parameter = method.Parameters[index];
if (parameter.Node.Modifiers.Any(x => x.Kind() == SyntaxKind.RefKeyword))
if (parameter.Node.Modifiers.Any(x => x.IsKind(SyntaxKind.RefKeyword)))
{
var defaultAssignmentValue = AssignmentValueHelper.GetDefaultAssignmentValue(parameter.TypeInfo, model.SemanticModel, _frameworkSet);

Expand All @@ -131,7 +131,7 @@ private void AddMethodBody(IMethodModel method, ClassModel model, int parameterI

paramList.Add(SyntaxFactory.Argument(SyntaxFactory.IdentifierName(parameter.Name)).WithRefKindKeyword(SyntaxFactory.Token(SyntaxKind.RefKeyword)));
}
else if (parameter.Node.Modifiers.Any(x => x.Kind() == SyntaxKind.OutKeyword))
else if (parameter.Node.Modifiers.Any(x => x.IsKind(SyntaxKind.OutKeyword)))
{
paramList.Add(SyntaxFactory.Argument(SyntaxFactory.IdentifierName("_")).WithRefKindKeyword(SyntaxFactory.Token(SyntaxKind.OutKeyword)));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Unitverse.Core/Unitverse.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
</PropertyGroup>

<ItemGroup Condition="'$(VsTargetVersion)' == 'VS2022'">
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0" />
</ItemGroup>

<ItemGroup Condition="'$(VsTargetVersion)' == 'VS2019'">
Expand All @@ -37,7 +37,7 @@
<ItemGroup>
<PackageReference Include="DotLiquid" Version="2.2.692" />
<PackageReference Include="editorconfig" Version="0.12.2" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</PropertyGroup>

<ItemGroup Condition="'$(VsTargetVersion)' == 'VS2022'">
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.10.0" />
</ItemGroup>

<ItemGroup Condition="'$(VsTargetVersion)' == 'VS2019'">
Expand Down
6 changes: 3 additions & 3 deletions src/Unitverse.Tests.Common/Unitverse.Tests.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
</PropertyGroup>

<ItemGroup Condition="'$(VsTargetVersion)' == 'VS2022'">
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0" />
</ItemGroup>

<ItemGroup Condition="'$(VsTargetVersion)' == 'VS2019'">
Expand All @@ -33,7 +33,7 @@

<ItemGroup>
<PackageReference Include="editorconfig" Version="0.12.2" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading
Loading