Skip to content

Commit a6733b5

Browse files
authored
Adding editorconfig (#132)
Updating LangVersion to 10 Converted everything to file scoped namespaces Ran dotnet format to clean up the source Bumping GH Action to 6.0 SDK Test project to net6 an nuget updates
1 parent b9eb041 commit a6733b5

File tree

82 files changed

+3544
-3259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+3544
-3259
lines changed

.editorconfig

Lines changed: 365 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/dotnetcore.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Setup .NET Core
3030
uses: actions/setup-dotnet@v1
3131
with:
32-
dotnet-version: 5.0.100
32+
dotnet-version: 6.0.100
3333

3434
# Run unit tests
3535
- name: Test

Directory.Build.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<Project>
22

33
<PropertyGroup>
4-
<LangVersion>9.0</LangVersion>
4+
<LangVersion>10.0</LangVersion>
55
<Nullable>enable</Nullable>
6+
<EnforceCodeStyleInBuild Condition=" '$(BuildingForLiveUnitTesting)' == '' ">true</EnforceCodeStyleInBuild>
67
<TreatWarningsAsErrors Condition=" '$(BuildingForLiveUnitTesting)' == '' ">true</TreatWarningsAsErrors>
78
</PropertyGroup>
89

Generators/CombineGenerator.cs

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,61 @@
1-
using Microsoft.CodeAnalysis;
1+
using System;
2+
using System.Linq;
3+
using Microsoft.CodeAnalysis;
24
using Microsoft.CodeAnalysis.CSharp;
35
using Microsoft.CodeAnalysis.CSharp.Syntax;
4-
using System;
5-
using System.Linq;
66
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
77
using static Microsoft.CodeAnalysis.CSharp.SyntaxKind;
88

9-
namespace Generators
9+
namespace Generators;
10+
11+
[Generator]
12+
public class CombineGenerator : ISourceGenerator
1013
{
11-
[Generator]
12-
public class CombineGenerator : ISourceGenerator
14+
public void Initialize(GeneratorInitializationContext context)
1315
{
14-
public void Initialize(GeneratorInitializationContext context)
15-
{
16-
}
16+
}
1717

18-
public void Execute(GeneratorExecutionContext context)
19-
{
20-
var sourceCode = CompilationUnit()
21-
.WithMembers(SingletonList<MemberDeclarationSyntax>(NamespaceDeclaration(QualifiedName(IdentifierName("Moq"), IdentifierName("AutoMock")))
22-
.WithMembers(SingletonList<MemberDeclarationSyntax>(ClassDeclaration("AutoMocker")
23-
.WithModifiers(TokenList(Token(PartialKeyword)))
24-
.WithMembers(List(Enumerable.Range(1, 10).Select(Combine)))))))
25-
.NormalizeWhitespace()
26-
.ToFullString();
18+
public void Execute(GeneratorExecutionContext context)
19+
{
20+
var sourceCode = CompilationUnit()
21+
.WithMembers(SingletonList<MemberDeclarationSyntax>(NamespaceDeclaration(QualifiedName(IdentifierName("Moq"), IdentifierName("AutoMock")))
22+
.WithMembers(SingletonList<MemberDeclarationSyntax>(ClassDeclaration("AutoMocker")
23+
.WithModifiers(TokenList(Token(PartialKeyword)))
24+
.WithMembers(List(Enumerable.Range(1, 10).Select(Combine)))))))
25+
.NormalizeWhitespace()
26+
.ToFullString();
2727

28-
context.AddSource(nameof(CombineGenerator), sourceCode);
29-
}
28+
context.AddSource(nameof(CombineGenerator), sourceCode);
29+
}
3030

31-
private MemberDeclarationSyntax Combine(int count)
32-
{
33-
return MethodDeclaration(PredefinedType(Token(VoidKeyword)), "Combine")
34-
.WithModifiers(TokenList(Token(TriviaList(Trivia(Documentation)), PublicKeyword, TriviaList())))
35-
.WithTypeParameterList(TypeParameterList(SeparatedList(Enumerable.Range(0, count + 1).Select(type))))
36-
.WithExpressionBody(ArrowExpressionClause(
37-
InvocationExpression(IdentifierName("Combine"))
38-
.WithArgumentList(ArgumentList(SeparatedList(Enumerable.Range(0, count + 1).Select(argument))))))
39-
.WithSemicolonToken(Token(SemicolonToken))
40-
.WithTrailingTrivia(LineFeed);
31+
private MemberDeclarationSyntax Combine(int count)
32+
{
33+
return MethodDeclaration(PredefinedType(Token(VoidKeyword)), "Combine")
34+
.WithModifiers(TokenList(Token(TriviaList(Trivia(Documentation)), PublicKeyword, TriviaList())))
35+
.WithTypeParameterList(TypeParameterList(SeparatedList(Enumerable.Range(0, count + 1).Select(type))))
36+
.WithExpressionBody(ArrowExpressionClause(
37+
InvocationExpression(IdentifierName("Combine"))
38+
.WithArgumentList(ArgumentList(SeparatedList(Enumerable.Range(0, count + 1).Select(argument))))))
39+
.WithSemicolonToken(Token(SemicolonToken))
40+
.WithTrailingTrivia(LineFeed);
4141

42-
static string identifier(int index) => index is 0 ? "TService" : $"TAsWellAs{index}";
43-
static TypeParameterSyntax type(int index) => TypeParameter(identifier(index));
44-
static ArgumentSyntax argument(int index) => Argument(TypeOfExpression(IdentifierName(identifier(index))));
45-
}
42+
static string identifier(int index) => index is 0 ? "TService" : $"TAsWellAs{index}";
43+
static TypeParameterSyntax type(int index) => TypeParameter(identifier(index));
44+
static ArgumentSyntax argument(int index) => Argument(TypeOfExpression(IdentifierName(identifier(index))));
45+
}
4646

47-
private DocumentationCommentTriviaSyntax Documentation { get; } = DocumentationComment(
48-
XmlText(" "),
49-
XmlSummaryElement(
50-
new[]
51-
{
47+
private DocumentationCommentTriviaSyntax Documentation { get; } = DocumentationComment(
48+
XmlText(" "),
49+
XmlSummaryElement(
50+
new[]
51+
{
5252
"Combines all given types so that they are mocked by the same",
5353
@"mock. Some IoC containers call this ""Forwarding"" one type to",
5454
"other interfaces. In the end, this just means that all given",
5555
"types will be implemnted by the same instance.",
56-
}.SelectMany(text => new[] { XmlNewLine(Environment.NewLine), XmlText($" {text}") })
57-
.Concat(new[] { XmlNewLine(Environment.NewLine), XmlText(" ") })
58-
.ToArray()
59-
),
60-
XmlText($"{Environment.NewLine} "));
61-
}
56+
}.SelectMany(text => new[] { XmlNewLine(Environment.NewLine), XmlText($" {text}") })
57+
.Concat(new[] { XmlNewLine(Environment.NewLine), XmlText(" ") })
58+
.ToArray()
59+
),
60+
XmlText($"{Environment.NewLine} "));
6261
}

Generators/Generators.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" PrivateAssets="all" />
9+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" PrivateAssets="all" />
1010
</ItemGroup>
1111

1212
</Project>
Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,69 @@
1-
using Microsoft.VisualStudio.TestTools.UnitTesting;
2-
using System;
1+
using System;
32
using System.Reflection;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
44
using Moq.AutoMock.Tests.Util;
55

6-
namespace Moq.AutoMock.Tests
6+
namespace Moq.AutoMock.Tests;
7+
8+
[TestClass]
9+
public class ConstructorSelectorTests
710
{
8-
[TestClass]
9-
public class ConstructorSelectorTests
10-
{
11-
private const BindingFlags DefaultBindingFlags = BindingFlags.Instance | BindingFlags.Public;
11+
private const BindingFlags DefaultBindingFlags = BindingFlags.Instance | BindingFlags.Public;
1212

13-
[TestMethod]
14-
public void It_chooses_the_ctor_with_arguments()
15-
{
16-
var ctor = typeof(WithDefaultAndSingleParameter).SelectCtor(Array.Empty<Type>(), DefaultBindingFlags);
17-
Assert.AreEqual(1, ctor.GetParameters().Length);
18-
}
13+
[TestMethod]
14+
public void It_chooses_the_ctor_with_arguments()
15+
{
16+
var ctor = typeof(WithDefaultAndSingleParameter).SelectCtor(Array.Empty<Type>(), DefaultBindingFlags);
17+
Assert.AreEqual(1, ctor.GetParameters().Length);
18+
}
1919

20-
[TestMethod]
21-
public void It_chooses_the_ctor_with_the_most_arguments()
22-
{
23-
var ctor = typeof(With3Parameters).SelectCtor(Array.Empty<Type>(), DefaultBindingFlags);
24-
Assert.AreEqual(2, ctor.GetParameters().Length);
25-
}
20+
[TestMethod]
21+
public void It_chooses_the_ctor_with_the_most_arguments()
22+
{
23+
var ctor = typeof(With3Parameters).SelectCtor(Array.Empty<Type>(), DefaultBindingFlags);
24+
Assert.AreEqual(2, ctor.GetParameters().Length);
25+
}
2626

27-
[TestMethod]
28-
public void It_chooses_the_ctor_with_the_most_arguments_when_arguments_are_arrays()
29-
{
30-
var ctor = typeof(WithArrayParameter).SelectCtor(Array.Empty<Type>(), DefaultBindingFlags);
31-
Assert.AreEqual(1, ctor.GetParameters().Length);
32-
}
27+
[TestMethod]
28+
public void It_chooses_the_ctor_with_the_most_arguments_when_arguments_are_arrays()
29+
{
30+
var ctor = typeof(WithArrayParameter).SelectCtor(Array.Empty<Type>(), DefaultBindingFlags);
31+
Assert.AreEqual(1, ctor.GetParameters().Length);
32+
}
3333

34-
[TestMethod]
35-
public void It_wont_select_if_an_argument_is_sealed_and_only_one_constructor()
36-
{
37-
Assert.ThrowsException<ArgumentException>(
38-
() => typeof(WithSealedParameter2).SelectCtor(Array.Empty<Type>(), DefaultBindingFlags));
39-
}
34+
[TestMethod]
35+
public void It_wont_select_if_an_argument_is_sealed_and_only_one_constructor()
36+
{
37+
Assert.ThrowsException<ArgumentException>(
38+
() => typeof(WithSealedParameter2).SelectCtor(Array.Empty<Type>(), DefaultBindingFlags));
39+
}
4040

41-
[TestMethod]
42-
public void It_wont_select_if_an_argument_is_sealed_and_not_array()
43-
{
44-
var ctor = typeof(WithSealedParameter).SelectCtor(Array.Empty<Type>(), DefaultBindingFlags);
45-
Assert.AreEqual(0, ctor.GetParameters().Length);
46-
}
41+
[TestMethod]
42+
public void It_wont_select_if_an_argument_is_sealed_and_not_array()
43+
{
44+
var ctor = typeof(WithSealedParameter).SelectCtor(Array.Empty<Type>(), DefaultBindingFlags);
45+
Assert.AreEqual(0, ctor.GetParameters().Length);
46+
}
4747

48-
[TestMethod]
49-
public void It_will_select_if_an_argument_is_sealed_and_supplied()
50-
{
51-
var ctor = typeof(WithSealedParameter).SelectCtor(new [] { typeof(string) }, DefaultBindingFlags);
52-
Assert.AreEqual(1, ctor.GetParameters().Length);
53-
}
48+
[TestMethod]
49+
public void It_will_select_if_an_argument_is_sealed_and_supplied()
50+
{
51+
var ctor = typeof(WithSealedParameter).SelectCtor(new[] { typeof(string) }, DefaultBindingFlags);
52+
Assert.AreEqual(1, ctor.GetParameters().Length);
53+
}
5454

55-
[TestMethod]
56-
public void It_will_select_a_private_ctor_when_specified()
57-
{
58-
const BindingFlags privateBindingFlags = DefaultBindingFlags | BindingFlags.NonPublic;
59-
var ctor = typeof(WithPrivateConstructor).SelectCtor(Array.Empty<Type>(), privateBindingFlags);
60-
Assert.AreEqual(2, ctor.GetParameters().Length);
61-
}
55+
[TestMethod]
56+
public void It_will_select_a_private_ctor_when_specified()
57+
{
58+
const BindingFlags privateBindingFlags = DefaultBindingFlags | BindingFlags.NonPublic;
59+
var ctor = typeof(WithPrivateConstructor).SelectCtor(Array.Empty<Type>(), privateBindingFlags);
60+
Assert.AreEqual(2, ctor.GetParameters().Length);
61+
}
6262

63-
[TestMethod]
64-
public void It_will_always_allow_empty_private_constructor()
65-
{
66-
var ctor = typeof(ProtectedConstructor).SelectCtor(Array.Empty<Type>(), DefaultBindingFlags);
67-
Assert.AreEqual(0, ctor.GetParameters().Length);
68-
}
63+
[TestMethod]
64+
public void It_will_always_allow_empty_private_constructor()
65+
{
66+
var ctor = typeof(ProtectedConstructor).SelectCtor(Array.Empty<Type>(), DefaultBindingFlags);
67+
Assert.AreEqual(0, ctor.GetParameters().Length);
6968
}
7069
}

0 commit comments

Comments
 (0)