Test out requesthandler

This commit is contained in:
Tim Clem
2012-04-28 12:44:12 -07:00
parent 90b88a6695
commit b5c93c1236
7 changed files with 85 additions and 26 deletions
+1
View File
@@ -56,6 +56,7 @@
<Compile Include="ApiObjectMapTests.cs" />
<Compile Include="Helpers\EnsureTests.cs" />
<Compile Include="Http\BuilderTests.cs" />
<Compile Include="Http\RequestHandlerTests.cs" />
<Compile Include="Http\ResponseHandlerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Helpers\StringExtensionsTests.cs" />
+57
View File
@@ -0,0 +1,57 @@
using System;
using System.Threading.Tasks;
using Burr.Http;
using FluentAssertions;
using Moq;
using Xunit;
namespace Burr.Tests.Http
{
public class RequestHandlerTests
{
public class MockRequestHandler : RequestHandler
{
public MockRequestHandler(IApplication app)
: base(app)
{
}
protected override void Before<T>(Env<T> env)
{
BeforeWasCalled = true;
}
public bool BeforeWasCalled { get; private set; }
}
public class TheConstructor
{
[Fact]
public void ThrowsForBadArguments()
{
Assert.Throws<ArgumentNullException>(() => new MockRequestHandler(null));
}
}
public class TheCallMethod
{
[Fact]
public async Task InvokesBefore()
{
var env = new Mock<Env<string>>();
var app = new Mock<IApplication>();
var handler = new MockRequestHandler(app.Object);
app.Setup(x => x.Call(env.Object))
.Returns(Task.FromResult(app.Object))
.Callback(() =>
{
handler.BeforeWasCalled.Should().BeTrue();
});
await handler.Call(env.Object);
app.Verify(x => x.Call(env.Object));
}
}
}
}
+1 -1
View File
@@ -1,9 +1,9 @@
using System;
using System.Threading.Tasks;
using Burr.Http;
using FluentAssertions;
using Moq;
using Xunit;
using FluentAssertions;
namespace Burr.Tests.Http
{
+1
View File
@@ -44,6 +44,7 @@
<Compile Include="Http\Connection.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Http\RequestHandler.cs" />
<Compile Include="Http\ResponseHandler.cs" />
<Compile Include="IApiObjectMap.cs" />
<Compile Include="ApiObjectMap.cs" />
-20
View File
@@ -2,10 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Burr.Helpers;
using Burr.SimpleJSON;
namespace Burr.Http
{
@@ -196,22 +194,4 @@ namespace Burr.Http
return this;
}
}
public abstract class RequestHandler : IApplication
{
protected RequestHandler(IApplication app)
{
App = app;
}
protected IApplication App { get; private set; }
public async Task<IApplication> Call<T>(Env<T> env)
{
Before(env);
return await App.Call(env);
}
protected abstract void Before<T>(Env<T> env);
}
}
+24
View File
@@ -0,0 +1,24 @@
using System.Threading.Tasks;
using Burr.Helpers;
namespace Burr.Http
{
public abstract class RequestHandler : IApplication
{
protected RequestHandler(IApplication app)
{
Ensure.ArgumentNotNull(app, "app");
App = app;
}
protected IApplication App { get; private set; }
public async Task<IApplication> Call<T>(Env<T> env)
{
Before(env);
return await App.Call(env);
}
protected abstract void Before<T>(Env<T> env);
}
}
+1 -5
View File
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Burr.Helpers;
namespace Burr.Http