Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Housekeeping #55

Merged
merged 9 commits into from
Apr 5, 2019
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
15 changes: 8 additions & 7 deletions appveyor.yml → .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,22 @@ build_script:

artifacts:
- path: src\**\*.nupkg
- path: test\TestResults
- path: TestResults_*.7z
name: TestResults

#---------------------------------#
# tests configuration #
#---------------------------------#

test_script:
- coverage.cmd %CONFIGURATION%
- "SET PATH=C:\\Python34;C:\\Python34\\Scripts;%PATH%"
- pip install codecov
- codecov -f "test\TestResults\Test.Coverage.xml"

after_test: |
FOR /r %%F IN (*coveralls.net.exe) DO SET coveralls_exe=%%F
%coveralls_exe% --opencover test\TestResults\Test.Coverage.xml
after_test:
- choco install codecov
- codecov -f "test\TestResults\Test.Coverage.xml"
- dotnet tool install -g coveralls.net --version 1.0.0
- IF DEFINED COVERALLS_REPO_TOKEN csmacnz.coveralls --opencover -i "./test/TestResults/Test.Coverage.xml" --treatUploadErrorsAsWarnings
- 7z a -t7z -mx9 -bd TestResults_%APPVEYOR_BUILD_VERSION%.7z .\test\TestResults\*

#---------------------------------#
# deployment configuration #
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Intercept(IInvocation invocation)

## What's not simple about asynchronous method interception?

When implementing `IInterceptor` the underlying the method is invoked like this:
When implementing `IInterceptor` the underlying method is invoked like this:

```csharp
public void Intercept(IInvocation invocation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private enum MethodType
}

/// <summary>
/// Gets the underlying async interceptor
/// Gets the underlying async interceptor.
/// </summary>
public IAsyncInterceptor AsyncInterceptor { get; }

Expand Down
17 changes: 12 additions & 5 deletions src/Castle.Core.AsyncInterceptor/AsyncInterceptorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public abstract class AsyncInterceptorBase : IAsyncInterceptor
#endif

private static readonly MethodInfo InterceptSynchronousMethodInfo =
typeof(AsyncInterceptorBase)
.GetMethod(nameof(InterceptSynchronousResult), BindingFlags.Static | BindingFlags.NonPublic);
typeof(AsyncInterceptorBase).GetMethod(
nameof(InterceptSynchronousResult),
BindingFlags.Static | BindingFlags.NonPublic);

private static readonly ConcurrentDictionary<Type, GenericSynchronousHandler> GenericSynchronousHandlers =
new ConcurrentDictionary<Type, GenericSynchronousHandler>
Expand Down Expand Up @@ -95,7 +96,10 @@ private static void InterceptSynchronousVoid(AsyncInterceptorBase me, IInvocatio
// If the intercept task has yet to complete, wait for it.
if (!task.IsCompleted)
{
Task.Run(() => task).Wait();
// Need to use Task.Run() to prevent deadlock in .NET Framework ASP.NET requests.
// GetAwaiter().GetResult() prevents a thrown exception being wrapped in a AggregateException.
// See https://stackoverflow.com/a/17284612
Task.Run(() => task).GetAwaiter().GetResult();
}

if (task.IsFaulted)
Expand All @@ -106,12 +110,15 @@ private static void InterceptSynchronousVoid(AsyncInterceptorBase me, IInvocatio

private static void InterceptSynchronousResult<TResult>(AsyncInterceptorBase me, IInvocation invocation)
{
Task task = me.InterceptAsync(invocation, ProceedSynchronous<TResult>);
Task<TResult> task = me.InterceptAsync(invocation, ProceedSynchronous<TResult>);

// If the intercept task has yet to complete, wait for it.
if (!task.IsCompleted)
{
Task.Run(() => task).Wait();
// Need to use Task.Run() to prevent deadlock in .NET Framework ASP.NET requests.
// GetAwaiter().GetResult() prevents a thrown exception being wrapped in a AggregateException.
// See https://stackoverflow.com/a/17284612
Task.Run(() => task).GetAwaiter().GetResult();
}

if (task.IsFaulted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<RepositoryType>git</RepositoryType>
<PackageTags>async asynchronous-methods castle castle-core dynamic dynamicproxy dynamic-proxy dynamicproxy2 intercept-methods proxy</PackageTags>
</PropertyGroup>

<!-- Strong name signing -->
<PropertyGroup>
<SignAssembly>true</SignAssembly>
Expand All @@ -36,7 +36,10 @@

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.2.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-rc.114">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Castle.DynamicProxy

/// <summary>
/// A base type for an <see cref="IAsyncInterceptor"/> which executes only minimal processing when intercepting a
/// method <see cref="IInvocation"/>
/// method <see cref="IInvocation"/>.
/// </summary>
/// <typeparam name="TState">
/// The type of the custom object used to maintain state between <see cref="StartingInvocation"/> and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Castle.DynamicProxy
using System.Linq;

/// <summary>
/// Extension methods to <see cref="IProxyGenerator"/>,
/// Extension methods to <see cref="IProxyGenerator"/>.
/// </summary>
public static class ProxyGeneratorExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Castle.DynamicProxy
public abstract class WhenExceptionInterceptingSynchronousVoidMethodsBase
{
private const string MethodName = nameof(IInterfaceToProxy.SynchronousVoidExceptionMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly IInterfaceToProxy _proxy;

protected WhenExceptionInterceptingSynchronousVoidMethodsBase(int msDelay)
Expand Down Expand Up @@ -78,7 +78,7 @@ public WhenExceptionInterceptingSynchronousVoidMethodsWithADelay() : base(10)
public abstract class WhenExceptionInterceptingSynchronousResultMethodsBase
{
private const string MethodName = nameof(IInterfaceToProxy.SynchronousResultExceptionMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly IInterfaceToProxy _proxy;

protected WhenExceptionInterceptingSynchronousResultMethodsBase(int msDelay)
Expand Down Expand Up @@ -143,7 +143,7 @@ public WhenExceptionInterceptingSynchronousResultMethodsWithADelay() : base(10)
public abstract class WhenExceptionInterceptingAsynchronousVoidMethodsBase
{
private const string MethodName = nameof(IInterfaceToProxy.AsynchronousVoidExceptionMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly IInterfaceToProxy _proxy;

protected WhenExceptionInterceptingAsynchronousVoidMethodsBase(int msDelay)
Expand Down Expand Up @@ -211,7 +211,7 @@ public WhenExceptionInterceptingAsynchronousVoidMethodsWithADelay() : base(10)
public abstract class WhenExceptionInterceptingAsynchronousResultMethodsBase
{
private const string MethodName = nameof(IInterfaceToProxy.AsynchronousResultExceptionMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly IInterfaceToProxy _proxy;

protected WhenExceptionInterceptingAsynchronousResultMethodsBase(int msDelay)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Castle.DynamicProxy
public abstract class WhenInterceptingSynchronousVoidMethodsBase
{
private const string MethodName = nameof(IInterfaceToProxy.SynchronousVoidMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly IInterfaceToProxy _proxy;

protected WhenInterceptingSynchronousVoidMethodsBase(int msDelay)
Expand Down Expand Up @@ -73,7 +73,7 @@ public WhenInterceptingSynchronousVoidMethodsWithADelay() : base(10)
public abstract class WhenInterceptingSynchronousResultMethodsBase
{
private const string MethodName = nameof(IInterfaceToProxy.SynchronousResultMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly IInterfaceToProxy _proxy;

protected WhenInterceptingSynchronousResultMethodsBase(int msDelay)
Expand Down Expand Up @@ -133,7 +133,7 @@ public WhenInterceptingSynchronousResultMethodsWithADelay() : base(10)
public abstract class WhenInterceptingAsynchronousVoidMethodsBase
{
private const string MethodName = nameof(IInterfaceToProxy.AsynchronousVoidMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly IInterfaceToProxy _proxy;

protected WhenInterceptingAsynchronousVoidMethodsBase(int msDelay)
Expand Down Expand Up @@ -193,7 +193,7 @@ public WhenInterceptingAsynchronousVoidMethodsWithADelay() : base(10)
public abstract class WhenInterceptingAsynchronousResultMethodsBase
{
private const string MethodName = nameof(IInterfaceToProxy.AsynchronousResultMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly IInterfaceToProxy _proxy;

protected WhenInterceptingAsynchronousResultMethodsBase(int msDelay)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static class ProxyGen
{
public static readonly IProxyGenerator Generator = new ProxyGenerator();

public static IInterfaceToProxy CreateProxy(List<string> log, IAsyncInterceptor interceptor)
public static IInterfaceToProxy CreateProxy(ListLogger log, IAsyncInterceptor interceptor)
{
// Arrange
var classWithInterfaceToProxy = new ClassWithInterfaceToProxy(log);
Expand All @@ -42,7 +42,7 @@ public static IInterfaceToProxy CreateProxy(List<string> log, IAsyncInterceptor
public class WhenInterceptingSynchronousVoidMethods
{
private const string MethodName = nameof(IInterfaceToProxy.SynchronousVoidMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly IInterfaceToProxy _proxy;

public WhenInterceptingSynchronousVoidMethods()
Expand Down Expand Up @@ -84,7 +84,7 @@ public void ShouldAllowInterceptionAfterInvocation()
public class WhenInterceptingSynchronousResultMethods
{
private const string MethodName = nameof(IInterfaceToProxy.SynchronousResultMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly IInterfaceToProxy _proxy;

public WhenInterceptingSynchronousResultMethods()
Expand Down Expand Up @@ -127,7 +127,7 @@ public void ShouldAllowInterceptionAfterInvocation()
public class WhenInterceptingAsynchronousVoidMethods
{
private const string MethodName = nameof(IInterfaceToProxy.AsynchronousVoidMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly IInterfaceToProxy _proxy;

public WhenInterceptingAsynchronousVoidMethods()
Expand Down Expand Up @@ -169,7 +169,7 @@ public async Task ShouldAllowInterceptionAfterInvocation()
public class WhenInterceptingAsynchronousResultMethods
{
private const string MethodName = nameof(IInterfaceToProxy.AsynchronousResultMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly IInterfaceToProxy _proxy;

public WhenInterceptingAsynchronousResultMethods()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Castle.DynamicProxy
public class WhenTimingSynchronousVoidMethods
{
private const string MethodName = nameof(IInterfaceToProxy.SynchronousVoidMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly TestAsyncTimingInterceptor _interceptor;
private readonly IInterfaceToProxy _proxy;

Expand Down Expand Up @@ -57,7 +57,7 @@ public void ShouldAllowTimingAfterInvocation()
public class WhenTimingSynchronousResultMethods
{
private const string MethodName = nameof(IInterfaceToProxy.SynchronousResultMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly TestAsyncTimingInterceptor _interceptor;
private readonly IInterfaceToProxy _proxy;

Expand Down Expand Up @@ -101,7 +101,7 @@ public void ShouldAllowTimingAfterInvocation()
public class WhenTimingAsynchronousVoidMethods
{
private const string MethodName = nameof(IInterfaceToProxy.AsynchronousVoidMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly TestAsyncTimingInterceptor _interceptor;
private readonly IInterfaceToProxy _proxy;

Expand Down Expand Up @@ -145,7 +145,7 @@ public async Task ShouldAllowTimingAfterInvocation()
public class WhenTimingAsynchronousResultMethods
{
private const string MethodName = nameof(IInterfaceToProxy.AsynchronousResultMethod);
private readonly List<string> _log = new List<string>();
private readonly ListLogger _log = new ListLogger();
private readonly TestAsyncTimingInterceptor _interceptor;
private readonly IInterfaceToProxy _proxy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="Moq" Version="4.7.145" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.analyzers" Version="0.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ namespace Castle.DynamicProxy.InterfaceProxies

public class ClassWithInterfaceToProxy : IInterfaceToProxy
{
private readonly List<string> _log;
private readonly ListLogger _log;

public ClassWithInterfaceToProxy(List<string> log)
public ClassWithInterfaceToProxy(ListLogger log)
{
_log = log ?? throw new ArgumentNullException(nameof(log));
}

public IReadOnlyList<string> Log => _log;
public IReadOnlyList<string> Log => _log.GetLog();

public void SynchronousVoidMethod()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ namespace Castle.DynamicProxy.InterfaceProxies

public class ClassWithVirtualMethodToProxy
{
private readonly List<string> _log;
private readonly ListLogger _log;

protected ClassWithVirtualMethodToProxy()
: this(new List<string>())
: this(new ListLogger())
{
}

public ClassWithVirtualMethodToProxy(List<string> log)
public ClassWithVirtualMethodToProxy(ListLogger log)
{
if (log == null)
throw new ArgumentNullException(nameof(log));

_log = log;
_log = log ?? throw new ArgumentNullException(nameof(log));
}

public IReadOnlyList<string> Log => _log;
public IReadOnlyList<string> Log => _log.GetLog();

public virtual async Task<Guid> AsynchronousResultMethod()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace Castle.DynamicProxy.InterfaceProxies

public class TestAsyncInterceptor : IAsyncInterceptor
{
private readonly ICollection<string> _log;
private readonly ListLogger _log;

public TestAsyncInterceptor(List<string> log)
public TestAsyncInterceptor(ListLogger log)
{
_log = log ?? throw new ArgumentNullException(nameof(log));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace Castle.DynamicProxy.InterfaceProxies
public class TestAsyncInterceptorBase : AsyncInterceptorBase
{
private readonly int _msDeley;
private readonly ICollection<string> _log;
private readonly ListLogger _log;

public TestAsyncInterceptorBase(List<string> log, int msDeley)
public TestAsyncInterceptorBase(ListLogger log, int msDeley)
{
_log = log ?? throw new ArgumentNullException(nameof(log));
_msDeley = msDeley;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace Castle.DynamicProxy.InterfaceProxies

public class TestAsyncTimingInterceptor : AsyncTimingInterceptor
{
private readonly ICollection<string> _log;
private readonly ListLogger _log;

public TestAsyncTimingInterceptor(List<string> log)
public TestAsyncTimingInterceptor(ListLogger log)
{
_log = log ?? throw new ArgumentNullException(nameof(log));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Castle.DynamicProxy.InterfaceProxies

public class TestProcessingAsyncInterceptor : ProcessingAsyncInterceptor<string>
{
private readonly ICollection<string> _log;
private readonly ListLogger _log;

public TestProcessingAsyncInterceptor(List<string> log, string randomValue)
public TestProcessingAsyncInterceptor(ListLogger log, string randomValue)
{
_log = log ?? throw new ArgumentNullException(nameof(log));
RandomValue = randomValue ?? throw new ArgumentNullException(nameof(randomValue));
Expand Down
Loading