diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..e596706f --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,16 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "nuget" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + + - package-ecosystem: "github-actions" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 2a1d760d..f503c797 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -1,102 +1,101 @@ -name: Continuous - -on: - # PRs will be built, and a package posted to GH Packages - pull_request: - - push: - paths-ignore: - - 'README.md' - - 'docs/**' - - # We'll build, pack, and push a pre-release to NuGet on master - branches: [ master ] - - # Tagging with v* will build that version number and push a release to Nuget - # e.g. v1.2, v3.4.5, etc. - tags: - - 'v*' - -defaults: - run: - shell: pwsh - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 6.0.202 - - # Run unit tests - - name: Test - run: dotnet test --configuration Release --verbosity normal - - # Package Release - - name: Pack - run: | - <# If we're a tag, force VersionPrefix to the tag value #> - if ('${{ github.ref }}' -match '^refs/tags/v') { - $match = [regex]::Match('${{ github.ref }}', '^refs/tags/v([0-9]+(\.[0-9]+){1,2})') - if ($match.Success) { - $env:VersionPrefix = $match.Groups[1].Value - } else { - throw 'Invalid tag version: ${{ github.ref }}' - } - } - else { - <# All other pushes get a CI suffix #> - $env:VersionSuffix = 'ci{0:0000}' -f ${{ github.run_number }} - } - - dotnet pack --configuration Release --verbosity normal --output . - - - name: Upload NuGet - uses: actions/upload-artifact@v3 - with: - name: NuGet - if-no-files-found: error - path: | - **/*.nupkg - **/*.snupkg - - # Update the docs - - name: Update Docs - if: github.event_name == 'push' - run: | - dotnet tool install xmldocmd - dotnet tool run xmldocmd .\Moq.AutoMock\bin\Release\net461\Moq.AutoMock.dll .\docs - - $modified = $(git status -u --porcelain) - if ($modified.Where({$_.Contains(" docs/")}, 'First').Count -lt 1) { - return 0 - } - - # Create docs pull request - - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 - if: github.event_name == 'push' - with: - commit-message: | - [Docs update detected by Github Action]. - Auto generated pull request. - branch: docs/automated-update - delete-branch: true - base: master - title: Update Docs [GitHub Action] - body: | - [Docs update detected by Github Action]. - Auto generated pull request. - - # Publish to NuGet and GitHub Packages - - name: Publish - if: github.event_name == 'push' - run: | - dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_TOKEN }} --skip-duplicate - dotnet nuget push *.nupkg ` - --source 'https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json' ` - --api-key '${{ github.token }}' ` - --skip-duplicate +name: Continuous + +on: + # PRs will be built, and a package posted to GH Packages + pull_request: + + push: + paths-ignore: + - 'README.md' + - 'docs/**' + + # We'll build, pack, and push a pre-release to NuGet on master + branches: [ master ] + + # Tagging with v* will build that version number and push a release to Nuget + # e.g. v1.2, v3.4.5, etc. + tags: + - 'v*' + +defaults: + run: + shell: pwsh + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + + # Run unit tests + - name: Test + run: dotnet test --configuration Release --verbosity normal + + # Package Release + - name: Pack + run: | + <# If we're a tag, force VersionPrefix to the tag value #> + if ('${{ github.ref }}' -match '^refs/tags/v') { + $match = [regex]::Match('${{ github.ref }}', '^refs/tags/v([0-9]+(\.[0-9]+){1,2})') + if ($match.Success) { + $env:VersionPrefix = $match.Groups[1].Value + } else { + throw 'Invalid tag version: ${{ github.ref }}' + } + } + else { + <# All other pushes get a CI suffix #> + $env:VersionSuffix = 'ci{0:0000}' -f ${{ github.run_number }} + } + + dotnet pack --configuration Release --verbosity normal --output . + + - name: Upload NuGet + uses: actions/upload-artifact@v3 + with: + name: NuGet + if-no-files-found: error + path: | + **/*.nupkg + **/*.snupkg + + # Update the docs + - name: Update Docs + if: github.event_name == 'push' + run: | + dotnet tool install xmldocmd + dotnet tool run xmldocmd .\Moq.AutoMock\bin\Release\net461\Moq.AutoMock.dll .\docs + + $modified = $(git status -u --porcelain) + if ($modified.Where({$_.Contains(" docs/")}, 'First').Count -lt 1) { + return 0 + } + + # Create docs pull request + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + if: github.event_name == 'push' + with: + commit-message: | + [Docs update detected by Github Action]. + Auto generated pull request. + branch: docs/automated-update + delete-branch: true + base: master + title: Update Docs [GitHub Action] + body: | + [Docs update detected by Github Action]. + Auto generated pull request. + + # Publish to NuGet and GitHub Packages + - name: Publish + if: github.event_name == 'push' + run: | + dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_TOKEN }} --skip-duplicate + dotnet nuget push *.nupkg ` + --source 'https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json' ` + --api-key '${{ github.token }}' ` + --skip-duplicate diff --git a/GeneratorTests/Moq.AutoMock.Generator.Example.MSTest/Moq.AutoMock.Generator.Example.MSTest.csproj b/GeneratorTests/Moq.AutoMock.Generator.Example.MSTest/Moq.AutoMock.Generator.Example.MSTest.csproj index ee601859..96616f16 100644 --- a/GeneratorTests/Moq.AutoMock.Generator.Example.MSTest/Moq.AutoMock.Generator.Example.MSTest.csproj +++ b/GeneratorTests/Moq.AutoMock.Generator.Example.MSTest/Moq.AutoMock.Generator.Example.MSTest.csproj @@ -1,31 +1,31 @@ - - - - net6.0 - enable - - false - true - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - Analyzer - false - - - - - - - + + + + net6.0 + enable + + false + true + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + Analyzer + false + + + + + + + diff --git a/GeneratorTests/Moq.AutoMock.Generator.Example.NUnit/Moq.AutoMock.Generator.Example.NUnit.csproj b/GeneratorTests/Moq.AutoMock.Generator.Example.NUnit/Moq.AutoMock.Generator.Example.NUnit.csproj index 7f080ee3..3e849961 100644 --- a/GeneratorTests/Moq.AutoMock.Generator.Example.NUnit/Moq.AutoMock.Generator.Example.NUnit.csproj +++ b/GeneratorTests/Moq.AutoMock.Generator.Example.NUnit/Moq.AutoMock.Generator.Example.NUnit.csproj @@ -1,30 +1,30 @@ - - - - net6.0 - enable - - false - true - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - Analyzer - false - - - - - - + + + + net6.0 + enable + + false + true + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + Analyzer + false + + + + + + diff --git a/GeneratorTests/Moq.AutoMock.Generator.Example.xUnit/Moq.AutoMock.Generator.Example.xUnit.csproj b/GeneratorTests/Moq.AutoMock.Generator.Example.xUnit/Moq.AutoMock.Generator.Example.xUnit.csproj index b1dc24a8..4c1c8d6a 100644 --- a/GeneratorTests/Moq.AutoMock.Generator.Example.xUnit/Moq.AutoMock.Generator.Example.xUnit.csproj +++ b/GeneratorTests/Moq.AutoMock.Generator.Example.xUnit/Moq.AutoMock.Generator.Example.xUnit.csproj @@ -1,40 +1,40 @@ - - - - net6.0 - enable - - false - true - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - Analyzer - false - - - - - - - - - + + + + net6.0 + enable + + false + true + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + Analyzer + false + + + + + + + + + diff --git a/Generators/Generators.csproj b/Generators/Generators.csproj index 8b9ccd82..bd4c1eb1 100644 --- a/Generators/Generators.csproj +++ b/Generators/Generators.csproj @@ -1,12 +1,12 @@ - - - - netstandard2.0 - false - - - - - - - + + + + netstandard2.0 + false + + + + + + + diff --git a/Moq.AutoMock.Tests/DescribeGetMock.cs b/Moq.AutoMock.Tests/DescribeGetMock.cs index f62ad9d0..3dcb5550 100644 --- a/Moq.AutoMock.Tests/DescribeGetMock.cs +++ b/Moq.AutoMock.Tests/DescribeGetMock.cs @@ -1,85 +1,85 @@ -using System; -using Castle.DynamicProxy; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq.AutoMock.Tests.Util; - -namespace Moq.AutoMock.Tests; - -[TestClass] -public class DescribeGetMock -{ - [TestMethod] - public void It_creates_mock_from_interface_from_generic_type_parameter() - { - var mocker = new AutoMocker(); - Mock mock = mocker.GetMock(); - Assert.IsNotNull(mock); - } - - [TestMethod] - public void It_creates_mock_from_interface_from_type_parameter() - { - var mocker = new AutoMocker(); - Mock? mock = mocker.GetMock(typeof(IService1)) as Mock; - Assert.IsNotNull(mock); - } - - [TestMethod] - public void It_creates_mock_from_class_from_generic_type_parameter() - { - var mocker = new AutoMocker(); - Mock? mock = mocker.GetMock(); - Assert.IsNotNull(mock); - } - - [TestMethod] - public void It_creates_mock_from_class_from_type_parameter() - { - var mocker = new AutoMocker(); - Mock? mock = mocker.GetMock(typeof(Empty)) as Mock; - Assert.IsNotNull(mock); - } - - [TestMethod] - public void It_allows_protected_abstract_mock_when_overriden() - { - var mocker = new AutoMocker(); - var mock = mocker.GetMock(enablePrivate: true); - Assert.IsNotNull(mock); - Assert.IsInstanceOfType(mock.Object, typeof(ProtectedConstructor1)); - } - - [TestMethod] - public void It_gets_mocked_object_with_protected_ctor() - { - var mocker = new AutoMocker(); - var mock = mocker.GetMock(); - Assert.ThrowsException(() => mock.Object); - } - - [TestMethod] - public void It_allows_getting_mocked_object_when_overriden() - { - var mocker = new AutoMocker(); - var @protected = mocker.Get(enablePrivate: true); - Assert.IsNotNull(@protected); - Assert.IsInstanceOfType(@protected, typeof(ProtectedConstructor1)); - } - - [TestMethod] - public void It_gets_mocked_object_via_iserviceprovider() - { - IServiceProvider mocker = new AutoMocker(); - var service = mocker.GetService(typeof(Empty)); - Assert.IsNotNull(service); - Assert.IsInstanceOfType(service, typeof(Empty)); - } - - [TestMethod] - public void It_returns_null_for_unmockable_object_via_iserviceprovider() - { - IServiceProvider mocker = new AutoMocker(); - var service = mocker.GetService(typeof(string)); - Assert.IsNull(service); - } -} +using System; +using Castle.DynamicProxy; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq.AutoMock.Tests.Util; + +namespace Moq.AutoMock.Tests; + +[TestClass] +public class DescribeGetMock +{ + [TestMethod] + public void It_creates_mock_from_interface_from_generic_type_parameter() + { + var mocker = new AutoMocker(); + Mock mock = mocker.GetMock(); + Assert.IsNotNull(mock); + } + + [TestMethod] + public void It_creates_mock_from_interface_from_type_parameter() + { + var mocker = new AutoMocker(); + Mock? mock = mocker.GetMock(typeof(IService1)) as Mock; + Assert.IsNotNull(mock); + } + + [TestMethod] + public void It_creates_mock_from_class_from_generic_type_parameter() + { + var mocker = new AutoMocker(); + Mock? mock = mocker.GetMock(); + Assert.IsNotNull(mock); + } + + [TestMethod] + public void It_creates_mock_from_class_from_type_parameter() + { + var mocker = new AutoMocker(); + Mock? mock = mocker.GetMock(typeof(Empty)) as Mock; + Assert.IsNotNull(mock); + } + + [TestMethod] + public void It_allows_protected_abstract_mock_when_overriden() + { + var mocker = new AutoMocker(); + var mock = mocker.GetMock(enablePrivate: true); + Assert.IsNotNull(mock); + Assert.IsInstanceOfType(mock.Object, typeof(ProtectedConstructor1)); + } + + [TestMethod] + public void It_gets_mocked_object_with_protected_ctor() + { + var mocker = new AutoMocker(); + var mock = mocker.GetMock(); + Assert.ThrowsException(() => mock.Object); + } + + [TestMethod] + public void It_allows_getting_mocked_object_when_overriden() + { + var mocker = new AutoMocker(); + var @protected = mocker.Get(enablePrivate: true); + Assert.IsNotNull(@protected); + Assert.IsInstanceOfType(@protected, typeof(ProtectedConstructor1)); + } + + [TestMethod] + public void It_gets_mocked_object_via_iserviceprovider() + { + IServiceProvider mocker = new AutoMocker(); + var service = mocker.GetService(typeof(Empty)); + Assert.IsNotNull(service); + Assert.IsInstanceOfType(service, typeof(Empty)); + } + + [TestMethod] + public void It_returns_null_for_unmockable_object_via_iserviceprovider() + { + IServiceProvider mocker = new AutoMocker(); + var service = mocker.GetService(typeof(string)); + Assert.IsNull(service); + } +} diff --git a/Moq.AutoMock.Tests/Moq.AutoMock.Tests.csproj b/Moq.AutoMock.Tests/Moq.AutoMock.Tests.csproj index a5a1543b..25815b6e 100644 --- a/Moq.AutoMock.Tests/Moq.AutoMock.Tests.csproj +++ b/Moq.AutoMock.Tests/Moq.AutoMock.Tests.csproj @@ -27,10 +27,10 @@ - - - - + + + + \ No newline at end of file diff --git a/Moq.AutoMock.sln b/Moq.AutoMock.sln index 3216af2e..05040c19 100644 --- a/Moq.AutoMock.sln +++ b/Moq.AutoMock.sln @@ -12,7 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .editorconfig = .editorconfig Directory.Build.props = Directory.Build.props Directory.Build.targets = Directory.Build.targets - .github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml + global.json = global.json LICENSE.md = LICENSE.md README.md = README.md EndProjectSection @@ -33,6 +33,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.AutoMocker.TestGenerato EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.AutoMocker.TestGenerator.Tests", "Moq.AutoMocker.TestGenerator.Tests\Moq.AutoMocker.TestGenerator.Tests.csproj", "{F3663663-0123-4DA3-9BDD-95C91AFA4596}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{820CF7FE-8E92-4500-BE62-55AF67007838}" + ProjectSection(SolutionItems) = preProject + .github\dependabot.yml = .github\dependabot.yml + .github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -84,6 +90,7 @@ Global {BAFB5236-9C52-48D2-8CD5-E214652F38D3} = {1D10BDDE-2E03-42E4-AA7A-B12AF01E7FE8} {0E545A4D-809E-47CA-AC16-5CB80CD231F6} = {1D10BDDE-2E03-42E4-AA7A-B12AF01E7FE8} {586D1D6A-3EE2-4AB8-988A-CEB810EF7787} = {1D10BDDE-2E03-42E4-AA7A-B12AF01E7FE8} + {820CF7FE-8E92-4500-BE62-55AF67007838} = {5698188E-884A-49D3-A74B-FF98C782BF15} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1A499C6A-1AB1-4A04-A133-BBCF4759DACA} diff --git a/Moq.AutoMock/Moq.AutoMock.csproj b/Moq.AutoMock/Moq.AutoMock.csproj index 673a7239..41d237f5 100644 --- a/Moq.AutoMock/Moq.AutoMock.csproj +++ b/Moq.AutoMock/Moq.AutoMock.csproj @@ -32,7 +32,7 @@ all - + Analyzer false diff --git a/Moq.AutoMocker.TestGenerator.Tests/Moq.AutoMocker.TestGenerator.Tests.csproj b/Moq.AutoMocker.TestGenerator.Tests/Moq.AutoMocker.TestGenerator.Tests.csproj index 7967cf31..726d3cd5 100644 --- a/Moq.AutoMocker.TestGenerator.Tests/Moq.AutoMocker.TestGenerator.Tests.csproj +++ b/Moq.AutoMocker.TestGenerator.Tests/Moq.AutoMocker.TestGenerator.Tests.csproj @@ -1,24 +1,24 @@ - - - - net6.0 - - false - true - true - - - - - - - - - - - - - - - - + + + + net6.0 + + false + true + true + + + + + + + + + + + + + + + + diff --git a/Moq.AutoMocker.TestGenerator/Moq.AutoMocker.TestGenerator.csproj b/Moq.AutoMocker.TestGenerator/Moq.AutoMocker.TestGenerator.csproj index 03ddeb65..4c64cd73 100644 --- a/Moq.AutoMocker.TestGenerator/Moq.AutoMocker.TestGenerator.csproj +++ b/Moq.AutoMocker.TestGenerator/Moq.AutoMocker.TestGenerator.csproj @@ -1,16 +1,16 @@ - - - - netstandard2.0 - false - - - - - - - - - - - + + + + netstandard2.0 + false + + + + + + + + + + + diff --git a/global.json b/global.json index 39d9f670..a071fad8 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ -{ - "sdk": { - "version": "5.0.100", - "rollForward": "latestMajor" - } +{ + "sdk": { + "version": "6.0.400", + "rollForward": "latestMinor" + } } \ No newline at end of file