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 1 commit
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
Prev Previous commit
Next Next commit
Switch to design-time generated proxy for Moq tests
No need for the overhead of compile-time generated ones.
  • Loading branch information
kzu committed Jul 6, 2017
commit f9282a8ef4cf67062331d99743bfd4a9d6aae4e5
17 changes: 1 addition & 16 deletions test/Moq.Tests/Moq.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<ProjectGuid>9a09225f-e0bc-4890-bed4-d9f6f5dac146</ProjectGuid>
<IncludeXunit>true</IncludeXunit>
<IncludeXunit>true</IncludeXunit>
<AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies>

<GeneratorProps>..\..\src\Proxy\Proxy.Generator.Build\bin\$(Configuration)\Moq.Proxy.Generator.props</GeneratorProps>
<GeneratorTargets>..\..\src\Proxy\Proxy.Generator.Build\bin\$(Configuration)\Moq.Proxy.Generator.targets</GeneratorTargets>

<SdkProps>..\..\src\Sdk.Generator\bin\$(Configuration)\Moq.Sdk.Build.props</SdkProps>
<SdkTargets>..\..\src\Sdk.Generator\bin\$(Configuration)\Moq.Sdk.Build.targets</SdkTargets>
<PGenPath>..\..\src\Proxy\Proxy.Generator.Console\bin\$(Configuration)</PGenPath>
</PropertyGroup>
<Import Project="$(GeneratorProps)" Condition="Exists('$(GeneratorProps)')" />
<Import Project="$(SdkProps)" Condition="Exists('$(SdkProps)')" />

<ItemGroup>
<ProjectReference Include="..\..\src\Proxy\Proxy.Generator\Moq.Proxy.Generator.csproj" />
Expand All @@ -22,11 +13,5 @@
<ProjectReference Include="..\..\src\Moq\Moq.csproj" />
</ItemGroup>

<Target Name="EnsureGenerator" BeforeTargets="Build" Condition="!Exists('$(GeneratorTargets)') Or !Exists('$(SdkTargets)')">
<Error Text="Proxy.Generator or Moq.Sdk.Build hasn't been build. Please run build.cmd once before building this project.'" />
</Target>

<Import Project="$(GeneratorTargets)" Condition="Exists('$(GeneratorTargets)')" />
<Import Project="$(SdkTargets)" Condition="Exists('$(SdkTargets)')" />
<Import Project="..\Moq.Testing\Moq.Testing.projitems" Label="Shared" />
</Project>
60 changes: 60 additions & 0 deletions test/Moq.Tests/Proxies/ICalculatorProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Moq.Proxy;
using System.Runtime.CompilerServices;
using System.ComponentModel;
using System.Threading;
using Moq.Sdk;

namespace Proxies
{
[CompilerGenerated]
public partial class ICalculatorProxy : ICalculator, IProxy, IMocked
{
public string Mode
{
get => pipeline.Execute<string>(new MethodInvocation(this, MethodBase.GetCurrentMethod()));
set => pipeline.Execute(new MethodInvocation(this, MethodBase.GetCurrentMethod(), value));
}

public int Add(int a, int b) => pipeline.Execute<int>(new MethodInvocation(this, MethodBase.GetCurrentMethod(), a, b));
public void PowerUp() => pipeline.Execute(new MethodInvocation(this, MethodBase.GetCurrentMethod()));
public bool TryAdd(ref int x, ref int y, out int z)
{
z = default (int);
IMethodReturn returns = pipeline.Execute(new MethodInvocation(this, MethodBase.GetCurrentMethod(), x, y, z));
x = (int)returns.Outputs["x"];
y = (int)returns.Outputs["y"];
z = (int)returns.Outputs["z"];
return (bool)returns.ReturnValue;
}

public event PropertyChangedEventHandler PropertyChanged
{
add => pipeline.Execute<PropertyChangedEventHandler>(new MethodInvocation(this, MethodBase.GetCurrentMethod(), value));
remove => pipeline.Execute<PropertyChangedEventHandler>(new MethodInvocation(this, MethodBase.GetCurrentMethod(), value));
}

public event EventHandler<int> Progress
{
add => pipeline.Execute<EventHandler<int>>(new MethodInvocation(this, MethodBase.GetCurrentMethod(), value));
remove => pipeline.Execute<EventHandler<int>>(new MethodInvocation(this, MethodBase.GetCurrentMethod(), value));
}

public event EventHandler PoweringUp
{
add => pipeline.Execute<EventHandler>(new MethodInvocation(this, MethodBase.GetCurrentMethod(), value));
remove => pipeline.Execute<EventHandler>(new MethodInvocation(this, MethodBase.GetCurrentMethod(), value));
}

#region IProxy
BehaviorPipeline pipeline = new BehaviorPipeline();
IList<IProxyBehavior> IProxy.Behaviors => pipeline.Behaviors;
#endregion
#region IMocked
IMock mock;
IMock IMocked.Mock => LazyInitializer.EnsureInitialized(ref mock, () => new MockInfo(pipeline.Behaviors));
#endregion
}
}
2 changes: 1 addition & 1 deletion test/Sdk.Tests/GeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task CanGenerateProxies(string languageName)
References = ReferencePaths.Paths
.Concat(new[] { typeof(GeneratorTests).Assembly.ManifestModule.FullyQualifiedName })
.Select(x => new MSBuild.TaskItem(x)).ToArray(),
AdditionalGenerators = new[] { new MSBuild.TaskItem(typeof(CSharpPrepare).Assembly.ManifestModule.FullyQualifiedName) },
AdditionalGenerators = new[] { new MSBuild.TaskItem(typeof(CSharpMocked).Assembly.ManifestModule.FullyQualifiedName) },
AdditionalInterfaces = new[] { new MSBuild.TaskItem(typeof(IMocked).FullName) },
AdditionalProxies = new[] { new MSBuild.TaskItem(typeof(ICalculator).FullName) },
};
Expand Down