Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jweber committed Oct 14, 2014
2 parents 48113c2 + dca012d commit d61df79
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .semver
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
:major: 2
:minor: 0
:patch: 7
:patch: 8
:special: ''
4 changes: 2 additions & 2 deletions rakefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
desc 'Builds version environment variables'
task :versioning do
ver = SemVer.find
revision = (ENV['BUILD_NUMBER'] || ver.patch).to_i
#revision = (ENV['BUILD_NUMBER'] || ver.patch).to_i
#ver = SemVer.new(ver.major, ver.minor, revision, ver.special)

if ver.special != ''
Expand All @@ -125,7 +125,7 @@
ENV['NUGET_VERSION'] = NUGET_VERSION = ver.format("%M.%m.%p")
end

ENV['FORMAL_VERSION'] = FORMAL_VERSION = "#{ SemVer.new(ver.major, ver.minor, revision).format "%M.%m.%p"}"
ENV['FORMAL_VERSION'] = FORMAL_VERSION = "#{ ver.format("%M.%m.%p")}"
puts "##teamcity[buildNumber '#{BUILD_VERSION}']"
end

Expand Down
135 changes: 134 additions & 1 deletion source/WcfClientProxyGenerator.Tests/ProxyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,73 @@ public void HandleResponse_CanChangeResponse_ForSimpleResponseType()

Assert.That(response, Is.EqualTo("hello: test"));
}


[Test]
public void HandleResponse_ActionWithPredicate_CanInspectResponse_WithoutReturning()
{
var resetEvent = new AutoResetEvent(false);

var mockService = new Mock<ITestService>();

const string expectedInput = "test";

mockService
.Setup(m => m.TestMethod(expectedInput))
.Returns((string req) => req);

var serviceHost = InProcTestFactory.CreateHost<ITestService>(new TestServiceImpl(mockService));

var proxy = WcfClientProxy.Create<ITestService>(c =>
{
c.SetEndpoint(serviceHost.Binding, serviceHost.EndpointAddress);
c.HandleResponse<string>(where: r => r.StartsWith("te"), handler: r =>
{
Assert.That(r, Is.EqualTo(expectedInput));
resetEvent.Set();
});
});

var response = proxy.TestMethod(expectedInput);

Assert.That(response, Is.EqualTo(expectedInput));

if (!resetEvent.WaitOne(200))
Assert.Fail("Callback not fired");
}

[Test]
public void HandleResponse_ActionWithoutPredicate_CanInspectResponse_WithoutReturning()
{
var resetEvent = new AutoResetEvent(false);

var mockService = new Mock<ITestService>();

const string expectedInput = "test";

mockService
.Setup(m => m.TestMethod(expectedInput))
.Returns((string req) => req);

var serviceHost = InProcTestFactory.CreateHost<ITestService>(new TestServiceImpl(mockService));

var proxy = WcfClientProxy.Create<ITestService>(c =>
{
c.SetEndpoint(serviceHost.Binding, serviceHost.EndpointAddress);
c.HandleResponse<string>(handler: r =>
{
Assert.That(r, Is.EqualTo(expectedInput));
resetEvent.Set();
});
});

var response = proxy.TestMethod(expectedInput);

Assert.That(response, Is.EqualTo(expectedInput));

if (!resetEvent.WaitOne(200))
Assert.Fail("Callback not fired");
}

[Test]
public void HandleResponse_CanChangeResponse_ForComplexResponseType()
{
Expand Down Expand Up @@ -1495,6 +1561,73 @@ public void Async_HandleResponse_CanThrowException()
message: "test");
}


[Test]
public async Task Async_HandleResponse_ActionWithPredicate_CanInspectResponse_WithoutReturning()
{
var resetEvent = new AutoResetEvent(false);

var mockService = new Mock<ITestService>();

const string expectedInput = "test";

mockService
.Setup(m => m.TestMethod(expectedInput))
.Returns((string req) => req);

var serviceHost = InProcTestFactory.CreateHost<ITestService>(new TestServiceImpl(mockService));

var proxy = WcfClientProxy.CreateAsyncProxy<ITestService>(c =>
{
c.SetEndpoint(serviceHost.Binding, serviceHost.EndpointAddress);
c.HandleResponse<string>(where: r => r.StartsWith("te"), handler: r =>
{
Assert.That(r, Is.EqualTo(expectedInput));
resetEvent.Set();
});
});

var response = await proxy.CallAsync(m => m.TestMethod(expectedInput));

Assert.That(response, Is.EqualTo(expectedInput));

if (!resetEvent.WaitOne(200))
Assert.Fail("Callback not fired");
}

[Test]
public async Task Async_HandleResponse_ActionWithoutPredicate_CanInspectResponse_WithoutReturning()
{
var resetEvent = new AutoResetEvent(false);

var mockService = new Mock<ITestService>();

const string expectedInput = "test";

mockService
.Setup(m => m.TestMethod(expectedInput))
.Returns((string req) => req);

var serviceHost = InProcTestFactory.CreateHost<ITestService>(new TestServiceImpl(mockService));

var proxy = WcfClientProxy.CreateAsyncProxy<ITestService>(c =>
{
c.SetEndpoint(serviceHost.Binding, serviceHost.EndpointAddress);
c.HandleResponse<string>(handler: r =>
{
Assert.That(r, Is.EqualTo(expectedInput));
resetEvent.Set();
});
});

var response = await proxy.CallAsync(m => m.TestMethod(expectedInput));

Assert.That(response, Is.EqualTo(expectedInput));

if (!resetEvent.WaitOne(200))
Assert.Fail("Callback not fired");
}

#endregion

#endregion
Expand Down
21 changes: 21 additions & 0 deletions source/WcfClientProxyGenerator/IProxyConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ public interface IProxyConfigurator
/// </remarks>
ChannelFactory ChannelFactory { get; }

/// <summary>
/// Allows inspecting and modifying the <typeparamref name="TResponse"/> object
/// before returning the response to the calling method.
/// </summary>
/// <typeparam name="TResponse">Type or parent type/interface of the response</typeparam>
/// <param name="where">Predicate to filter responses based on its parameters</param>
/// <param name="handler">
/// Delegate that takes a <typeparamref name="TResponse"/>
/// </param>
void HandleResponse<TResponse>(Predicate<TResponse> where, Action<TResponse> handler);

/// <summary>
/// Allows inspecting and modifying the <typeparamref name="TResponse"/> object
/// before returning the response to the calling method.
/// </summary>
/// <typeparam name="TResponse">Type or parent type/interface of the response</typeparam>
/// <param name="handler">
/// Delegate that takes a <typeparamref name="TResponse"/>
/// </param>
void HandleResponse<TResponse>(Action<TResponse> handler);

/// <summary>
/// Allows inspecting and modifying the <typeparamref name="TResponse"/> object
/// before returning the response to the calling method.
Expand Down
34 changes: 34 additions & 0 deletions source/WcfClientProxyGenerator/RetryingWcfActionInvokerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,40 @@ public IActionInvoker<TServiceInterface> ActionInvoker
get { return _actionInvoker; }
}

/// <summary>
/// Allows inspecting and modifying the <typeparamref name="TResponse"/> object
/// before returning the response to the calling method.
/// </summary>
/// <typeparam name="TResponse">Type or parent type/interface of the response</typeparam>
/// <param name="where">Predicate to filter responses based on its parameters</param>
/// <param name="handler">
/// Delegate that takes a <typeparamref name="TResponse"/>
/// </param>
public void HandleResponse<TResponse>(Predicate<TResponse> @where, Action<TResponse> handler)
{
_actionInvoker.AddResponseHandler(r =>
{
handler(r);
return r;
}, @where);
}

/// <summary>
/// Allows inspecting and modifying the <typeparamref name="TResponse"/> object
/// before returning the response to the calling method.
/// </summary>
/// <typeparam name="TResponse">Type or parent type/interface of the response</typeparam>
/// <param name="handler">
/// Delegate that takes a <typeparamref name="TResponse"/>
/// </param>
public void HandleResponse<TResponse>(Action<TResponse> handler)
{
_actionInvoker.AddResponseHandler<TResponse>(r =>
{
handler(r);
return r;
}, null);
}

/// <summary>
/// Allows inspecting and modifying the <typeparamref name="TResponse"/> object
Expand Down

0 comments on commit d61df79

Please sign in to comment.