Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DarthFubuMVC/fubumvc
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed May 24, 2010
2 parents 8567d36 + 15cf1f2 commit f2a859c
Show file tree
Hide file tree
Showing 33 changed files with 7,258 additions and 138 deletions.
2 changes: 1 addition & 1 deletion rakefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
gittag = `git describe --long`.chomp # looks something like v0.1.0-63-g92228f4
gitnumberpart = /-(\d+)-/.match(gittag)
gitnumber = gitnumberpart.nil? ? '0' : gitnumberpart[1]
commit = (ENV["BUILD_VCS_NUMBER"].nil? ? `git log -1 --pretty=format:%H` : ENV["BUILD_VCS_NUMBER"])
commit = `git log -1 --pretty=format:%H`
rescue
commit = "git unavailable"
gitnumber = "0"
Expand Down
76 changes: 67 additions & 9 deletions src/FubuCore.Testing/UrlContextTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,92 @@ namespace FubuCore.Testing
[TestFixture]
public class UrlContextTester
{
private const string SERVER_BASE = "http://www.someserver/ignored/path";
/**************************************************************************
* These tests really only confirm the Stubbed behavior, which is only
* useful in the context of other tests.
*
* The real (live) behavior is tested via qunit in the FubuMVC.HelloWorld project.
* To run the test, start the FubuMVC.HelloWorld project and navigate to:
* http://localhost:52010/helloworld/IntegrationTests/run
*
* The source of the tests is in:
* FubuMVC.HelloWorld\Controllers\IntegrationTests\RunView.aspx
**************************************************************************/

[SetUp]
public void SetUp()
{
UrlContext.Stub();
UrlContext.Stub("/app");
}

[Test]
public void get_absolute_for_unrooted_url()
{
"someUrl".ToAbsoluteUrl().ShouldEqual("/app/someUrl");
}

[Test]
public void get_absolute_for_rooted_url()
{
"/folder/someUrl".ToAbsoluteUrl().ShouldEqual("/folder/someUrl");
}

[Test]
public void get_absolute_for_app_relative_url()
{
"~/someUrl".ToAbsoluteUrl().ShouldEqual("/app/someUrl");
}

[Test]
public void get_absolute_for_fully_qualified_url()
{
"http://somewhere.com/someUrl".ToAbsoluteUrl().ShouldEqual("http://somewhere.com/someUrl");
}


[Test]
public void get_server_Url_for_unrooted_url()
{
"someUrl".ToServerQualifiedUrl(SERVER_BASE).ShouldEqual("http://www.someserver/app/someUrl");
}

[Test]
public void get_server_Url_for_rooted_url()
{
"/folder/someUrl".ToServerQualifiedUrl(SERVER_BASE).ShouldEqual("http://www.someserver/folder/someUrl");
}

[Test]
public void get_server_Url_for_app_relative_url()
{
"~/someUrl".ToServerQualifiedUrl(SERVER_BASE).ShouldEqual("http://www.someserver/app/someUrl");
}

[Test]
public void get_url()
public void get_server_Url_for_fully_qualified_url()
{
UrlContext.GetUrl("someUrl").ShouldEqual("/someUrl");
"http://somewhere.com/someUrl".ToServerQualifiedUrl(SERVER_BASE).ShouldEqual("http://somewhere.com/someUrl");
}



[Test]
public void get_full_url()
public void get_path_for_unrooted_url()
{
UrlContext.GetFullUrl("~SomePath").ShouldEqual("/SomePath");
"someUrl".ToPhysicalPath().ShouldEqual(@"\app\someUrl");
}

[Test]
public void map_path()
public void get_path_for_rooted_url()
{
UrlContext.MapPath("~SomePath").ShouldEqual("/SomePath");
"/folder/someUrl".ToPhysicalPath().ShouldEqual(@"\folder\someUrl");
}

[Test]
public void physical_path()
public void get_path_for_app_relative_url()
{
UrlContext.PhysicalPath("~/SomePath").ShouldEqual("\\SomePath");
"~/someUrl".ToPhysicalPath().ShouldEqual(@"\app\someUrl");
}
}
}
2 changes: 1 addition & 1 deletion src/FubuCore/Binding/MapFromWebPathFamily.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ValueConverter Build(IValueConverterRegistry registry, PropertyInfo prope
var strVal = rawValue.PropertyValue as String;
return strVal.IsNotEmpty()
? strVal.MapPath()
? strVal.ToAbsoluteUrl()
: strVal;
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/FubuCore/Binding/MapWebToPhysicalPathFamily.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ValueConverter Build(IValueConverterRegistry registry, PropertyInfo prope
var strVal = rawValue.PropertyValue as String;
return strVal.IsNotEmpty()
? strVal.PhysicalPath()
? strVal.ToPhysicalPath()
: strVal;
};
}
Expand Down
4 changes: 3 additions & 1 deletion src/FubuCore/Binding/ModelBinderCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public IModelBinder BinderFor(Type modelType)
IModelBinder binder = _cache[modelType];
if (binder == null)
{
throw new FubuException(2200, "Could not determine an IModelBinder for input type {0}", modelType.AssemblyQualifiedName);
throw new FubuException(2200,
"Could not determine an IModelBinder for input type {0}. No model binders matched on this type. The standard model binder requires a parameterless constructor for the model type. Alternatively, you could implement your own IModelBinder which can process this model type.",
modelType.AssemblyQualifiedName);
}

return binder;
Expand Down
70 changes: 27 additions & 43 deletions src/FubuCore/UrlContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Web;
using System.Web.Hosting;

namespace FubuCore
{
Expand All @@ -11,10 +12,10 @@ static UrlContext()
Reset();
}

public static Func<string, string, string> Combine { get; private set; }
public static Func<string, string> ToAbsolute { get; private set; }
public static Func<string, string> ToFull { get; private set; }
public static Func<string, string> ToPhysicalPath { get; private set; }
private static Func<string, string, string> _combine { get; set; }
private static Func<string, string> _toAbsolute { get; set; }
private static Func<string, bool> _isAbsolute { get; set; }
private static Func<string, string> _mapPath { get; set; }

public static void Reset()
{
Expand All @@ -34,67 +35,50 @@ public static void Stub()

public static void Stub(string usingFakeUrl)
{
Combine = (basePath, subPath) => "{0}/{1}".ToFormat(basePath.TrimEnd('/'), subPath.TrimStart('/'));
ToAbsolute = path => Combine(usingFakeUrl, path.Replace("~", ""));
ToFull = path => Combine(usingFakeUrl, path.Replace("~", ""));
ToPhysicalPath =
virtPath => Combine(usingFakeUrl, virtPath).Replace("~", "").Replace("//", "/").Replace("/", "\\");
_combine = (basePath, subPath) => "{0}/{1}".ToFormat(basePath.TrimEnd('/'), subPath.TrimStart('/'));
_isAbsolute = path => path.StartsWith("/");
_toAbsolute = path => _isAbsolute(path) ? path : _combine(usingFakeUrl, path.Replace("~", ""));
_mapPath = virtPath => _toAbsolute(virtPath).Replace("~", "").Replace("//", "/").Replace("/", "\\");
}

public static void Live()
{
Combine = VirtualPathUtility.Combine;
ToAbsolute = path =>
{
string result = path.Replace("~", VirtualPathUtility.ToAbsolute("~"));
return result.StartsWith("//") ? result.Substring(1) : result;
};
ToFull = path =>
{
var baseUri = new Uri(HttpContext.Current.Request.Url.AbsoluteUri);
return new Uri(baseUri, ToAbsolute(path)).ToString();
};
ToPhysicalPath = HttpContext.Current.Server.MapPath;
_combine = VirtualPathUtility.Combine;
_toAbsolute = VirtualPathUtility.ToAbsolute;
_isAbsolute = VirtualPathUtility.IsAbsolute;
_mapPath = HostingEnvironment.MapPath;
}

public static string GetUrl(string url)
public static string ToAbsoluteUrl(this string url)
{
if (!url.StartsWith("~/") || !url.StartsWith("/"))
if (Uri.IsWellFormedUriString(url, UriKind.Absolute)) return url;
if (!_isAbsolute(url))
{
url = ("~/" + url).Replace("~//", "~/");
url = _combine("~", url);
}


return ToAbsolute(url);
}

public static string GetFullUrl(string path)
{
return ToFull(path);
return _toAbsolute(url);
}

public static string MapPath(this string webRelativePath)
public static string ToServerQualifiedUrl(this string relativeUrl, string serverBasedUrl)
{
return ToAbsolute(webRelativePath);
var baseUri = new Uri(serverBasedUrl);
return new Uri(baseUri, ToAbsoluteUrl(relativeUrl)).ToString();
}

public static string PhysicalPath(this string webRelativePath)
public static string ToPhysicalPath(this string webRelativePath)
{
return ToPhysicalPath(webRelativePath);
if (!_isAbsolute(webRelativePath))
{
webRelativePath = _combine("~", webRelativePath);
}
return _mapPath(webRelativePath);
}

public static string WithQueryStringValues(this string querystring, params object[] values)
{
return querystring.ToFormat(values.Select(value => value.ToString().UrlEncoded()).ToArray());
}

public static string ToFullUrl(this string relativeUrl, params object[] args)
{
string formattedUrl = (args == null) ? relativeUrl : relativeUrl.ToFormat(args);

return UrlContext.GetFullUrl(formattedUrl);
}

public static string UrlEncoded(this object target)
{
//properly encoding URI: http://blogs.msdn.com/yangxind/default.aspx
Expand Down
26 changes: 19 additions & 7 deletions src/FubuMVC.Core/Diagnostics/BehaviorGraphWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ public class BehaviorGraphWriter
{
private const string sourceControlUrlBase = "http://github.com/DarthFubuMVC/fubumvc/";
private const string sourceControlUrlFormat = sourceControlUrlBase + "commit/{0}";
public const string FUBU_INTERNAL_CLASS = "fubu-internal";
private readonly BehaviorGraph _graph;
private readonly IUrlRegistry _urls;
private readonly string _diagnosticsNamespace;

public BehaviorGraphWriter(BehaviorGraph graph, IUrlRegistry urls)
{
_graph = graph;
_urls = urls;
_diagnosticsNamespace = GetType().Namespace;
}

[UrlPattern("_fubu")]
[UrlPattern(DiagnosticUrlPolicy.DIAGNOSTICS_URL_ROOT)]
public HtmlDocument Index()
{
var ul = new HtmlTag("ul");
Expand Down Expand Up @@ -119,12 +122,21 @@ public HtmlDocument Chain(ChainRequest chainRequest)
header.Header("Description");
header.Header("Type");
});
behaviorChain.Each(node => nodeTable.AddBodyRow(row =>
foreach (var node in behaviorChain)
{
row.Cell().Text(node.Category.ToString());
row.Cell().Text(node.ToString());
row.Cell().Text(node.GetType().FullName);
}));

var description = node.ToString();
nodeTable.AddBodyRow(row =>
{
row.Cell().Text(node.Category.ToString());
row.Cell().Text(description);
row.Cell().Text(node.GetType().FullName);
if (description.Contains(_diagnosticsNamespace))
{
row.AddClass(FUBU_INTERNAL_CLASS);
}
});
}


var logDiv = new HtmlTag("div").AddClass("convention-log");
Expand Down Expand Up @@ -274,7 +286,7 @@ private HtmlTag writeTable(IEnumerable<BehaviorChain> chains, params IColumn[] c
{
columns.Each(col =>
{
col.WriteBody(chain, row.Cell());
col.WriteBody(chain, row, row.Cell());
});
});
});
Expand Down
6 changes: 4 additions & 2 deletions src/FubuMVC.Core/Diagnostics/DiagnosticUrlPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace FubuMVC.Core.Diagnostics
{
public class DiagnosticUrlPolicy : IUrlPolicy
{
public const string DIAGNOSTICS_URL_ROOT = "_fubu";

public bool Matches(ActionCall call, IConfigurationObserver log)
{
return call.HandlerType == typeof (BehaviorGraphWriter);
Expand All @@ -18,7 +20,7 @@ public IRouteDefinition Build(ActionCall call)
{
MethodInfo method = call.Method;
var definition = call.ToRouteDefinition();
definition.Append("_fubu/" + UrlFor(method));
definition.Append(DIAGNOSTICS_URL_ROOT + "/" + UrlFor(method));
if (call.InputType().CanBeCastTo<ChainRequest>())
{
definition.AddRouteInput(new RouteInput(ReflectionHelper.GetAccessor<ChainRequest>(x => x.Id)), true);
Expand All @@ -33,7 +35,7 @@ public static string UrlFor(MethodInfo method)

public static string RootUrlFor(MethodInfo method)
{
return UrlContext.GetFullUrl("~/_fubu/" + UrlFor(method));
return ("~/" + DIAGNOSTICS_URL_ROOT + "/" + UrlFor(method)).ToAbsoluteUrl();
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/FubuMVC.Core/Diagnostics/HtmlWriting/ActionColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public string Header()
return "Action(s)";
}

public void WriteBody(BehaviorChain chain, HtmlTag cell)
public void WriteBody(BehaviorChain chain, HtmlTag row, HtmlTag cell)
{
string text = Text(chain);

Expand Down
2 changes: 1 addition & 1 deletion src/FubuMVC.Core/Diagnostics/HtmlWriting/ChainColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public string Header()
return "Chain";
}

public void WriteBody(BehaviorChain chain, HtmlTag cell)
public void WriteBody(BehaviorChain chain, HtmlTag row, HtmlTag cell)
{
cell.Child(new LinkTag(Text(chain), "chain/" + chain.UniqueId).AddClass("chainId"));
}
Expand Down
2 changes: 1 addition & 1 deletion src/FubuMVC.Core/Diagnostics/HtmlWriting/IColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace FubuMVC.Core.Diagnostics.HtmlWriting
public interface IColumn
{
string Header();
void WriteBody(BehaviorChain chain, HtmlTag cell);
void WriteBody(BehaviorChain chain, HtmlTag row, HtmlTag cell);
string Text(BehaviorChain chain);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public string Header()
return "Input Model";
}

public void WriteBody(BehaviorChain chain, HtmlTag cell)
public void WriteBody(BehaviorChain chain, HtmlTag row, HtmlTag cell)
{
Type inputType = chain.ActionInputType();

Expand Down
2 changes: 1 addition & 1 deletion src/FubuMVC.Core/Diagnostics/HtmlWriting/OutputColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public string Header()
return "Output(s)";
}

public void WriteBody(BehaviorChain chain, HtmlTag cell)
public void WriteBody(BehaviorChain chain, HtmlTag row, HtmlTag cell)
{
cell.Text(Text(chain));
}
Expand Down
6 changes: 5 additions & 1 deletion src/FubuMVC.Core/Diagnostics/HtmlWriting/RouteColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ public string Header()
return "Route";
}

public void WriteBody(BehaviorChain chain, HtmlTag cell)
public void WriteBody(BehaviorChain chain, HtmlTag row, HtmlTag cell)
{
string text = Text(chain);
cell.Text(text);
if (text.StartsWith(DiagnosticUrlPolicy.DIAGNOSTICS_URL_ROOT))
{
row.AddClass(BehaviorGraphWriter.FUBU_INTERNAL_CLASS);
}
}

public string Text(BehaviorChain chain)
Expand Down
Loading

0 comments on commit f2a859c

Please sign in to comment.