Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
54 changes: 13 additions & 41 deletions src/Moq.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stunts", "Stunts\Stunts\Stu
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.Sdk", "Moq\Moq.Sdk\Moq.Sdk.csproj", "{80DE507E-3AF9-4360-9E56-66523B01FB51}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.CodeAnalysis", "Moq\Moq.CodeAnalysis\Moq.CodeAnalysis.csproj", "{6496C171-32F2-47DD-A8EE-B99E9E26B6C6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stunts.Sdk", "Stunts\Stunts.Sdk\Stunts.Sdk.csproj", "{493E8F90-2663-47EC-A2AE-E2440E6AE180}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stunts.CodeAnalysis", "Stunts\Stunts.CodeAnalysis\Stunts.CodeAnalysis.csproj", "{9ACA3490-778C-4C58-914C-87B9E7C15AC7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Stunts", "Stunts", "{EEC3EC48-ACB2-4D25-B592-F360F676BE45}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.Sdk.Tests", "Moq\Moq.Sdk.Tests\Moq.Sdk.Tests.csproj", "{EB66BC5E-4072-4F26-9772-979D8561883F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample", "Samples\Sample\Sample.csproj", "{03D94BF7-F2BA-476D-BDBA-9E49048D7F03}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.Tests", "Moq\Moq.Tests\Moq.Tests.csproj", "{9A09225F-E0BC-4890-BED4-D9F6F5DAC146}"
ProjectSection(ProjectDependencies) = postProject
{6496C171-32F2-47DD-A8EE-B99E9E26B6C6} = {6496C171-32F2-47DD-A8EE-B99E9E26B6C6}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{1DBDFC27-21EC-4EAC-B51B-84EDC8DBB9D5}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -56,20 +47,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{1DBDFC27
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stunts.Tests", "Stunts\Stunts.Tests\Stunts.Tests.csproj", "{EDBDA217-CA42-4C82-826F-7D990185EC0F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stunts.CodeFix", "Stunts\Stunts.CodeFix\Stunts.CodeFix.csproj", "{A4D96CA3-75ED-43E4-B172-872EF2BCF128}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.CodeFix", "Moq\Moq.CodeFix\Moq.CodeFix.csproj", "{20370B86-1339-40F5-8A6E-ED15FE64112D}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Moq.Testing", "Testing\Moq.Testing.shproj", "{1BD7DFDE-2FC8-4899-9903-6CA5724CC185}"
EndProject
Project("{13B669BE-BB05-4DDF-9536-439F39A36129}") = "Stunts.Package", "Stunts\Stunts.Package\Stunts.Package.msbuildproj", "{336A513F-BEC7-44EE-A720-F61E3A65410F}"
EndProject
Project("{13B669BE-BB05-4DDF-9536-439F39A36129}") = "Moq.Package", "Moq\Moq.Package\Moq.Package.msbuildproj", "{09C65B0B-9206-4682-9837-6B98936553C1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stunts.DynamicProxy", "Stunts\Stunts.DynamicProxy\Stunts.DynamicProxy.csproj", "{2FC48D20-CB36-4606-A9DC-22981DD13A3D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.DynamicProxy", "Moq\Moq.DynamicProxy\Moq.DynamicProxy.csproj", "{BA43EF2F-6CA8-49A5-A4E7-C2FF71928F05}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Testing\Moq.Testing.projitems*{1bd7dfde-2fc8-4899-9903-6ca5724cc185}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Expand All @@ -87,18 +73,6 @@ Global
{80DE507E-3AF9-4360-9E56-66523B01FB51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80DE507E-3AF9-4360-9E56-66523B01FB51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80DE507E-3AF9-4360-9E56-66523B01FB51}.Release|Any CPU.Build.0 = Release|Any CPU
{6496C171-32F2-47DD-A8EE-B99E9E26B6C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6496C171-32F2-47DD-A8EE-B99E9E26B6C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6496C171-32F2-47DD-A8EE-B99E9E26B6C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6496C171-32F2-47DD-A8EE-B99E9E26B6C6}.Release|Any CPU.Build.0 = Release|Any CPU
{493E8F90-2663-47EC-A2AE-E2440E6AE180}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{493E8F90-2663-47EC-A2AE-E2440E6AE180}.Debug|Any CPU.Build.0 = Debug|Any CPU
{493E8F90-2663-47EC-A2AE-E2440E6AE180}.Release|Any CPU.ActiveCfg = Release|Any CPU
{493E8F90-2663-47EC-A2AE-E2440E6AE180}.Release|Any CPU.Build.0 = Release|Any CPU
{9ACA3490-778C-4C58-914C-87B9E7C15AC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9ACA3490-778C-4C58-914C-87B9E7C15AC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9ACA3490-778C-4C58-914C-87B9E7C15AC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9ACA3490-778C-4C58-914C-87B9E7C15AC7}.Release|Any CPU.Build.0 = Release|Any CPU
{EB66BC5E-4072-4F26-9772-979D8561883F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB66BC5E-4072-4F26-9772-979D8561883F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB66BC5E-4072-4F26-9772-979D8561883F}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -115,14 +89,6 @@ Global
{EDBDA217-CA42-4C82-826F-7D990185EC0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDBDA217-CA42-4C82-826F-7D990185EC0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDBDA217-CA42-4C82-826F-7D990185EC0F}.Release|Any CPU.Build.0 = Release|Any CPU
{A4D96CA3-75ED-43E4-B172-872EF2BCF128}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4D96CA3-75ED-43E4-B172-872EF2BCF128}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4D96CA3-75ED-43E4-B172-872EF2BCF128}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4D96CA3-75ED-43E4-B172-872EF2BCF128}.Release|Any CPU.Build.0 = Release|Any CPU
{20370B86-1339-40F5-8A6E-ED15FE64112D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20370B86-1339-40F5-8A6E-ED15FE64112D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20370B86-1339-40F5-8A6E-ED15FE64112D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20370B86-1339-40F5-8A6E-ED15FE64112D}.Release|Any CPU.Build.0 = Release|Any CPU
{336A513F-BEC7-44EE-A720-F61E3A65410F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{336A513F-BEC7-44EE-A720-F61E3A65410F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{336A513F-BEC7-44EE-A720-F61E3A65410F}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -131,18 +97,24 @@ Global
{09C65B0B-9206-4682-9837-6B98936553C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09C65B0B-9206-4682-9837-6B98936553C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09C65B0B-9206-4682-9837-6B98936553C1}.Release|Any CPU.Build.0 = Release|Any CPU
{2FC48D20-CB36-4606-A9DC-22981DD13A3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2FC48D20-CB36-4606-A9DC-22981DD13A3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2FC48D20-CB36-4606-A9DC-22981DD13A3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2FC48D20-CB36-4606-A9DC-22981DD13A3D}.Release|Any CPU.Build.0 = Release|Any CPU
{BA43EF2F-6CA8-49A5-A4E7-C2FF71928F05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA43EF2F-6CA8-49A5-A4E7-C2FF71928F05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA43EF2F-6CA8-49A5-A4E7-C2FF71928F05}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA43EF2F-6CA8-49A5-A4E7-C2FF71928F05}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{AE46AE30-8002-4F2C-B368-44546B1D71D8} = {EEC3EC48-ACB2-4D25-B592-F360F676BE45}
{493E8F90-2663-47EC-A2AE-E2440E6AE180} = {EEC3EC48-ACB2-4D25-B592-F360F676BE45}
{9ACA3490-778C-4C58-914C-87B9E7C15AC7} = {EEC3EC48-ACB2-4D25-B592-F360F676BE45}
{1DBDFC27-21EC-4EAC-B51B-84EDC8DBB9D5} = {2093478C-CEA6-4034-BCDE-EDC7A5DD4532}
{EDBDA217-CA42-4C82-826F-7D990185EC0F} = {EEC3EC48-ACB2-4D25-B592-F360F676BE45}
{A4D96CA3-75ED-43E4-B172-872EF2BCF128} = {EEC3EC48-ACB2-4D25-B592-F360F676BE45}
{336A513F-BEC7-44EE-A720-F61E3A65410F} = {EEC3EC48-ACB2-4D25-B592-F360F676BE45}
{2FC48D20-CB36-4606-A9DC-22981DD13A3D} = {EEC3EC48-ACB2-4D25-B592-F360F676BE45}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DA4CFD03-827D-482B-9304-83456D2A8115}
Expand Down
32 changes: 0 additions & 32 deletions src/Moq/Moq.CodeFix/Moq.targets

This file was deleted.

63 changes: 63 additions & 0 deletions src/Moq/Moq.DynamicProxy/DynamicMockFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Threading;
using Castle.DynamicProxy;
using Stunts;
using Stunts.Sdk;

namespace Moq.Sdk
{
/// <summary>
/// Provides an <see cref="IMockFactory"/> that creates types at run-time using Castle DynamicProxy.
/// </summary>
public class DynamicMockFactory : DynamicStuntFactory, IMockFactory
{
/// <inheritdoc />
public object CreateMock(Assembly mocksAssembly, Type baseType, Type[] implementedInterfaces, object[] constructorArguments)
=> CreateStunt(mocksAssembly, baseType, implementedInterfaces, constructorArguments);

/// <summary>
/// Creates the mock proxy.
/// </summary>
protected override object CreateProxy(Type baseType, Type[] implementedInterfaces, ProxyGenerationOptions options, object[] constructorArguments, bool notImplemented)
{
if (!implementedInterfaces.Contains(typeof(IMocked)))
{
var fixedInterfaces = new Type[implementedInterfaces.Length + 1];
fixedInterfaces[0] = typeof(IMocked);
implementedInterfaces.CopyTo(fixedInterfaces, 1);
implementedInterfaces = fixedInterfaces;
}

var mocked = (IMocked)Generator.CreateClassProxy(baseType, implementedInterfaces, options, constructorArguments, new DynamicMockInterceptor(notImplemented));

// Save for cloning purposes. We opened a generated proxy from DP to figure out the ctor signature it creates.
// The lazy-calculated value allows us to provide a new interceptor for every retrieval.
// Add first-class support in statebag for this pattern of either Func<T> for values, or
// Lazy<T>, since both could be quite useful for expensive state that may be needed lazily.
mocked.Mock.State.Set(".ctor", () => new object[] { new IInterceptor[] { new DynamicMockInterceptor(notImplemented) } }.Concat(constructorArguments).ToArray());

return mocked;
}

class DynamicMockInterceptor : DynamicStuntInterceptor
{
IMock mock;

public DynamicMockInterceptor(bool notImplemented) : base(notImplemented) { }

public override void Intercept(IInvocation invocation)
{
if (invocation.Method.DeclaringType == typeof(IMocked))
{
invocation.ReturnValue = LazyInitializer.EnsureInitialized(ref mock, () => new DefaultMock((IStunt)invocation.Proxy));
return;
}

base.Intercept(invocation);
}
}
}
}
14 changes: 14 additions & 0 deletions src/Moq/Moq.DynamicProxy/Moq.DynamicProxy.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="Microsoft.Build.CentralPackageVersions" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Moq.Sdk</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Stunts\Stunts.DynamicProxy\Stunts.DynamicProxy.csproj" />
<ProjectReference Include="..\Moq.Sdk\Moq.Sdk.csproj" />
</ItemGroup>

</Project>
11 changes: 1 addition & 10 deletions src/Moq/Moq.Package/Moq.Package.msbuildproj
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
<Project Sdk="Microsoft.Build.NoTargets" DefaultTargets="Pack">
<Sdk Name="Microsoft.Build.CentralPackageVersions" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>

<PackageId>Moq</PackageId>
<Title>Moq</Title>
<Summary>The most popular and friendly mocking framework for .NET</Summary>
<Description>The most popular and friendly mocking framework for .NET</Description>
<PackageTags>moq mocking mock</PackageTags>
<PackOnBuild Condition="'$(PackOnBuild)' == '' and '$(Configuration)' == 'Release'">true</PackOnBuild>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Moq.CodeAnalysis\Moq.CodeAnalysis.csproj" />
<ProjectReference Include="..\Moq.CodeFix\Moq.CodeFix.csproj" />
<ProjectReference Include="..\Moq.DynamicProxy\Moq.DynamicProxy.csproj" />
<ProjectReference Include="..\Moq.Sdk\Moq.Sdk.csproj" />
<ProjectReference Include="..\Moq\Moq.csproj" />
<ProjectReference Include="..\..\Stunts\Stunts.Package\Stunts.Package.msbuildproj" IncludeAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageFile Include="AutoCodeFix" Version="2.10-alpha" Kind="Dependency" />
</ItemGroup>

<Target Name="FixPackageFileFramework" BeforeTargets="Pack" AfterTargets="$(GetPackageContents)" Returns="@(_PackageContent)">
<ItemGroup>
<_PackageContent Condition="'%(Kind)' == 'Dependency'">
Expand Down
10 changes: 0 additions & 10 deletions src/Moq/Moq.Sdk.Tests/App.config

This file was deleted.

49 changes: 0 additions & 49 deletions src/Moq/Moq.Sdk.Tests/MockFactoryTests.cs

This file was deleted.

8 changes: 0 additions & 8 deletions src/Moq/Moq.Sdk.Tests/Moq.Sdk.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<IncludeXunit>true</IncludeXunit>
<IncludeMSBuild>true</IncludeMSBuild>

<!-- Don't include this assembly in the generated ReferencePaths.g.cs because we confuse Roslyn with NS2 + net471 refs -->
<IncludeTargetPath>false</IncludeTargetPath>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,13 +12,9 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Stunts\Stunts.CodeFix\Stunts.CodeFix.csproj" />
<ProjectReference Include="..\Moq.Sdk\Moq.Sdk.csproj" />
<ProjectReference Include="..\..\Stunts\Stunts\Stunts.csproj" />
<ProjectReference Include="..\..\Stunts\Stunts.Sdk\Stunts.Sdk.csproj" />
<ProjectReference Include="..\..\Samples\Sample\Sample.csproj" />
</ItemGroup>

<Import Project="..\..\Testing\Moq.Testing.projitems" Label="Shared" />

</Project>
4 changes: 2 additions & 2 deletions src/Moq/Moq.Sdk/IMockFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public interface IMockFactory
/// <param name="mocksAssembly">Assembly where compile-time generated mocks exist.</param>
/// <param name="baseType">The base type (or main interface) of the mock.</param>
/// <param name="implementedInterfaces">Additional interfaces implemented by the mock, or an empty array.</param>
/// <param name="construtorArguments">
/// <param name="constructorArguments">
/// Constructor arguments if the <paramref name="baseType" /> is a class, rather than an interface, or an empty array.
/// </param>
/// <returns>A mock that implements <see cref="IMocked"/> in addition to the specified interfaces (if any).</returns>
object CreateMock(Assembly mocksAssembly, Type baseType, Type[] implementedInterfaces, object[] construtorArguments);
object CreateMock(Assembly mocksAssembly, Type baseType, Type[] implementedInterfaces, object[] constructorArguments);
}
}
8 changes: 5 additions & 3 deletions src/Moq/Moq.Sdk/MockBehaviorPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public class MockBehaviorPipeline : IMockBehaviorPipeline
/// where all sub-pipeline behaviors automatically apply to the invocation, since they
/// are filtered as a whole according to the <see cref="Setup"/>.
/// </summary>
/// <param name="invocation"></param>
/// <param name="next"></param>
/// <returns></returns>
public IMethodReturn Execute(IMethodInvocation invocation, GetNextBehavior next)
{
var mock = (invocation.Target as IMocked)?.Mock ?? throw new ArgumentException(Resources.TargetNotMock);
Expand All @@ -48,6 +45,11 @@ public IMethodReturn Execute(IMethodInvocation invocation, GetNextBehavior next)
// since they all share the same AppliesTo implementation, which is the setup
// itself.

// Regardless of the configured mock behaviors or subsequent pipeline behaviors,
// we have matched a call, meaning the strict mode behavior, if configured,
// should nevertheless *not* run, since we consider this a successfull match.
invocation.SkipBehaviors.Add(typeof(StrictMockBehavior));

if (Behaviors.Count == 0)
return next().Invoke(invocation, next);

Expand Down
Loading