Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 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
15 changes: 12 additions & 3 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ defaults:

jobs:
build:
runs-on: windows-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.100
dotnet-version: 6.0.202

# Run unit tests
- name: Test
Expand All @@ -53,7 +53,16 @@ jobs:
}

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'
Expand Down
5 changes: 3 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<Project>

<PropertyGroup>
<PropertyGroup>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnforceCodeStyleInBuild Condition=" '$(BuildingForLiveUnitTesting)' == '' ">true</EnforceCodeStyleInBuild>
<TreatWarningsAsErrors Condition=" '$(BuildingForLiveUnitTesting)' == '' ">true</TreatWarningsAsErrors>
</PropertyGroup>
</PropertyGroup>

</Project>
7 changes: 7 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>

<ItemGroup>
<Using Remove="System.Net.Http" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Moq.AutoMock.Generator.Example.MSTest;

[TestClass]
[ConstructorTests(TargetType = typeof(Controller))]
public partial class ControllerTests
{
partial void ControllerConstructor_WithNullIService3_ThrowsArgumentNullExceptionSetup(AutoMocker mocker)
{
mocker.Use<string>("");
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.9" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.9" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Moq.AutoMocker.TestGenerator\Moq.AutoMocker.TestGenerator.csproj">
<OutputItemType>Analyzer</OutputItemType>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>

<ProjectReference Include="..\Moq.AutoMocker.Generator.Example\Moq.AutoMock.Generator.Example.csproj" />
<ProjectReference Include="..\..\Moq.AutoMock\Moq.AutoMock.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Moq.AutoMock.Generator.Example.NUnit;

[ConstructorTests(TargetType = typeof(Controller))]
public partial class ControllerTests
{
partial void AutoMockerTestSetup(Moq.AutoMock.AutoMocker mocker, string testName)
{
mocker.Use<string>("");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Moq.AutoMocker.TestGenerator\Moq.AutoMocker.TestGenerator.csproj">
<OutputItemType>Analyzer</OutputItemType>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\Moq.AutoMocker.Generator.Example\Moq.AutoMock.Generator.Example.csproj" />
<ProjectReference Include="..\..\Moq.AutoMock\Moq.AutoMock.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Moq.AutoMock.Generator.Example.xUnit;

[ConstructorTests(TargetType = typeof(Controller))]
public partial class ControllerTests
{
partial void AutoMockerTestSetup(Moq.AutoMock.AutoMocker mocker, string testName)
{
mocker.Use<string>("");
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<!--<ItemGroup>
<PackageReference Include="Moq.AutoMock" Version="3.3.0-ci0233" />
</ItemGroup>-->

<ItemGroup>
<ProjectReference Include="..\..\Moq.AutoMocker.TestGenerator\Moq.AutoMocker.TestGenerator.csproj">
<OutputItemType>Analyzer</OutputItemType>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\Moq.AutoMock\Moq.AutoMock.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Moq.AutoMocker.Generator.Example\Moq.AutoMock.Generator.Example.csproj" />
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions GeneratorTests/Moq.AutoMocker.Generator.Example/Controller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Moq.AutoMock.Generator.Example;

public class Controller
{
public Controller(IService service)
{
_ = service ?? throw new ArgumentNullException(nameof(service));
}

public Controller(IService service1, IService service2)
{
_ = service1 ?? throw new ArgumentNullException(nameof(service1));
_ = service2 ?? throw new ArgumentNullException(nameof(service2));
}

public Controller(IService service, string name)
{
_ = service ?? throw new ArgumentNullException(nameof(service));
Name = name ?? throw new ArgumentNullException(nameof(name));
}

public string Name { get; } = "";
}
6 changes: 6 additions & 0 deletions GeneratorTests/Moq.AutoMocker.Generator.Example/IService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Moq.AutoMock.Generator.Example;

public interface IService
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

</Project>
4 changes: 2 additions & 2 deletions Moq.AutoMock.Tests/Moq.AutoMock.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<ItemGroup>
<PackageReference Include="Moq" version="4.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.9" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.9" />
<ProjectReference Include="..\Moq.AutoMock\Moq.AutoMock.csproj" />
</ItemGroup>
</Project>
45 changes: 45 additions & 0 deletions Moq.AutoMock.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,28 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
.github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml
LICENSE.md = LICENSE.md
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Generators", "Generators\Generators.csproj", "{98CADDA9-5D66-405A-8A59-90636A242869}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GeneratorTests", "GeneratorTests", "{1D10BDDE-2E03-42E4-AA7A-B12AF01E7FE8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.AutoMock.Generator.Example", "GeneratorTests\Moq.AutoMocker.Generator.Example\Moq.AutoMock.Generator.Example.csproj", "{F142399A-FAB8-4097-BC7B-0266200FA14D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.AutoMock.Generator.Example.MSTest", "GeneratorTests\Moq.AutoMock.Generator.Example.MSTest\Moq.AutoMock.Generator.Example.MSTest.csproj", "{BAFB5236-9C52-48D2-8CD5-E214652F38D3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.AutoMock.Generator.Example.NUnit", "GeneratorTests\Moq.AutoMock.Generator.Example.NUnit\Moq.AutoMock.Generator.Example.NUnit.csproj", "{0E545A4D-809E-47CA-AC16-5CB80CD231F6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.AutoMock.Generator.Example.xUnit", "GeneratorTests\Moq.AutoMock.Generator.Example.xUnit\Moq.AutoMock.Generator.Example.xUnit.csproj", "{586D1D6A-3EE2-4AB8-988A-CEB810EF7787}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.AutoMocker.TestGenerator", "Moq.AutoMocker.TestGenerator\Moq.AutoMocker.TestGenerator.csproj", "{710AF8FE-BB9E-4FE9-ABF7-0CE8BD212BB4}"
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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,10 +51,40 @@ Global
{98CADDA9-5D66-405A-8A59-90636A242869}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98CADDA9-5D66-405A-8A59-90636A242869}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98CADDA9-5D66-405A-8A59-90636A242869}.Release|Any CPU.Build.0 = Release|Any CPU
{F142399A-FAB8-4097-BC7B-0266200FA14D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F142399A-FAB8-4097-BC7B-0266200FA14D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F142399A-FAB8-4097-BC7B-0266200FA14D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F142399A-FAB8-4097-BC7B-0266200FA14D}.Release|Any CPU.Build.0 = Release|Any CPU
{BAFB5236-9C52-48D2-8CD5-E214652F38D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAFB5236-9C52-48D2-8CD5-E214652F38D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAFB5236-9C52-48D2-8CD5-E214652F38D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAFB5236-9C52-48D2-8CD5-E214652F38D3}.Release|Any CPU.Build.0 = Release|Any CPU
{0E545A4D-809E-47CA-AC16-5CB80CD231F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E545A4D-809E-47CA-AC16-5CB80CD231F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E545A4D-809E-47CA-AC16-5CB80CD231F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E545A4D-809E-47CA-AC16-5CB80CD231F6}.Release|Any CPU.Build.0 = Release|Any CPU
{586D1D6A-3EE2-4AB8-988A-CEB810EF7787}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{586D1D6A-3EE2-4AB8-988A-CEB810EF7787}.Debug|Any CPU.Build.0 = Debug|Any CPU
{586D1D6A-3EE2-4AB8-988A-CEB810EF7787}.Release|Any CPU.ActiveCfg = Release|Any CPU
{586D1D6A-3EE2-4AB8-988A-CEB810EF7787}.Release|Any CPU.Build.0 = Release|Any CPU
{710AF8FE-BB9E-4FE9-ABF7-0CE8BD212BB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{710AF8FE-BB9E-4FE9-ABF7-0CE8BD212BB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{710AF8FE-BB9E-4FE9-ABF7-0CE8BD212BB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{710AF8FE-BB9E-4FE9-ABF7-0CE8BD212BB4}.Release|Any CPU.Build.0 = Release|Any CPU
{F3663663-0123-4DA3-9BDD-95C91AFA4596}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F3663663-0123-4DA3-9BDD-95C91AFA4596}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F3663663-0123-4DA3-9BDD-95C91AFA4596}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F3663663-0123-4DA3-9BDD-95C91AFA4596}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F142399A-FAB8-4097-BC7B-0266200FA14D} = {1D10BDDE-2E03-42E4-AA7A-B12AF01E7FE8}
{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}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1A499C6A-1AB1-4A04-A133-BBCF4759DACA}
EndGlobalSection
Expand Down
3 changes: 1 addition & 2 deletions Moq.AutoMock/AutoMocker.Verify.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq.Expressions;
using System.Linq.Expressions;

namespace Moq.AutoMock;

Expand Down
17 changes: 7 additions & 10 deletions Moq.AutoMock/AutoMocker.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.ExceptionServices;
Expand Down Expand Up @@ -262,10 +259,10 @@ public T CreateSelfMock<T>(bool enablePrivate) where T : class?
/// <param name="callBase">Sets the CallBase property on the created Mock.</param>
/// <returns>An instance with virtual and abstract members mocked</returns>
public T CreateSelfMock<T>(
bool enablePrivate = false,
MockBehavior? mockBehavior = null,
DefaultValue? defaultValue = null,
bool? callBase = null)
bool enablePrivate = false,
MockBehavior? mockBehavior = null,
DefaultValue? defaultValue = null,
bool? callBase = null)
where T : class?
{
return BuildSelfMock<T>(enablePrivate, mockBehavior ?? MockBehavior, defaultValue ?? DefaultValue, callBase ?? CallBase).Object;
Expand All @@ -284,13 +281,13 @@ public T CreateSelfMock<T>(
/// <returns>An instance with virtual and abstract members mocked</returns>
public TImplementation WithSelfMock<TService, TImplementation>(
bool enablePrivate = false,
MockBehavior? mockBehavior = null,
MockBehavior? mockBehavior = null,
DefaultValue? defaultValue = null,
bool? callBase = null)
where TImplementation : class, TService
where TService : class
{
Mock<TImplementation> selfMock = BuildSelfMock<TImplementation>(enablePrivate,
Mock<TImplementation> selfMock = BuildSelfMock<TImplementation>(enablePrivate,
mockBehavior ?? MockBehavior,
defaultValue ?? DefaultValue,
callBase ?? CallBase);
Expand Down Expand Up @@ -391,7 +388,7 @@ public object WithSelfMock(
}


private Mock<T> BuildSelfMock<T>(bool enablePrivate, MockBehavior mockBehavior, DefaultValue defaultValue, bool callBase)
private Mock<T> BuildSelfMock<T>(bool enablePrivate, MockBehavior mockBehavior, DefaultValue defaultValue, bool callBase)
where T : class?
{
var context = new ObjectGraphContext(enablePrivate);
Expand Down
3 changes: 1 addition & 2 deletions Moq.AutoMock/CastChecker.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq.Expressions;
using System.Linq.Expressions;

namespace Moq.AutoMock;

Expand Down
3 changes: 0 additions & 3 deletions Moq.AutoMock/ConstructorSelector.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Moq.AutoMock.Extensions;

Expand Down
Loading