Skip to content

Commit

Permalink
adding test for exception in handler
Browse files Browse the repository at this point in the history
  • Loading branch information
G3N7 committed Jun 23, 2015
1 parent cdd93fa commit 21a361d
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 28 deletions.
24 changes: 15 additions & 9 deletions RailsSharp.Example/App/TestCtrl.js

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

2 changes: 1 addition & 1 deletion RailsSharp.Example/App/TestCtrl.js.map

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

31 changes: 21 additions & 10 deletions RailsSharp.Example/App/TestCtrl.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
interface ITestScope extends ng.IScope {
testState: TestState;
inititeSingleRequestAndResponseTest(): void;
}

class Status {
static Unknown = 'Unknown';
static Success = 'Success';
inititeRequestThatResultsInErrorTest(): void;
}

class TestState {
constructor() {
this.singleRequestAndResponse = Status.Unknown;
this.singleRequestAndResponse = false;
this.requestThatResultsInError = false;
}

singleRequestAndResponse: Status;

singleRequestAndResponse: boolean;
requestThatResultsInError: boolean;
}

// ReSharper disable once InconsistentNaming
Expand All @@ -27,9 +23,24 @@ function TestCtrl($scope: ITestScope, eventRegistry: jMess.IEventRegistry) {

eventRegistry.hook(TestEvents.TestSingleResponse,(reply: TestSingleResponse) => {
$scope.$apply(() => {
$scope.testState.singleRequestAndResponse = Status.Success;
$scope.testState.singleRequestAndResponse = true;
});
});

var errorTestRunning = false;
$scope.inititeRequestThatResultsInErrorTest = () => {
errorTestRunning = true;
eventRegistry.raise(TestEvents.TestFailedRequest, {});
}

eventRegistry.hook(ServerEvents.OnError,(error) => {
$scope.$apply(() => {
if (errorTestRunning) {
$scope.testState.requestThatResultsInError = true;
}
});
});

}

TestCtrl.$inject = ['$scope', 'eventRegistry'];
8 changes: 8 additions & 0 deletions RailsSharp.Example/App/TypeScriptEvents.js

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

2 changes: 1 addition & 1 deletion RailsSharp.Example/App/TypeScriptEvents.js.map

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

18 changes: 18 additions & 0 deletions RailsSharp.Example/App/TypeScriptEvents.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@


declare class TestFailedRequest {
}
declare class TestSingleRequest {
}
declare class TestSingleResponse {
Expand All @@ -10,6 +12,22 @@
static TestSingleRequest : string = 'TestTestSingleRequest';

static TestSingleResponse : string = 'TestTestSingleResponse';

static TestFailedRequest : string = 'TestTestFailedRequest';

static TestFailedResponse : string = 'TestTestFailedResponse';

static TestSingleLegacyRequest : string = 'TestTestSingleLegacyRequest';

static TestSingleLegacyResponse : string = 'TestTestSingleLegacyResponse';

static TestDoubleARequest : string = 'TestTestDoubleARequest';

static TestDoubleAResponse : string = 'TestTestDoubleAResponse';

static TestDoubleBRequest : string = 'TestTestDoubleBRequest';

static TestDoubleBResponse : string = 'TestTestDoubleBResponse';
}

var ServerEvents = {
Expand Down
1 change: 1 addition & 0 deletions RailsSharp.Example/App_Start/HandlerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class HandlerConfig
public static void RegisterHandlers(IHandlerRepository repository)
{
repository.AddHandler<TestSingleHandler>(TestEvents.TestSingleRequest);
repository.AddHandler<TestFailedHandler>(TestEvents.TestFailedRequest);
}
}
}
2 changes: 2 additions & 0 deletions RailsSharp.Example/RailsSharp.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@
<Compile Include="Startup.cs" />
<Compile Include="Test\AnyoneIsAllowedHandlerBase.cs" />
<Compile Include="Test\TestEvents.cs" />
<Compile Include="Test\TestFailedHandler.cs" />
<Compile Include="Test\TestFailedRequest.cs" />
<Compile Include="Test\TestSingleHandler.cs" />
<Compile Include="Test\TestSingleRequest.cs" />
<Compile Include="Test\TestSingleResponse.cs" />
Expand Down
4 changes: 2 additions & 2 deletions RailsSharp.Example/Test/AnyoneIsAllowedHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace RailsSharp.Example.Test
{
public abstract class AnyoneIsAllowedHandlerBase : HandlerBase<TestSingleRequest, IPrincipal>
public abstract class AnyoneIsAllowedHandlerBase<TRequest> : HandlerBase<TRequest, IPrincipal> where TRequest : RequestBase
{
protected override bool IsAuthorized(TestSingleRequest request, IPrincipal principal)
protected override bool IsAuthorized(TRequest request, IPrincipal principal)
{
return true;
}
Expand Down
8 changes: 8 additions & 0 deletions RailsSharp.Example/Test/TestEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@ public enum TestEvents
{
TestSingleRequest,
TestSingleResponse,
TestFailedRequest,
TestFailedResponse,
TestSingleLegacyRequest,
TestSingleLegacyResponse,
TestDoubleARequest,
TestDoubleAResponse,
TestDoubleBRequest,
TestDoubleBResponse,
}
}
13 changes: 13 additions & 0 deletions RailsSharp.Example/Test/TestFailedHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Security.Principal;

namespace RailsSharp.Example.Test
{
public class TestFailedHandler : AnyoneIsAllowedHandlerBase<TestFailedRequest>
{
protected override void Invoke(TestFailedRequest request, IPrincipal principal)
{
throw new Exception();
}
}
}
8 changes: 8 additions & 0 deletions RailsSharp.Example/Test/TestFailedRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using LAN.Core.Eventing;

namespace RailsSharp.Example.Test
{
public class TestFailedRequest : RequestBase
{
}
}
2 changes: 1 addition & 1 deletion RailsSharp.Example/Test/TestSingleHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace RailsSharp.Example.Test
{
public class TestSingleHandler : AnyoneIsAllowedHandlerBase
public class TestSingleHandler : AnyoneIsAllowedHandlerBase<TestSingleRequest>
{
private readonly IMessagingContext _messagingContext;

Expand Down
18 changes: 14 additions & 4 deletions RailsSharp.Example/Views/Home/Test.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@
<h3>Request/Response</h3>
<button class="btn btn-primary" ng-click="inititeSingleRequestAndResponseTest()">Send Request Expecting Single Reply to client.</button>
Result: <span class="glyphicon" ng-class="{
'glyphicon-cog': testState.singleRequestAndResponse === 'Unknown',
'text-warning': testState.singleRequestAndResponse === 'Unknown',
'glyphicon-check': testState.singleRequestAndResponse === 'Success',
'text-success': testState.singleRequestAndResponse === 'Success'}"></span>
'glyphicon-cog': !testState.singleRequestAndResponse,
'text-warning': !testState.singleRequestAndResponse,
'glyphicon-check': testState.singleRequestAndResponse,
'text-success': testState.singleRequestAndResponse}"></span>

<br />
<br />

<button class="btn btn-primary" ng-click="inititeRequestThatResultsInErrorTest()">Send Request Expecting unhandled exception to get returned to client.</button>
Result: <span class="glyphicon" ng-class="{
'glyphicon-cog': !testState.requestThatResultsInError,
'text-warning': !testState.requestThatResultsInError,
'glyphicon-check': testState.requestThatResultsInError,
'text-success': testState.requestThatResultsInError}"></span>

@* todo: test: group membership to stalwart group *@

Expand Down

0 comments on commit 21a361d

Please sign in to comment.