Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
44 lines (34 sloc) 1.32 KB
using Castle.DynamicProxy;
using StronglyTypedContext.Exceptions;
using StronglyTypedContext.Specflow;
namespace StronglyTypedContext.Proxy
{
public class ProxyInterceptor : IInterceptor
{
private readonly IScenarioContext _scenarioContext;
private readonly IKeyGenerator _keyGenerator;
public ProxyInterceptor(IScenarioContext scenarioContext, IKeyGenerator keyGenerator)
{
_scenarioContext = scenarioContext;
_keyGenerator = keyGenerator;
}
public ProxyInterceptor() : this(new SpecFlowScenarioContext(), new KeyGenerator())
{
}
public void Intercept(IInvocation invocation)
{
if (invocation.Method == null || !invocation.Method.IsSpecialName)
throw new MethodsNotSupportOnInterfaceException();
var method = invocation.Method;
var key = _keyGenerator.GenerateKey(invocation.Method.DeclaringType, method);
if (method.ReturnType == typeof (void))
{
_scenarioContext.Add(key, invocation.Arguments[0]);
}
else
{
invocation.ReturnValue = _scenarioContext[key];
}
}
}
}
You can’t perform that action at this time.