Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pushing new changes

  • Loading branch information...
commit f7d3a41b4ff87b14ab951f0f13b717a6382b2a35 1 parent a7d68f2
@alexisatkinson alexisatkinson authored developwithpassion committed
View
118 product/nothinbutdotnetstore.specs/UrlFormattingVisitorSpecs.cs
@@ -0,0 +1,118 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Machine.Specifications;
+using developwithpassion.specifications.rhino;
+using developwithpassion.specifications.extensions;
+using nothinbutdotnetstore.web.core;
+using Rhino.Mocks;
+
+namespace nothinbutdotnetstore.specs
+{
+ public class UrlFormattingVisitorSpecs
+ {
+ public abstract class concern : Observes<UrlFormattingVisitor,
+ DefaultUrlFormattingVistor>
+ {
+ Establish c = () =>
+ {
+ builder = new StringBuilder();
+ provide_a_basic_sut_constructor_argument(builder);
+ };
+
+ protected static StringBuilder builder;
+ }
+
+ [Subject(typeof(DefaultUrlFormattingVistor))]
+ public class when_created_and_no_visits_have_been_made : concern
+ {
+ It should_return_an_empty_string_when_get_result_is_called = () =>
+ builder.ToString().ShouldEqual(string.Empty);
+ }
+
+
+
+
+ [Subject(typeof(DefaultUrlFormattingVistor))]
+ public class when_visiting_the_first_item : concern
+ {
+
+ Establish c = () =>
+ {
+ command_name = "anycommand";
+ token = new KeyValuePair<string, object>(string.Empty, command_name);
+ };
+
+ Because b = () =>
+ sut.process(token);
+
+ It should_append_to_the_builder_the_command_name_appended_with_dot_uk = () =>
+ builder.ToString().ShouldEqual(command_name + ".uk");
+
+ static KeyValuePair<string, object> token;
+ static string command_name;
+ }
+
+ [Subject(typeof(DefaultUrlFormattingVistor))]
+ public class when_visiting_two_items : concern
+ {
+ Establish c = () =>
+ {
+ command_name = "anycommand";
+ first_token = new KeyValuePair<string, object>(string.Empty, command_name);
+ key = "anykey";
+ value = "anyValue";
+ second_token = new KeyValuePair<string, object>(key, value);
+ };
+
+ Because b = () =>
+ {
+ sut.process(first_token);
+ after_first_token = builder.ToString();
+ sut.process(second_token);
+ };
+
+
+ It should_append_to_the_builder_a_question_mark_followed_by_the_key_value_pair = () =>
+ builder.ToString().ShouldEqual(after_first_token + "?" + key + "=" + value);
+
+
+ static string command_name;
+ static KeyValuePair<string, object> first_token;
+ static KeyValuePair<string, object> second_token;
+ static string after_first_token;
+ static string key;
+ static string value;
+ }
+
+ [Subject(typeof(DefaultUrlFormattingVistor))]
+ public class when_visiting_more_than_two_items : concern
+ {
+ Establish c = () =>
+ {
+ add_pipeline_behaviour_against_sut(x =>
+ {
+ x.process(new KeyValuePair<string, object>(string.Empty, "any_command"));
+ x.process(new KeyValuePair<string, object>("first_key", "first_value"));
+ });
+
+ subsequent_tokens =
+ Enumerable.Range(1, 5).Select(x => new KeyValuePair<string, object>("key_" + x.ToString(), x)).ToList();
+
+ };
+
+ Because b = () =>
+ subsequent_tokens.ForEach(token => sut.process(token));
+
+ It should_append_to_the_builder_a_question_mark_followed_by_the_key_value_pair = () => { };
+// builder.ToString().ShouldEqual(after_first_token + "?" + key + "=" + value);
+
+ static List<KeyValuePair<string, object>> subsequent_tokens;
+ }
+
+
+
+
+ }
+}
View
1  product/nothinbutdotnetstore.specs/nothinbutdotnetstore.specs.csproj
@@ -262,6 +262,7 @@ build from_ide</PostBuildEvent>
<Compile Include="PropertyExpressionTokenFactorySpecs.cs" />
<Compile Include="StartupSpecs.cs" />
<Compile Include="TokenStoreSpecs.cs" />
+ <Compile Include="UrlFormattingVisitorSpecs.cs" />
<Compile Include="VisitorExtensionsSpecs.cs" />
<Compile Include="FrontControllerSpecs.cs" />
<Compile Include="RenderingGatewaySpecs.cs" />
View
1  product/nothinbutdotnetstore.web.ui/nothinbutdotnetstore.web.ui.csproj
@@ -17,6 +17,7 @@
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation />
<TargetFrameworkProfile />
+ <UseIISExpress>false</UseIISExpress>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
View
1  product/nothinbutdotnetstore/nothinbutdotnetstore.csproj
@@ -264,6 +264,7 @@
<Compile Include="web\core\DefaultPropertyExpressionTokenFactory.cs" />
<Compile Include="web\core\DefaultRequestCommand.cs" />
<Compile Include="web\core\DefaultUrlBuilder.cs" />
+ <Compile Include="web\core\DefaultUrlFormattingVistor.cs" />
<Compile Include="web\core\FrontController.cs" />
<Compile Include="web\core\IncomingRequest.cs" />
<Compile Include="web\core\MissingCommandFactory.cs" />
View
30 product/nothinbutdotnetstore/web/core/DefaultUrlFormattingVistor.cs
@@ -0,0 +1,30 @@
+using System.Collections.Generic;
+using System.Text;
+
+namespace nothinbutdotnetstore.web.core
+{
+ public class DefaultUrlFormattingVistor : UrlFormattingVisitor
+ {
+ StringBuilder builder;
+
+ public DefaultUrlFormattingVistor(StringBuilder builder)
+ {
+ this.builder = builder;
+ }
+
+ public void process(KeyValuePair<string, object> item)
+ {
+ if(builder.Length == 0)
+ builder.AppendFormat("{0}.uk", item.Value);
+ else
+ {
+ builder.AppendFormat("?{0}={1}", item.Key, item.Value);
+ }
+ }
+
+ public string get_result()
+ {
+ return string.Empty;
+ }
+ }
+}

0 comments on commit f7d3a41

Please sign in to comment.
Something went wrong with that request. Please try again.