From c259f2af1bf20c3bb4e62bbc4edf571ff656090f Mon Sep 17 00:00:00 2001 From: Kevin B Date: Sun, 14 Jan 2024 07:40:10 -0800 Subject: [PATCH 1/6] Adding test for primary constructors --- Moq.AutoMock.Tests/DescribeCreateInstance.cs | 10 ++++++++++ Moq.AutoMock.Tests/Util/PrimaryConstructor.cs | 9 +++++++++ 2 files changed, 19 insertions(+) create mode 100644 Moq.AutoMock.Tests/Util/PrimaryConstructor.cs diff --git a/Moq.AutoMock.Tests/DescribeCreateInstance.cs b/Moq.AutoMock.Tests/DescribeCreateInstance.cs index 1d377f40..143e4884 100644 --- a/Moq.AutoMock.Tests/DescribeCreateInstance.cs +++ b/Moq.AutoMock.Tests/DescribeCreateInstance.cs @@ -226,6 +226,16 @@ public void It_can_create_instances_of_nested_sealed_classes() Assert.AreEqual(mockWithSealedService.SealedService, mockWithSealedService.NestedSealedService.SealedService); } + [TestMethod] + public void It_can_create_instance_of_class_with_primary_constructor() + { + AutoMocker mocker = new(); + + PrimaryConstructor instance = mocker.CreateInstance(); + + Assert.IsInstanceOfType(instance.Service, typeof(Service1)); + } + private class CustomStringResolver : IMockResolver { public CustomStringResolver(string stringValue) diff --git a/Moq.AutoMock.Tests/Util/PrimaryConstructor.cs b/Moq.AutoMock.Tests/Util/PrimaryConstructor.cs new file mode 100644 index 00000000..f984b059 --- /dev/null +++ b/Moq.AutoMock.Tests/Util/PrimaryConstructor.cs @@ -0,0 +1,9 @@ +using System.Diagnostics.CodeAnalysis; + +namespace Moq.AutoMock.Tests.Util; + +[ExcludeFromCodeCoverage] +public class WithService(IService1 service) +{ + public IService1 Service { get; set; } = service; +} \ No newline at end of file From 675ab020a74bb32dff2a578c246faa545ffb5bb7 Mon Sep 17 00:00:00 2001 From: Kevin B Date: Sun, 14 Jan 2024 07:43:56 -0800 Subject: [PATCH 2/6] Adding workflow dispatch CI trigger --- .github/workflows/dotnetcore.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 91f1d8d3..808fb56e 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -4,6 +4,8 @@ on: # PRs will be built, and a package posted to GH Packages pull_request: + workflow_dispatch: + push: paths-ignore: - 'README.md' From d432fbd3cad5781b89a05a0b6fb60cf050b97215 Mon Sep 17 00:00:00 2001 From: Kevin B Date: Sun, 14 Jan 2024 07:55:46 -0800 Subject: [PATCH 3/6] Bump lang version --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 82dc6821..66820c8f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 10.0 + 12.0 enable enable true From 65afff576cf3acdcd6eb857d2e3c73c4eb1fca90 Mon Sep 17 00:00:00 2001 From: Kevin B Date: Sun, 14 Jan 2024 08:01:57 -0800 Subject: [PATCH 4/6] Bumping SDK in global.json --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index a071fad8..bc54e196 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "6.0.400", + "version": "8.0.100", "rollForward": "latestMinor" } } \ No newline at end of file From 1d67637611ffe92ac8e5293da3dd95ad8ba7db84 Mon Sep 17 00:00:00 2001 From: Kevin B Date: Sun, 14 Jan 2024 08:06:03 -0800 Subject: [PATCH 5/6] Split up restore/build/test --- .github/workflows/dotnetcore.yml | 9 +++++++-- Moq.AutoMock.Tests/Util/PrimaryConstructor.cs | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 808fb56e..b22860c3 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -32,9 +32,14 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v4 - # Run unit tests + - name: NuGet restore + run: dotnet restore + + - name: Build + run: dotnet build --configuration Release --no-restore + - name: Test - run: dotnet test --configuration Release --verbosity normal + run: dotnet test --configuration Release --no-build --verbosity normal # Package Release - name: Pack diff --git a/Moq.AutoMock.Tests/Util/PrimaryConstructor.cs b/Moq.AutoMock.Tests/Util/PrimaryConstructor.cs index f984b059..27cdb041 100644 --- a/Moq.AutoMock.Tests/Util/PrimaryConstructor.cs +++ b/Moq.AutoMock.Tests/Util/PrimaryConstructor.cs @@ -3,7 +3,7 @@ namespace Moq.AutoMock.Tests.Util; [ExcludeFromCodeCoverage] -public class WithService(IService1 service) +public class PrimaryConstructor(IService1 service) { public IService1 Service { get; set; } = service; } \ No newline at end of file From 02b9d82c4dfb02f8b05ff9b885bee64e095b0f22 Mon Sep 17 00:00:00 2001 From: Kevin B Date: Sun, 14 Jan 2024 08:08:08 -0800 Subject: [PATCH 6/6] Fixing type name --- Moq.AutoMock.Tests/DescribeCreateInstance.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moq.AutoMock.Tests/DescribeCreateInstance.cs b/Moq.AutoMock.Tests/DescribeCreateInstance.cs index 143e4884..a31f135b 100644 --- a/Moq.AutoMock.Tests/DescribeCreateInstance.cs +++ b/Moq.AutoMock.Tests/DescribeCreateInstance.cs @@ -233,7 +233,7 @@ public void It_can_create_instance_of_class_with_primary_constructor() PrimaryConstructor instance = mocker.CreateInstance(); - Assert.IsInstanceOfType(instance.Service, typeof(Service1)); + Assert.IsInstanceOfType(instance.Service, typeof(IService1)); } private class CustomStringResolver : IMockResolver