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

Change the real proxies to support ref / out parameters #2

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
/src/ChannelAdam.Core.BehaviourSpecs/obj/Debug
/src/ChannelAdam.Core.BehaviourSpecs/ChannelAdam.Core.BehaviourSpecs.csproj.user
/src/ChannelAdam.Core/TransientFaultHandling.csproj.user
/src/.vs/ChannelAdam.Core/v15/Server/sqlite3
/src/.vs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,22 @@
</Compile>
<Compile Include="CommandingUnitSteps.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RealProxy.feature.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>RealProxy.feature</DependentUpon>
</Compile>
<Compile Include="RealProxyUnitTestSteps.cs" />
<Compile Include="StringExtensions.feature.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>StringExtensions.feature</DependentUpon>
</Compile>
<Compile Include="StringExtensionsUnitSteps.cs" />
<Compile Include="TestDoubles\ITestCalculatorToProxy.cs" />
<Compile Include="TestDoubles\TestCalculatorToProxy.cs" />
<Compile Include="TestDoubles\TestObjectForXmlStuff.cs" />
<Compile Include="TestDoubles\TestObjectRealProxy.cs" />
<Compile Include="XmlSerialisation.feature.cs">
<DependentUpon>XmlSerialisation.feature</DependentUpon>
<AutoGen>True</AutoGen>
Expand All @@ -108,6 +117,10 @@
<LastGenOutput>Commanding.feature.cs</LastGenOutput>
</None>
<None Include="packages.config" />
<None Include="RealProxy.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>RealProxy.feature.cs</LastGenOutput>
</None>
<None Include="StringExtensions.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>StringExtensions.feature.cs</LastGenOutput>
Expand Down
19 changes: 19 additions & 0 deletions src/ChannelAdam.Core.BehaviourSpecs/RealProxy.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Feature: Real Proxy

@UnitTest
Scenario: RealProxy - UT-01 - Should return a value when calling a function through the object real proxy
Given a proxied function with a return value
When the proxied function with a return value is called
Then the value returned from the proxied function with a return value has the correct return value

@UnitTest
Scenario: RealProxy - UT-02 - Should allow usage of ref parameters when calling a method through the object real proxy
Given a proxied method with ref parameters
When the proxied method with ref parameters is called
Then the ref parameters from the proxied method have the correct values

@UnitTest
Scenario: RealProxy - UT-03 - Should allow usage of in, out and ref parameters when calling a function through the object real proxy
Given a proxied function with in, out and ref parameters
When the proxied function with in, out and ref parameters is called
Then the return value, out and ref parameters from the proxied function have the correct values
142 changes: 142 additions & 0 deletions src/ChannelAdam.Core.BehaviourSpecs/RealProxy.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

122 changes: 122 additions & 0 deletions src/ChannelAdam.Core.BehaviourSpecs/RealProxyUnitTestSteps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using ChannelAdam.Core.BehaviourSpecs.TestDoubles;
using ChannelAdam.TestFramework.MSTest;
using TechTalk.SpecFlow;

namespace ChannelAdam.Core.BehaviourSpecs
{
[Binding]
[Scope(Feature = "Real Proxy")]
public class RealProxyUnitSteps : MoqTestFixture
{
#region Private Fields

private int _actualOutValue;
private int _actualReturnedValue;
private int _actualZAndRefResult;
private TestObjectRealProxy<ITestCalculatorToProxy> _calculatorRealProxy;
private int? _expectedOutValue;
private int? _expectedReturnedValue;
private int? _expectedZAndRefResult;
private ITestCalculatorToProxy _transparentCalculatorProxy;
private int _x;
private int _y;

#endregion Private Fields

#region Public Methods

[BeforeScenario]
public void BeforeScenario()
{
_calculatorRealProxy = new TestObjectRealProxy<ITestCalculatorToProxy>(new TestCalculatorToProxy());
_transparentCalculatorProxy = (ITestCalculatorToProxy)_calculatorRealProxy.GetTransparentProxy();

_x = 1;
_y = 2;
_actualZAndRefResult = 5;
Logger.Log($"INPUTS: x={_x} y={_y} z={_actualZAndRefResult}");
}

#endregion Public Methods

#region Given

[Given(@"a proxied function with a return value")]
public void GivenAProxiedFunctionWithAReturnValue()
{
_expectedReturnedValue = _x + _y;
_expectedOutValue = null;
_expectedZAndRefResult = null;
Logger.Log($"EXPECTED: return value={_expectedReturnedValue}");
}

[Given(@"a proxied function with in, out and ref parameters")]
public void GivenAProxiedFunctionWithInOutAndRefParameters()
{
_expectedReturnedValue = _expectedOutValue = _x + _y;
_expectedZAndRefResult = _x + _y + _actualZAndRefResult;
Logger.Log($"EXPECTED: return value={_expectedReturnedValue}, out value={_expectedOutValue}, ref result={_expectedZAndRefResult}");
}

[Given(@"a proxied method with ref parameters")]
public void GivenAProxiedMethodWithRefParameters()
{
_expectedReturnedValue = null;
_expectedOutValue = null;
_expectedZAndRefResult = _x + _y + _actualZAndRefResult;
Logger.Log($"EXPECTED: ref result={_expectedZAndRefResult}");
}

#endregion Given

#region When

[When(@"the proxied function with a return value is called")]
public void WhenTheProxiedFunctionWithAReturnValueIsCalled()
{
_actualReturnedValue = _transparentCalculatorProxy.AddFunction(_x, _y);
Logger.Log($"ACTUAL: return value={_actualReturnedValue}");
}

[When(@"the proxied function with in, out and ref parameters is called")]
public void WhenTheProxiedFunctionWithInOutAndRefParametersIsCalled()
{
_actualReturnedValue = _transparentCalculatorProxy.AddFunctionWithAllParams(_x, _y, ref _actualZAndRefResult, out _actualOutValue);
Logger.Log($"ACTUAL: return value={_actualReturnedValue}, out value={_actualOutValue}, ref result={_actualZAndRefResult}");
}

[When(@"the proxied method with ref parameters is called")]
public void WhenTheProxiedMethodWithRefParametersIsCalled()
{
_transparentCalculatorProxy.AddMethodWithRefParams(_x, _y, ref _actualZAndRefResult);
Logger.Log($"ACTUAL: ref result={_actualZAndRefResult}");
}

#endregion When

#region Then

[Then(@"the value returned from the proxied function with a return value has the correct return value")]
[Then(@"the ref parameters from the proxied method have the correct values")]
[Then(@"the return value, out and ref parameters from the proxied function have the correct values")]
public void ThenAssertResultingValuesFromTheProxiedFunction()
{
if (_expectedReturnedValue.HasValue)
{
LogAssert.AreEqual("return value", _expectedReturnedValue, _actualReturnedValue);
}

if (_expectedOutValue.HasValue)
{
LogAssert.AreEqual("out value", _expectedOutValue, _actualOutValue);
}

if (_expectedZAndRefResult.HasValue)
{
LogAssert.AreEqual("ref result", _expectedZAndRefResult, _actualZAndRefResult);
}
}

#endregion Then
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ChannelAdam.Core.BehaviourSpecs.TestDoubles
{
public interface ITestCalculatorToProxy
{
int AddFunction(int x, int y);
int AddFunctionWithAllParams(int x, int y, ref int zAndRefResult, out int outResult);
void AddMethodWithRefParams(int x, int y, ref int refResult);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace ChannelAdam.Core.BehaviourSpecs.TestDoubles
{
public class TestCalculatorToProxy : ITestCalculatorToProxy
{
public int AddFunction(int x, int y)
{
return x + y;
}

public void AddMethodWithRefParams(int x, int y, ref int zAndRefResult)
{
zAndRefResult = x + y + zAndRefResult;
}

public int AddFunctionWithAllParams(int x, int y, ref int zAndRefResult, out int outResult)
{
outResult = x + y;
zAndRefResult = x + y + zAndRefResult;
return outResult;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using ChannelAdam.Runtime.Remoting.Proxies;

namespace ChannelAdam.Core.BehaviourSpecs.TestDoubles
{
public class TestObjectRealProxy<TObjectToProxy> : DisposableObjectRealProxy<TObjectToProxy>
{
#region Public Fields

public readonly TObjectToProxy obj;

#endregion Public Fields

#region Public Constructors

public TestObjectRealProxy(TObjectToProxy objectToProxy)
{
this.obj = objectToProxy;
}

#endregion Public Constructors

#region Protected Properties

protected override object ProxiedObject
{
get
{
return this.obj;
}
}

#endregion Protected Properties
}
}
Loading