Skip to content

Commit

Permalink
switch to arg collections instead of tuples of args (#15)
Browse files Browse the repository at this point in the history
* add coverage to new test

* add property tests

* change arg.any to method instead of prop

* generic classes working

* generic classes working and fixed indexers

* remove unused code

* update test coverage process

* no need to restore (I think?)

* add props

* switch up the order

* clean up buildAndTest yaml

* switch up NumTimes

* add throws functionality

* add interface overload tests

* fix tests slnf

* add support for internal interface calls

* fix tests

* add nuget icon

* fix warnings

* exclude dummy class from code cov

* add more generic tests

* Merge remote-tracking branch 'origin/main' into dev

* fix errors

* add tests for virtual members

* builds, but logic doesn't work

* wip redoing with argCollection instead of generic param list

* this actually builds

* fix the setter test

* generic method tests now working

* everything is fixed

* add additional tests for setting out params

* delete a bunch of code :)

* this works when you 'dotnet clean' followed by '

dotnet-coverage collect "dotnet test -c Release -s .\CodeCoverage.runsettings" -f xml

* seems to be fully working when I run

dotnet-coverage collect "dotnet run" -f cobertura -s ..\..\CodeCoverage.runsettings

* change build pipeline

* bump .net version

* modify pipeline

* try something else?

* try loading generator assembly?

* please work

* please

* can I add some logging?

* bump log severity

* try again

* try again

* does this point to dll?

* try this

* get cool message

* try this

* try this

* Revert "try this"

This reverts commit a4b5f9d.

* added some callback and return tests with new arg colletions

* fix ci pipeline

* generate repo badge

* don't generate setter for non-byRef parameters

* remove logging call
  • Loading branch information
connorivy authored Dec 4, 2024
1 parent 997f29f commit a0d15ee
Show file tree
Hide file tree
Showing 69 changed files with 2,295 additions and 8,873 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,23 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4

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

- name: Restore Dependencies
run: dotnet restore
dotnet-version: '9.0.x'

- name: Test And Collect CodeCov
run: |
dotnet tool install --global dotnet-coverage
dotnet-coverage collect "dotnet test --no-restore -c Release" -f xml
dotnet-coverage collect "dotnet run --project ./tests/MockMe.Tests.Runner/" -f cobertura -s ./CodeCoverage.runsettings
- name: Generate report
uses: danielpalme/[email protected]
with:
reports: './output.xml'
reports: './output.cobertura.xml'
targetdir: './tests/TestResults'
reporttypes: 'lcov'
filefilters: '-*\*.g.cs'
# reporttypes: 'html'

- name: Coveralls
uses: coverallsapp/github-action@master
Expand All @@ -40,8 +37,7 @@ jobs:
path-to-lcov: ./tests/TestResults/lcov.info

- name: Pack NuGet Packages
# run: dotnet pack --configuration Release --no-build --output ./packages --version 0.0.1-dev.$GITHUB_RUN_ID
run: dotnet pack --configuration Release --no-build --output ./packages /p:Version=0.0.1-dev
run: dotnet pack --configuration Release --output ./packages /p:Version=0.0.1-dev

- name: Upload NuGet Packages
uses: actions/upload-artifact@v4
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/publishWiki.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,34 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: Andrew-Chen-Wang/github-wiki-action@v4

build_and_pack:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4

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

- name: Test And Collect CodeCov
run: |
dotnet tool install --global dotnet-coverage
dotnet-coverage collect "dotnet run --project ./tests/MockMe.Tests.Runner/" -f cobertura -s ./CodeCoverage.runsettings
- name: Generate report
uses: danielpalme/[email protected]
with:
reports: './output.cobertura.xml'
targetdir: './tests/TestResults'
reporttypes: 'lcov'
# reporttypes: 'html'

- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.COVERALLS_REPO_TOKEN }}
path-to-lcov: ./tests/TestResults/lcov.info
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,5 @@ MigrationBackup/
openSees/lib

output.xml

output.cobertura.xml
33 changes: 33 additions & 0 deletions CodeCoverage.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Configuration>
<!--<Option Name="IncludeUninstrumentedCode" Value="true" />-->
<!--<Option Name="ExcludeFromCodeCoverage"> */**/*.g.cs </Option>-->
<CodeCoverage>
<ModulePaths>
<Exclude>
<ModulePath>.MockMe.Tests.ExampleClasses.dll$</ModulePath>
<!--<ModulePath>.*Tests.*</ModulePath>-->
</Exclude>
</ModulePaths>
<Sources>
<Exclude>
<Source>.*Polysharp.*</Source>
<Source>.*.g.cs$</Source>
</Exclude>
</Sources>

<CollectFromChildProcesses>True</CollectFromChildProcesses>
<!--<UseVerifiableInstrumentation>False</UseVerifiableInstrumentation>-->
<!--<UseVerifiableInstrumentation>False</UseVerifiableInstrumentation>-->
<EnableStaticNativeInstrumentation>False</EnableStaticNativeInstrumentation>
<EnableDynamicNativeInstrumentation>False</EnableDynamicNativeInstrumentation>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
10 changes: 9 additions & 1 deletion MockMe.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{AB32507E-2EE
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{134D18E2-ECAC-4571-B7BE-0C10796D5555}"
ProjectSection(SolutionItems) = preProject
CodeCoverage.runsettings = CodeCoverage.runsettings
tests\Directory.Build.props = tests\Directory.Build.props
tests\Directory.Build.targets = tests\Directory.Build.targets
EndProjectSection
Expand All @@ -21,7 +22,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.github\workflows\buildAndTest.yml = .github\workflows\buildAndTest.yml
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
global.json = global.json
.github\workflows\publishWiki.yml = .github\workflows\publishWiki.yml
README.md = README.md
.github\workflows\release.yml = .github\workflows\release.yml
Expand All @@ -35,6 +35,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MockMe.Tests.ExampleClasses
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "wiki", "wiki", "{4723EF4B-98A5-4F3D-BEB9-0632A3939D4D}"
ProjectSection(SolutionItems) = preProject
wiki\AdvancedUsage.md = wiki\AdvancedUsage.md
wiki\AvoidingCommonPitfalls.md = wiki\AvoidingCommonPitfalls.md
wiki\HowDoesItWork.md = wiki\HowDoesItWork.md
wiki\QuickStart.md = wiki\QuickStart.md
Expand All @@ -50,6 +51,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MockMe.Tests.Overloads.Inte
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MockMe.Tests.Overloads.Virtual", "tests\MockMe.Tests.Overloads.Virtual\MockMe.Tests.Overloads.Virtual.csproj", "{2F9424F6-0BB5-4BD8-92A7-3625A666111F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MockMe.Tests.Runner", "tests\MockMe.Tests.Runner\MockMe.Tests.Runner.csproj", "{71009957-1245-48AD-BE28-7377CF50DA6B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -92,6 +95,10 @@ Global
{2F9424F6-0BB5-4BD8-92A7-3625A666111F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F9424F6-0BB5-4BD8-92A7-3625A666111F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F9424F6-0BB5-4BD8-92A7-3625A666111F}.Release|Any CPU.Build.0 = Release|Any CPU
{71009957-1245-48AD-BE28-7377CF50DA6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -107,6 +114,7 @@ Global
{1CDE1684-1F3F-AF84-5126-85482E225FD8} = {134D18E2-ECAC-4571-B7BE-0C10796D5555}
{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}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CF07A0CA-1140-44DC-9E7E-F99E65D9EF97}
Expand Down
6 changes: 0 additions & 6 deletions global.json

This file was deleted.

50 changes: 15 additions & 35 deletions src/MockMe.Abstractions/GenericMethodDefinitionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,21 @@
namespace MockMe.Abstractions;

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public class GenericMethodDefinitionAttribute : Attribute
public class GenericMethodDefinitionAttribute(
string typeToReplaceAssemblyName,
string typeToReplaceTypeFullName,
string typeToReplaceMethodName,
string sourceTypeAssemblyName,
string sourceTypeFullName,
string sourceTypeMethodName
) : Attribute
{
public GenericMethodDefinitionAttribute(
string typeToReplaceAssemblyName,
string typeToReplaceTypeFullName,
string typeToReplaceMethodName,
string sourceTypeAssemblyName,
string sourceTypeFullName,
string sourceTypeMethodName
)
{
this.TypeToReplaceAssemblyName = typeToReplaceAssemblyName;
this.TypeToReplaceTypeFullName = typeToReplaceTypeFullName;
this.TypeToReplaceMethoName = typeToReplaceMethodName;
this.SourceTypeAssemblyName = sourceTypeAssemblyName;
this.SourceTypeFullName = sourceTypeFullName;
this.SourceTypeMethodName = sourceTypeMethodName;
}
public string TypeToReplaceAssemblyName { get; } = typeToReplaceAssemblyName;
public string TypeToReplaceTypeFullName { get; } = typeToReplaceTypeFullName;
public string TypeToReplaceMethoName { get; } = typeToReplaceMethodName;
public string SourceTypeAssemblyName { get; } = sourceTypeAssemblyName;
public string SourceTypeFullName { get; } = sourceTypeFullName;
public string SourceTypeMethodName { get; } = sourceTypeMethodName;

public string TypeToReplaceAssemblyName { get; }
public string TypeToReplaceTypeFullName { get; }
public string TypeToReplaceMethoName { get; }
public string SourceTypeAssemblyName { get; }
public string SourceTypeFullName { get; }
public string SourceTypeMethodName { get; }
}

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public class GenericMethodDefinition2Attribute : Attribute
{
public GenericMethodDefinition2Attribute(
string typeToReplaceAssemblyName,
string typeToReplaceTypeFullName,
string typeToReplaceMethodName,
string mockClassNamespace,
string mockClassName
) { }
public static string GetCoolMessage() => "This only comes from abstractions";
}
25 changes: 0 additions & 25 deletions src/MockMe.Abstractions/IMemberMock.cs

This file was deleted.

10 changes: 3 additions & 7 deletions src/MockMe.Abstractions/MockBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ public static implicit operator TObjectToMock(SealedTypeMock<TObjectToMock> mock
mock.MockedObject;
}

public abstract class InterfaceMock<TObjectToMock, TCallTracker> : MockBase<TObjectToMock>
public abstract class InterfaceMock<TObjectToMock, TCallTracker>(TCallTracker callTracker)
: MockBase<TObjectToMock>
where TCallTracker : TObjectToMock
{
protected TCallTracker CallTracker { get; }

protected InterfaceMock(TCallTracker callTracker)
{
this.CallTracker = callTracker;
}
protected TCallTracker CallTracker { get; } = callTracker;

public override TObjectToMock MockedObject => this.CallTracker;

Expand Down
5 changes: 0 additions & 5 deletions src/MockMe.Abstractions/MockMe.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
</ItemGroup>

</Project>
27 changes: 7 additions & 20 deletions src/MockMe.Abstractions/MockReplacementInfo.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
namespace MockMe.Abstractions;

public class MockReplacementInfo
public class MockReplacementInfo(GenericMethodInfo typeToReplace, GenericMethodInfo sourceType)
{
public MockReplacementInfo(GenericMethodInfo typeToReplace, GenericMethodInfo sourceType)
{
this.TypeToReplace = typeToReplace;
this.SourceType = sourceType;
}

public GenericMethodInfo TypeToReplace { get; }
public GenericMethodInfo SourceType { get; }
public GenericMethodInfo TypeToReplace { get; } = typeToReplace;
public GenericMethodInfo SourceType { get; } = sourceType;
}

public class GenericMethodInfo
public class GenericMethodInfo(string assemblyName, string typeFullName, string methodName)
{
public GenericMethodInfo(string assemblyName, string typeFullName, string methodName)
{
this.AssemblyName = assemblyName;
this.TypeFullName = typeFullName;
this.MethodName = methodName;
}

public string AssemblyName { get; }
public string TypeFullName { get; }
public string MethodName { get; }
public string AssemblyName { get; } = assemblyName;
public string TypeFullName { get; } = typeFullName;
public string MethodName { get; } = methodName;
}
54 changes: 53 additions & 1 deletion src/MockMe.Generator/Extensions/MethodSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,56 @@ private static string GetParametersWithTypesAndModifiers(
);
}

public static string GetParametersWithOriginalTypesAndNoModifiers(this IMethodSymbol method)
{
if (method.Parameters.Length == 0)
{
return string.Empty;
}

return string.Join(
", ",
method.Parameters.Select(p =>
{
var paramString = $"{p.Type.ToFullTypeString()} {p.Name}";
//if (p.HasExplicitDefaultValue)
//{
// var defaultValue =
// p.ExplicitDefaultValue != null ? p.ExplicitDefaultValue.ToString() : "null";
// paramString += $" = {defaultValue}";
//}
return paramString;
})
);
}

public static string GetParametersWithModifiersAndNoTypes(this IMethodSymbol method)
{
if (method.Parameters.Length == 0)
{
return string.Empty;
}

return string.Join(
", ",
method.Parameters.Select(p =>
{
var modifiers = p.RefKind switch
{
RefKind.Ref => "ref ",
RefKind.Out => "out ",
RefKind.In => "in ",
//RefKind.RefReadOnlyParameter => "ref readonly ",
RefKind.None or _ => "",
};

var paramString = $"{modifiers} {p.Name}";

return paramString;
})
);
}

public static string GetParametersWithoutTypesAndModifiers(this IMethodSymbol method) =>
string.Join(", ", method.Parameters.Select(p => p.Name));

Expand Down Expand Up @@ -140,7 +190,9 @@ public static string GetPropertyName(this IMethodSymbol methodSymbol)
public static string GetUniqueMethodName(this IMethodSymbol methodSymbol)
{
var methodName = methodSymbol.Name;
var parameterTypes = methodSymbol.Parameters.Select(p => p.Type.Name);
var parameterTypes = methodSymbol.Parameters.Select(p =>
(p.RefKind == RefKind.None ? "" : p.RefKind.ToString()) + p.Type.Name
);
var uniqueMethodName = $"{methodName}_{string.Join("_", parameterTypes)}";
return uniqueMethodName;
}
Expand Down
Loading

0 comments on commit a0d15ee

Please sign in to comment.