Skip to content

Commit

Permalink
Merge dev into main (#25)
Browse files Browse the repository at this point in the history
* adds support for .net 9

* fixes bug with post build event not being able to handle spaces in the assembly path
---------

Co-authored-by: Douglas Gaskell <[email protected]>
  • Loading branch information
connorivy and douglasg14b authored Jan 4, 2025
1 parent 42e9050 commit 46debcd
Show file tree
Hide file tree
Showing 23 changed files with 125 additions and 63 deletions.
23 changes: 15 additions & 8 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
submodules: true

- name: Setup .NET 9
uses: actions/setup-dotnet@v3
with:
dotnet-version: '9.0.x'

- name: Build harmony
run: |
dotnet build ./Harmony/Harmony/Harmony.csproj -c ReleaseThin
- name: Test And Collect CodeCov
run: |
dotnet tool install --global dotnet-coverage
export PATH="$PATH:/root/.dotnet/tools"
dotnet-coverage collect "dotnet run --project ./tests/MockMe.Tests.Runner/" -f cobertura -s ./CodeCoverage.runsettings
- name: Generate report
Expand All @@ -28,7 +35,6 @@ jobs:
reports: './output.cobertura.xml'
targetdir: './tests/TestResults'
reporttypes: 'lcov'
# reporttypes: 'html'

- name: Coveralls
uses: coverallsapp/github-action@master
Expand Down Expand Up @@ -76,17 +82,18 @@ jobs:
- name: Create local package feed
run: dotnet nuget add source ${{ github.workspace }}/packages --name localNuGet

- name: Print NuGet Sources
run: dotnet nuget list source

- name: Restore dependencies
run: dotnet restore /p:MockMeNugetPackageVersion="0.0.1-dev"
- name: Clean previous build artifacts
run: |
find . -type d -name 'bin' -exec rm -rf {} +
find . -type d -name 'obj' -exec rm -rf {} +
# stack overflow thread for why I'm using maxcpucount
# https://stackoverflow.com/questions/72267139/msbuild-error-msb4018-cannot-access-project-assets-json-in-net-5-build
- name: Build
run: dotnet build ./tests/MockMe.Tests.slnf --no-restore -c Release /p:MockMeNugetPackageVersion="0.0.1-dev"
run: dotnet build ./tests/MockMe.Tests.slnf -c Release /p:MockMeNugetPackageVersion="0.0.1-dev" /p:MockMeTestsTargetFramework=net${{ matrix.dotnet }} -f net${{ matrix.dotnet }} -maxcpucount:1

- name: Test
run: dotnet test ./tests/MockMe.Tests.slnf --no-build -c Release --verbosity normal
run: dotnet test ./tests/MockMe.Tests.slnf --no-build -c Release --verbosity normal /p:MockMeTestsTargetFramework=net${{ matrix.dotnet }} -f net${{ matrix.dotnet }}

# test-windows:
# runs-on: windows-latest
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Harmony"]
path = Harmony
url = https://github.com/connorivy/Harmony
2 changes: 2 additions & 0 deletions CodeCoverage.runsettings
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<ModulePaths>
<Exclude>
<ModulePath>.MockMe.Tests.ExampleClasses.dll$</ModulePath>
<ModulePath>.0Harmony.dll$</ModulePath>
<ModulePath>.MockMe.Generator.dll$</ModulePath>
<!--<ModulePath>.*Tests.*</ModulePath>-->
</Exclude>
</ModulePaths>
Expand Down
1 change: 1 addition & 0 deletions Harmony
Submodule Harmony added at 4e3488
7 changes: 7 additions & 0 deletions MockMe.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MockMe.Tests.Overloads.Virt
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MockMe.Tests.Runner", "tests\MockMe.Tests.Runner\MockMe.Tests.Runner.csproj", "{71009957-1245-48AD-BE28-7377CF50DA6B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MockMe Tests With Path Spaces", "tests\MockMe Tests With Path Spaces\MockMe Tests With Path Spaces.csproj", "{21B57A75-EE1A-D96F-57EF-82EAF1A767EE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -98,6 +100,10 @@ Global
{71009957-1245-48AD-BE28-7377CF50DA6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71009957-1245-48AD-BE28-7377CF50DA6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71009957-1245-48AD-BE28-7377CF50DA6B}.Release|Any CPU.Build.0 = Release|Any CPU
{21B57A75-EE1A-D96F-57EF-82EAF1A767EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{21B57A75-EE1A-D96F-57EF-82EAF1A767EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{21B57A75-EE1A-D96F-57EF-82EAF1A767EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21B57A75-EE1A-D96F-57EF-82EAF1A767EE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -114,6 +120,7 @@ Global
{E08ADBB1-7CB8-4BFF-9BAC-485DC7822719} = {134D18E2-ECAC-4571-B7BE-0C10796D5555}
{2F9424F6-0BB5-4BD8-92A7-3625A666111F} = {134D18E2-ECAC-4571-B7BE-0C10796D5555}
{71009957-1245-48AD-BE28-7377CF50DA6B} = {134D18E2-ECAC-4571-B7BE-0C10796D5555}
{21B57A75-EE1A-D96F-57EF-82EAF1A767EE} = {134D18E2-ECAC-4571-B7BE-0C10796D5555}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CF07A0CA-1140-44DC-9E7E-F99E65D9EF97}
Expand Down
28 changes: 1 addition & 27 deletions src/MockMe.Generator/MockStoreGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,36 +210,10 @@ internal static partial class {StoreClassName}
}}
}}
#pragma warning restore";

context.AddSource(
"Mock.DummyDeclaration.g.cs",
SourceText.From(mockStoreSource, Encoding.UTF8)
);

//AppDomain.CurrentDomain.TypeResolve += new ResolveEventHandler(HandleTypeResolve);
//// Load the assembly
//var assemblyPath = Path.Combine(
// Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
// "MockMe.SampleMocks.dll"
//);
//var assembly = AssemblyDefinition.ReadAssembly(assemblyPath);
//// Find the type to delete
////
//var typeToRemove = assembly.MainModule.Types.FirstOrDefault(t => t.Name == "Calculator");
//if (typeToRemove != null)
//{
// assembly.MainModule.Types.Remove(typeToRemove);
//}
//var outputPath = "MockMe.SampleMocks.dll";
}

//static Assembly HandleTypeResolve(object sender, ResolveEventArgs args)
//{
// Console.WriteLine("TypeResolve event handler.");

// // Save the dynamic assembly, and then load it using its
// // display name. Return the loaded assembly.
// //
// //ab.Save(moduleName);
// return Assembly.Load(Assembly.GetExecutingAssembly().Location);
//}
}
2 changes: 0 additions & 2 deletions src/MockMe.PostBuild/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
//System.Diagnostics.Debugger.Launch();
# endif

Console.WriteLine("Hello, Task!");

var testAssemblyPath = args[0];
var binLocation =
Path.GetDirectoryName(testAssemblyPath)
Expand Down
11 changes: 5 additions & 6 deletions src/MockMe/Build/MockMe.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@
<MockMeAssembly Condition="$(MockMeAssembly) == ''">$(MockMePath)MockMe.dll</MockMeAssembly>
</PropertyGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<!--<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="echo After Build: $(MockMeAssembly) $(MockMePath)" />
</Target>
</Target>-->

<ItemGroup>
<!--<ItemGroup>
<JsonFiles Include="$(MockMePath)*.json" />
</ItemGroup>
<Target Name="CopyRuntimeConfig" BeforeTargets="ReplaceGenericMethods">
<Exec Command="echo CopyRuntimeConfig: $(OutputPath) $(MockMePath)" />
<Copy SourceFiles="@(JsonFiles)" DestinationFolder="$(OutputPath)" />
</Target>
</Target>-->

<!--<UsingTask TaskName="MockMe.Build.ReplaceGenericMethods" AssemblyFile="$(MockMeAssembly)" />-->

<Target Name="ReplaceGenericMethods" AfterTargets="PostBuildEvent">
<Exec Command="dotnet --roll-forward Major $(OutputPath)MockMe.PostBuild.dll $(MSBuildProjectDirectory)\$(OutputPath)$(ProjectName).dll" />
<Exec Command='dotnet --roll-forward Major "$(MockMePath)MockMe.PostBuild.dll" "$(MSBuildProjectDirectory)\$(OutputPath)$(ProjectName).dll"' />
</Target>
</Project>
3 changes: 2 additions & 1 deletion src/MockMe/MockMe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.3.3" />
<PackageReference Include="Mono.Cecil" Version="0.11.6" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Framework" Version="17.12.6" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.12.6" PrivateAssets="all" />
<PackageReference Include="MonoMod.Core" Version="1.2.2" />
<PackageReference Include="PolySharp" Version="1.14.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down Expand Up @@ -54,6 +54,7 @@
<None Include="$(MSBuildProjectDirectory)\..\MockMe.PostBuild\bin\$(Configuration)\$(TargetFramework)\MockMe.PostBuild.dll" Pack="true" PackagePath="lib/$(TargetFramework)" Visible="true" />
<None Include="$(MSBuildProjectDirectory)\..\MockMe.PostBuild\bin\$(Configuration)\$(TargetFramework)\MockMe.PostBuild.runtimeconfig.json" Pack="true" PackagePath="lib/$(TargetFramework)" Visible="true" />

<None Include="$(MSBuildProjectDirectory)\..\..\Harmony\Harmony\bin\ReleaseThin\$(TargetFramework)\0Harmony.dll" Pack="true" PackagePath="lib/$(TargetFramework)" Visible="true" />
<None Include="$(NugetPackageRoot)\mono.cecil\0.11.6\lib\netstandard2.0\Mono.Cecil.dll" Pack="true" PackagePath="lib/$(TargetFramework)" Visible="true" />
<None Include="$(NugetPackageRoot)\mono.cecil\0.11.6\lib\netstandard2.0\Mono.Cecil.Rocks.dll" Pack="true" PackagePath="lib/$(TargetFramework)" Visible="false" />
</ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..\'))" />

<PropertyGroup>
<MockMeTestsTargetFramework Condition="'$(MockMeTestsTargetFramework)' == ''">net6.0</MockMeTestsTargetFramework>
<TargetFramework>$(MockMeTestsTargetFramework)</TargetFramework>
<LangVersion>10</LangVersion>
<RollForward>major</RollForward>
<IncludeMockMeRef Condition="'$(IncludeMockMeRef)' == ''">True</IncludeMockMeRef>
<WarningsNotAsErrors>
CA1822; <!-- Mark members as static -->
CA1861; <!-- Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array -->
IDE0060; <!--Remove unused parameter-->
IDE0161; <!-- Convert to file-scoped namespace -->
IDE0130; <!-- Namespace does not match folder structure -->
IDE0034; <!-- Simplify 'default' expression -->
Expand All @@ -26,10 +30,15 @@
<ProjectReference Include="..\..\src\MockMe.Generator\MockMe.Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\..\src\MockMe\MockMe.csproj" />
<ProjectReference Include="..\..\src\MockMe.PostBuild\MockMe.PostBuild.csproj" />

<Reference Include="0Harmony">
<HintPath>..\..\Harmony\Harmony\bin\ReleaseThin\net6.0\0Harmony.dll</HintPath>
</Reference>
</ItemGroup>

<PropertyGroup Condition="'$(IncludeMockMeRef)' == 'True' And '$(MockMeNugetPackageVersion)' == ''">
<MockMePath>$(MSBuildProjectDirectory)\bin\$(Configuration)\$(TargetFramework)\</MockMePath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<Import Project="..\src\MockMe\Build\MockMe.targets" Condition="'$(IncludeMockMeRef)' == 'True' And '$(MockMeNugetPackageVersion)' == ''" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.CodeCoverage" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MockMe.Tests.ExampleClasses\MockMe.Tests.ExampleClasses.csproj" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions tests/MockMe Tests With Path Spaces/PathSpacesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using MockMe;
using MockMe.Tests.ExampleClasses;
using Xunit;

namespace MockMe_Tests_With_Path_Spaces;

public class PathSpacesTests
{
/// <summary>
/// Regression test for this issue building projects when the project path contained a space
/// https://github.com/connorivy/MockMe/issues/20
/// </summary>
[Fact]
public void AssemblyWithPathSpaces_ThatUsesGenericMethodMock_ShouldWork()
{
var mock = Mock.Me(default(ClassWithGenericMethods));

mock.Setup.ThreeGenericTypes<string, int, double>(Arg.Any(), Arg.Any(), Arg.Any())
.Returns("asdf");

ClassWithGenericMethods obj = mock;

var result = obj.ThreeGenericTypes("Hello", 1, 9.9);
Assert.Equal("asdf", result);
}
}
4 changes: 2 additions & 2 deletions tests/MockMe.Tests.ExampleClasses/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<!--<PropertyGroup>
<IncludeMockMeRef>False</IncludeMockMeRef>
</PropertyGroup>
</PropertyGroup>-->

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..\'))" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.3.3" />
<PackageReference Include="Mono.Cecil" Version="0.11.6" PrivateAssets="all" />
</ItemGroup>

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

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

<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<IsPackable>false</IsPackable>
Expand Down
4 changes: 3 additions & 1 deletion tests/MockMe.Tests.Overloads.Virtual/AllOverloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
using System.Threading.Tasks;

#pragma warning disable CA1716 // Using reserved word in namespace
#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace MockMe.Tests.Overloads
#pragma warning restore IDE0130 // Namespace does not match folder structure
#pragma warning restore CA1716 // Using reserved word in namespace
{
[ExcludeFromCodeCoverage]
internal class AllOverloads
public class AllOverloads
{
public int OutArgument(out int arg) => throw new NotImplementedException();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<IsPackable>false</IsPackable>
Expand Down
1 change: 0 additions & 1 deletion tests/MockMe.Tests.Runner/MockMe.Tests.Runner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions tests/MockMe.Tests.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"solution": {
"path": "..\\MockMe.sln",
"projects": [
"tests\\MockMe Tests With Path Spaces\\MockMe Tests With Path Spaces.csproj",
"tests\\MockMe.Tests.ExampleClasses\\MockMe.Tests.ExampleClasses.csproj",
"tests\\MockMe.Tests.Overloads.Interface\\MockMe.Tests.Overloads.Interface.csproj",
"tests\\MockMe.Tests.Overloads.Sealed\\MockMe.Tests.Overloads.Sealed.csproj",
Expand Down
2 changes: 0 additions & 2 deletions tests/MockMe.Tests/MockMe.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<IsPackable>false</IsPackable>
Expand All @@ -13,7 +12,6 @@
<PackageReference Include="coverlet.collector" Version="6.0.0" />-->
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.CodeCoverage" Version="17.11.1" />
<PackageReference Include="Mono.Cecil" Version="0.11.6" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion wiki/AdvancedUsage.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MyCoolClass

var mock = Mock.Me(default(MyCoolClass));

// the out parameter can be discarded, as it doesn't do anything here.
// the out parameter can be discarded, as it doesn't do anything when used by the Setup or Assert property methods.
// the only reason it is here is because dropping it could lead to conflicts with other method overloads
mock.Setup.TryGetVal(Arg.Any(), out _).Returns(args =>
{
Expand Down
Loading

0 comments on commit 46debcd

Please sign in to comment.