mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 03:16:11 +00:00
Test out requesthandler
This commit is contained in:
@@ -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" />
|
||||
|
||||
@@ -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,9 +1,9 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Burr.Http;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace Burr.Tests.Http
|
||||
{
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,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
|
||||
|
||||
Reference in New Issue
Block a user