forked from DarthFubuMVC/fubumvc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'spark-view-tokens' of https://github.com/jmarnold/fubumvc…
… into jmarnold-spark-view-tokens
- Loading branch information
Showing
2 changed files
with
167 additions
and
126 deletions.
There are no files selected for viewing
243 changes: 141 additions & 102 deletions
243
src/Spark.Web.FubuMVC.Tests/Registration/when_applying_action_and_view_filter.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,103 +1,142 @@ | |||
using System.Collections.Generic; | using System.Collections.Generic; | ||
using System.Linq; | using System.Linq; | ||
using FubuMVC.Core.Registration.Nodes; | using FubuMVC.Core.Registration.Nodes; | ||
using FubuMVC.Core.View; | using FubuMVC.Core.View; | ||
using NUnit.Framework; | using NUnit.Framework; | ||
using Rhino.Mocks; | using Rhino.Mocks; | ||
using Spark.Web.FubuMVC.Registration; | using Spark.Web.FubuMVC.Registration; | ||
using Spark.Web.FubuMVC.ViewCreation; | using Spark.Web.FubuMVC.ViewCreation; | ||
|
|
||
namespace Spark.Web.FubuMVC.Tests.Registration | namespace Spark.Web.FubuMVC.Tests.Registration | ||
{ | { | ||
[TestFixture] | [TestFixture] | ||
public class when_applying_action_and_view_filter : InteractionContext<ActionAndViewMatchedBySparkViewDescriptors> | public class when_applying_action_and_view_filter : InteractionContext<ActionAndViewMatchedBySparkViewDescriptors> | ||
{ | { | ||
private ActionCall _call; | private ActionCall _call; | ||
private SparkViewDescriptor _desciptor; | private SparkViewDescriptor _descriptor; | ||
private ViewBag _views; | private ViewBag _views; | ||
|
private SparkViewToken _token; | ||
protected override void beforeEach() |
|
||
{ | protected override void beforeEach() | ||
_call = ActionCall.For<SampleEndpoint>(e => e.Get(new SampleInput())); | { | ||
_desciptor = new SparkViewDescriptor | _call = ActionCall.For<SampleEndpoint>(e => e.Get(new SampleInput())); | ||
{ | _descriptor = newDescriptor(); | ||
Accessors = new List<SparkViewDescriptor.Accessor>(), |
|
||
Templates = new List<string>() | _token = new SparkViewToken(_call, _descriptor, "Sample", "Sample"); | ||
}; | _token.Descriptors.Add(_descriptor); | ||
var token = new SparkViewToken(_call, _desciptor, "Sample", "Sample"); |
|
||
token.Descriptors.Add(_desciptor); | _views = new ViewBag(new List<IViewToken> { _token }); | ||
|
} | ||
_views = new ViewBag(new List<IViewToken> { token }); |
|
||
} | protected SparkViewDescriptor newDescriptor() | ||
|
{ | ||
[Test] | return new SparkViewDescriptor | ||
public void should_return_empty_collection_when_action_call_returns_a_fubu_continuation() | { | ||
{ | Accessors = new List<SparkViewDescriptor.Accessor>(), | ||
var call = ActionCall.For<SampleEndpoint>(e => e.Post()); | Templates = new List<string>() | ||
|
}; | ||
ClassUnderTest | } | ||
.Apply(call, _views) |
|
||
.ShouldHaveCount(0); | [Test] | ||
} | public void should_return_empty_collection_when_action_call_returns_a_fubu_continuation() | ||
|
{ | ||
[Test] | var call = ActionCall.For<SampleEndpoint>(e => e.Post()); | ||
public void should_return_empty_collection_when_resolver_has_no_matching_policies() |
|
||
{ | ClassUnderTest | ||
MockFor<ISparkPolicyResolver>() | .Apply(call, _views) | ||
.Expect(resolver => resolver.HasMatchFor(_call)) | .ShouldHaveCount(0); | ||
.Return(false); | } | ||
|
|
||
ClassUnderTest | [Test] | ||
.Apply(_call, _views) | public void should_return_empty_collection_when_resolver_has_no_matching_policies() | ||
.ShouldHaveCount(0); | { | ||
} | MockFor<ISparkPolicyResolver>() | ||
|
.Expect(resolver => resolver.HasMatchFor(_call)) | ||
[Test] | .Return(false); | ||
public void should_return_empty_collection_when_no_desciptors_are_matched() |
|
||
{ | ClassUnderTest | ||
MockFor<ISparkPolicyResolver>() | .Apply(_call, _views) | ||
.Expect(resolver => resolver.HasMatchFor(_call)) | .ShouldHaveCount(0); | ||
.Return(true); | } | ||
|
|
||
MockFor<ISparkPolicyResolver>() | [Test] | ||
.Expect(resolver => resolver.ResolveViewLocator(_call)) | public void should_return_empty_collection_when_no_desciptors_are_matched() | ||
.Return(""); | { | ||
|
MockFor<ISparkPolicyResolver>() | ||
MockFor<ISparkPolicyResolver>() | .Expect(resolver => resolver.HasMatchFor(_call)) | ||
.Expect(resolver => resolver.ResolveViewName(_call)) | .Return(true); | ||
.Return(""); |
|
||
|
MockFor<ISparkPolicyResolver>() | ||
ClassUnderTest | .Expect(resolver => resolver.ResolveViewLocator(_call)) | ||
.Apply(_call, _views) | .Return(""); | ||
.ShouldHaveCount(0); |
|
||
} | MockFor<ISparkPolicyResolver>() | ||
|
.Expect(resolver => resolver.ResolveViewName(_call)) | ||
[Test] | .Return(""); | ||
public void should_return_single_view_token_when_desciptor_is_matched() |
|
||
{ | ClassUnderTest | ||
const string viewLocator = "TestFolder"; | .Apply(_call, _views) | ||
const string viewName = "Sample"; | .ShouldHaveCount(0); | ||
|
} | ||
_desciptor.Templates.Add(viewLocator + "\\" + viewName); |
|
||
|
[Test] | ||
MockFor<ISparkPolicyResolver>() | public void should_return_single_view_token_when_desciptor_is_matched() | ||
.Expect(resolver => resolver.HasMatchFor(_call)) | { | ||
.Return(true); | _descriptor.Templates.Add("TestFolder\\Sample.spark"); | ||
|
|
||
MockFor<ISparkPolicyResolver>() | MockFor<ISparkPolicyResolver>() | ||
.Expect(resolver => resolver.ResolveViewLocator(_call)) | .Expect(resolver => resolver.HasMatchFor(_call)) | ||
.Return(viewLocator); | .Return(true); | ||
|
|
||
MockFor<ISparkPolicyResolver>() | MockFor<ISparkPolicyResolver>() | ||
.Expect(resolver => resolver.ResolveViewName(_call)) | .Expect(resolver => resolver.ResolveViewLocator(_call)) | ||
.Return(viewName); | .Return("TestFolder"); | ||
|
|
||
var token = ClassUnderTest | MockFor<ISparkPolicyResolver>() | ||
.Apply(_call, _views) | .Expect(resolver => resolver.ResolveViewName(_call)) | ||
.FirstOrDefault(); | .Return("Sample"); | ||
|
|
||
token.ShouldNotBeNull(); | var token = ClassUnderTest | ||
token.Name.ShouldEqual(viewName); | .Apply(_call, _views) | ||
} | .FirstOrDefault(); | ||
} |
|
||
token.ShouldNotBeNull(); | |||
token.Name.ShouldEqual("Sample"); | |||
} | |||
|
|||
[Test] | |||
public void should_return_single_view_token_matched_on_policy_criteria() | |||
{ | |||
_descriptor.Templates.Add("Projects\\Dashboard.spark"); | |||
_descriptor.Templates.Add("Shared\\Application.spark"); | |||
|
|||
var descriptor2 = newDescriptor(); | |||
descriptor2.Templates.Add("Projects\\StoryMap.spark"); | |||
descriptor2.Templates.Add("Shared\\Application.spark"); | |||
_token.Descriptors.Add(descriptor2); | |||
|
|||
var descriptor3 = newDescriptor(); | |||
descriptor3.Templates.Add("Projects.spark"); | |||
descriptor3.Templates.Add("Shared\\Application.spark"); | |||
_token.Descriptors.Add(descriptor3); | |||
|
|||
|
|||
MockFor<ISparkPolicyResolver>() | |||
.Expect(resolver => resolver.HasMatchFor(_call)) | |||
.Return(true); | |||
|
|||
MockFor<ISparkPolicyResolver>() | |||
.Expect(resolver => resolver.ResolveViewLocator(_call)) | |||
.Return(""); | |||
|
|||
MockFor<ISparkPolicyResolver>() | |||
.Expect(resolver => resolver.ResolveViewName(_call)) | |||
.Return("Projects"); | |||
|
|||
ClassUnderTest | |||
.Apply(_call, _views) | |||
.FirstOrDefault() | |||
.ShouldNotBeNull(); | |||
} | |||
} | |||
} | } |
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