-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new BehaviorTracer for the redone instrumentation
- Loading branch information
1 parent
3bf5b31
commit a8d75f8
Showing
7 changed files
with
123 additions
and
6 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/FubuMVC.Core/Diagnostics/Instrumentation/BehaviorTracer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using FubuMVC.Core.Behaviors; | ||
using FubuMVC.Core.Registration.Nodes; | ||
|
||
namespace FubuMVC.Core.Diagnostics.Instrumentation | ||
{ | ||
public class BehaviorTracer : WrappingBehavior | ||
{ | ||
private readonly BehaviorNode _node; | ||
private readonly IChainExecutionLog _log; | ||
|
||
public BehaviorTracer(BehaviorNode node, IChainExecutionLog log) | ||
{ | ||
_node = node; | ||
_log = log; | ||
} | ||
|
||
protected override void invoke(Action action) | ||
{ | ||
_log.StartSubject(_node); | ||
|
||
try | ||
{ | ||
action(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_log.LogException(ex); | ||
throw; | ||
} | ||
finally | ||
{ | ||
_log.FinishSubject(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/FubuMVC.Core/Diagnostics/Instrumentation/IChainExecutionLog.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
|
||
namespace FubuMVC.Core.Diagnostics.Instrumentation | ||
{ | ||
public interface IChainExecutionLog | ||
{ | ||
void StartSubject(ISubject subject); | ||
void FinishSubject(); | ||
void LogException(Exception ex); | ||
void AddLog(object log); | ||
void Trace(string description, Action action); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/FubuMVC.Tests/Diagnostics/Instrumentation/BehaviorTracerTester.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using FubuMVC.Core.Behaviors; | ||
using FubuMVC.Core.Diagnostics.Instrumentation; | ||
using FubuMVC.Core.Registration.Nodes; | ||
using FubuMVC.Tests.Registration; | ||
using FubuMVC.Tests.TestSupport; | ||
using NUnit.Framework; | ||
using Rhino.Mocks; | ||
using Shouldly; | ||
|
||
namespace FubuMVC.Tests.Diagnostics.Instrumentation | ||
{ | ||
[TestFixture] | ||
public class BehaviorTracerTester : InteractionContext<FubuMVC.Core.Diagnostics.Instrumentation.BehaviorTracer> | ||
{ | ||
[Test] | ||
public void when_the_inner_behavior_runs_cleanly() | ||
{ | ||
var node = Wrapper.For<FakeBehavior>(); | ||
Services.Inject<BehaviorNode>(node); | ||
|
||
var inner = MockFor<IActionBehavior>(); | ||
ClassUnderTest.Inner = inner; | ||
|
||
ClassUnderTest.Invoke(); | ||
|
||
var log = MockFor<IChainExecutionLog>(); | ||
log.AssertWasCalled(x => x.StartSubject(node)); | ||
|
||
inner.AssertWasCalled(x => x.Invoke()); | ||
|
||
log.AssertWasCalled(x => x.FinishSubject()); | ||
|
||
} | ||
|
||
[Test] | ||
public void when_the_inner_behavior_throws_an_exception() | ||
{ | ||
var node = Wrapper.For<FakeBehavior>(); | ||
Services.Inject<BehaviorNode>(node); | ||
|
||
var ex = new DivideByZeroException(); | ||
var inner = MockFor<IActionBehavior>(); | ||
inner.Stub(x => x.Invoke()).Throw(ex); | ||
|
||
ClassUnderTest.Inner = inner; | ||
|
||
Exception<DivideByZeroException>.ShouldBeThrownBy(() => | ||
{ | ||
ClassUnderTest.Invoke(); | ||
}); | ||
|
||
|
||
|
||
var log = MockFor<IChainExecutionLog>(); | ||
log.AssertWasCalled(x => x.StartSubject(node)); | ||
|
||
inner.AssertWasCalled(x => x.Invoke()); | ||
log.AssertWasCalled(x => x.LogException(ex)); | ||
|
||
log.AssertWasCalled(x => x.FinishSubject()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters