public void SetUp() { Layout = null; PropertyBag = new Hashtable(StringComparer.InvariantCultureIgnoreCase); Helpers = new HelperDictionary(); var services = new StubMonoRailServices { UrlBuilder = new DefaultUrlBuilder(new StubServerUtility(), new StubRoutingEngine()), UrlTokenizer = new DefaultUrlTokenizer() }; var urlInfo = new UrlInfo( "example.org", "test", "/TestBrail", "http", 80, "http://test.example.org/test_area/test_controller/test_action.tdd", Area, ControllerName, Action, "tdd", "no.idea"); StubEngineContext = new StubEngineContext(new StubRequest(), new StubResponse(), services, urlInfo); StubEngineContext.AddService<IUrlBuilder>(services.UrlBuilder); StubEngineContext.AddService<IUrlTokenizer>(services.UrlTokenizer); ViewComponentFactory = new DefaultViewComponentFactory(); ViewComponentFactory.Service(StubEngineContext); ViewComponentFactory.Initialize(); StubEngineContext.AddService<IViewComponentFactory>(ViewComponentFactory); ControllerContext = new ControllerContext { Helpers = Helpers, PropertyBag = PropertyBag }; StubEngineContext.CurrentControllerContext = ControllerContext; Helpers["formhelper"] = Helpers["form"] = new FormHelper(StubEngineContext); Helpers["urlhelper"] = Helpers["url"] = new UrlHelper(StubEngineContext); Helpers["dicthelper"] = Helpers["dict"] = new DictHelper(StubEngineContext); Helpers["DateFormatHelper"] = Helpers["DateFormat"] = new DateFormatHelper(StubEngineContext); var viewPath = Path.Combine(viewSourcePath, "Views"); var loader = new FileAssemblyViewSourceLoader(viewPath); loader.AddAssemblySource( new AssemblySourceInfo(Assembly.GetExecutingAssembly().FullName, "Castle.MonoRail.Views.Brail.Tests.ResourcedViews")); BooViewEngine = new BooViewEngine { Options = new BooViewEngineOptions { SaveDirectory = Environment.CurrentDirectory, SaveToDisk = false, Debug = true, BatchCompile = false } }; BooViewEngine.SetViewSourceLoader(loader); BooViewEngine.Initialize(); BeforEachTest(); }
/// <summary> /// Initializes a new instance of the <see cref="MockRailsEngineContext"/> class. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> /// <param name="trace">The trace.</param> /// <param name="urlInfo">The URL info.</param> public MockRailsEngineContext(IRequest request, IResponse response, ITrace trace, UrlInfo urlInfo) : this() { this.request = request; this.response = response; this.trace = trace; this.urlInfo = urlInfo; }
public void OverridingArea() { var url = new UrlInfo("", "controller", "action", "", ".castle"); Assert.AreEqual("/admin/cars/new.castle", urlBuilder.BuildUrl(url, DictHelper.Create("area=admin", "controller=cars", "action=new"))); }
public void UsesMoreThanASingleLevelAppPath() { var url = new UrlInfo("", "controller", "action", "/app/some", ".castle"); Assert.AreEqual("/app/some/controller/new.castle", urlBuilder.BuildUrl(url, DictHelper.Create("action=new"))); }
public void SetUp() { string siteRoot = GetSiteRoot(); string viewPath = Path.Combine(siteRoot, "RenderingTests\\Views"); Layout = null; PropertyBag = new Hashtable(StringComparer.InvariantCultureIgnoreCase); Helpers = new HelperDictionary(); StubMonoRailServices services = new StubMonoRailServices(); services.UrlBuilder = new DefaultUrlBuilder(new StubServerUtility(), new StubRoutingEngine()); services.UrlTokenizer = new DefaultUrlTokenizer(); UrlInfo urlInfo = new UrlInfo( "example.org", "test", "/TestBrail", "http", 80, "http://test.example.org/test_area/test_controller/test_action.tdd", Area, ControllerName, Action, "tdd", "no.idea"); StubEngineContext = new StubEngineContext(new StubRequest(), new StubResponse(), services, urlInfo); StubEngineContext.AddService<IUrlBuilder>(services.UrlBuilder); StubEngineContext.AddService<IUrlTokenizer>(services.UrlTokenizer); StubEngineContext.AddService<IViewComponentFactory>(ViewComponentFactory); StubEngineContext.AddService<ILoggerFactory>(new ConsoleFactory()); StubEngineContext.AddService<IViewSourceLoader>(new FileAssemblyViewSourceLoader(viewPath)); ViewComponentFactory = new DefaultViewComponentFactory(); ViewComponentFactory.Service(StubEngineContext); ViewComponentFactory.Initialize(); ControllerContext = new ControllerContext(); ControllerContext.Helpers = Helpers; ControllerContext.PropertyBag = PropertyBag; StubEngineContext.CurrentControllerContext = ControllerContext; Helpers["urlhelper"] = Helpers["url"] = new UrlHelper(StubEngineContext); Helpers["htmlhelper"] = Helpers["html"] = new HtmlHelper(StubEngineContext); Helpers["dicthelper"] = Helpers["dict"] = new DictHelper(StubEngineContext); Helpers["DateFormatHelper"] = Helpers["DateFormat"] = new DateFormatHelper(StubEngineContext); //FileAssemblyViewSourceLoader loader = new FileAssemblyViewSourceLoader(viewPath); // loader.AddAssemblySource( // new AssemblySourceInfo(Assembly.GetExecutingAssembly().FullName, // "Castle.MonoRail.Views.Brail.Tests.ResourcedViews")); viewEngine = new AspViewEngine(); viewEngine.Service(StubEngineContext); AspViewEngineOptions options = new AspViewEngineOptions(); options.CompilerOptions.AutoRecompilation = true; options.CompilerOptions.KeepTemporarySourceFiles = false; ICompilationContext context = new CompilationContext( new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory), new DirectoryInfo(siteRoot), new DirectoryInfo(Path.Combine(siteRoot, "RenderingTests\\Views")), new DirectoryInfo(siteRoot)); List<ICompilationContext> compilationContexts = new List<ICompilationContext>(); compilationContexts.Add(context); viewEngine.Initialize(compilationContexts, options); }
public void InheritsControllerAndAreaWhenCreatingUrl() { var url = new UrlInfo("", "controller", "action", "", ".castle"); Assert.AreEqual("/controller/new.castle", urlBuilder.BuildUrl(url, DictHelper.Create("action=new"))); }
public void UsesAppPath() { UrlInfo url = new UrlInfo("", "controller", "action", "/app", ".castle"); Assert.AreEqual("/app/controller/new.castle", urlBuilder.BuildUrl(url, DictHelper.Create("action=new"))); }
public virtual void Setup() { response = new StubResponse(); var url = new UrlInfo("eleutian.com", "www", virtualDirectory, "http", 80, Path.Combine(Path.Combine("Area", "Controller"), "Action"), "Area", "Controller", "Action", "rails", ""); var stubEngineContext = new StubEngineContext(new StubRequest(), response, new StubMonoRailServices(), url) { Server = MockRepository.GenerateMock<IServerUtility>() }; railsContext = stubEngineContext; serverUtility = railsContext.Server; argumentConversionService = MockRepository.GenerateMock<IArgumentConversionService>(); controller = new TestController(); controller.Contextualize(railsContext, MockRepository.GenerateStub<IControllerContext>()); parameters = new Hashtable(); services = MockRepository.GenerateMock<ICodeGeneratorServices>(); services.Expect(s => s.ArgumentConversionService).Return(argumentConversionService).Repeat.Any(); services.Expect(s => s.Controller).Return(controller).Repeat.Any(); services.Expect(s => s.RailsContext).Return(railsContext).Repeat.Any(); argumentConversionService.Expect(s => s.CreateParameters()).Return(parameters).Repeat.Any(); }
/// <summary> /// Initializes a new instance of the <see cref="BaseResponse"/> class. /// </summary> /// <param name="currentUrl">The current URL.</param> /// <param name="urlBuilder">The URL builder.</param> /// <param name="serverUtility">The server utility.</param> /// <param name="routeMatch">The route match.</param> /// <param name="referrer">The referrer.</param> protected BaseResponse(UrlInfo currentUrl, IUrlBuilder urlBuilder, IServerUtility serverUtility, RouteMatch routeMatch, string referrer) { this.currentUrl = currentUrl; this.urlBuilder = urlBuilder; this.serverUtility = serverUtility; this.routeMatch = routeMatch; this.referrer = referrer; }
/// <summary> /// Adds the default rule mapping. /// </summary> /// <remarks> /// A defautl rule can associate something like a 'default.castle' /// to a controller/action like 'Home/index.castle' /// </remarks> /// <param name="url">The URL.</param> /// <param name="area">The area.</param> /// <param name="controller">The controller.</param> /// <param name="action">The action.</param> public void AddDefaultRule(string url, string area, string controller, string action) { if (area == null) { area = string.Empty; } defaultUrl2CustomUrlInfo[url] = new UrlInfo(area, controller, action); }
public static UrlSharer.UrlInfo GetDate() { UrlInfo uInfo = new UrlInfo(); uInfo.Description = "test"; uInfo.Title = "test"; uInfo.Images = new List<string>(); uInfo.Images.Add("http://google.com"); return uInfo; }
public DefaultUrlBuilderTestCase() { DefaultUrlTokenizer tokenizer = new DefaultUrlTokenizer(); noAreaUrl = tokenizer.TokenizeUrl("/home/index.rails", new Uri("http://localhost/home/index.rails"), true, "/"); areaUrl = tokenizer.TokenizeUrl("/area/home/index.rails", new Uri("http://localhost/area/home/index.rails"), true, "/"); withSubDomain = tokenizer.TokenizeUrl("/app/home/index.rails", new Uri("http://sub.domain.com/app/home/index.rails"), false, "/app"); diffPort = tokenizer.TokenizeUrl("/app/home/index.rails", new Uri("http://localhost:81/app/home/index.rails"), false, "/app"); }
/// <summary> /// Initializes a new instance of the <see cref="StubEngineContext"/> class. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> /// <param name="services">The services.</param> /// <param name="urlInfo">The URL info.</param> public StubEngineContext(IMockRequest request, IMockResponse response, IMonoRailServices services, UrlInfo urlInfo) { this.request = request; this.response = response; this.services = services; this.urlInfo = urlInfo; if (response != null) { response.UrlInfo = urlInfo; response.UrlBuilder = services.UrlBuilder; } }
private void bindShow( ContentPost post ) { ctx.SetItem( "ContentPost", post ); set( "post.Title", post.Title ); set( "post.CreateTime", post.Created ); set( "post.ReplyCount", post.Replies ); set( "post.Source", post.SourceLink ); set( "post.Hits", post.Hits ); String siteUrl = new UrlInfo( post.SourceLink ).SiteUrl; set( "post.Source", siteUrl ); String val = WebHelper.GetFlash( post.SourceLink, 500, 400 ); set( "post.Content", val ); }
public MunzeeDfxAtForm(Framework.Interfaces.ICore core): this() { _core = core; this.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_TITLE); this.groupBox3.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_MUNZEECOMACCOUNT); this.groupBox2.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_SELECTURL); this.groupBox1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_ADD); this.label7.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_NAME); this.label1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_URLS); this.button2.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_ADD); this.button3.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_REMOVE); this.button4.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_OK); this.label2.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_URL); this.label5.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_COMMENT); this.label6.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_INFO); textBox3.Text = Properties.Settings.Default.AccountName; try { _urlsFile = System.IO.Path.Combine( _core.PluginDataPath, "MunzeeDfxAt.xml" ); if (System.IO.File.Exists(_urlsFile)) { XmlDocument doc = new XmlDocument(); doc.Load(_urlsFile); XmlElement root = doc.DocumentElement; XmlNodeList bmNodes = root.SelectNodes("url"); if (bmNodes != null) { foreach (XmlNode n in bmNodes) { UrlInfo bm = new UrlInfo(); bm.Url = n.SelectSingleNode("Url").InnerText; bm.Comment = n.SelectSingleNode("Comment").InnerText; _urlInfos.Add(bm); } } listBox1.Items.AddRange(_urlInfos.ToArray()); } } catch { } }
public void test() { Uri uri = new Uri( "http://*****:*****@www.wojilu.net/myapp/Photo/1984?title=eee#top" ); UrlInfo u = new UrlInfo( uri, "/myapp/", "myPathInfo" ); Console.WriteLine( "Scheme=>" + u.Scheme ); Console.WriteLine( "UserName=>" + u.UserName ); Console.WriteLine( "Password=>" + u.Password ); Console.WriteLine( "Host=>" + u.Host ); Console.WriteLine( "Port=>" + u.Port ); Console.WriteLine( "Path=>" + u.Path ); Console.WriteLine( "PathAndQuery=>" + u.PathAndQuery ); Console.WriteLine( "PathInfo=>" + u.PathInfo ); Console.WriteLine( "AppPath=>" + u.AppPath ); Console.WriteLine( "PathAndQueryWithouApp=>" + u.PathAndQueryWithouApp ); Console.WriteLine( "Query=>" + u.Query ); Console.WriteLine( "Fragment=>" + u.Fragment ); Console.WriteLine( "SiteUrl=>" + u.SiteUrl ); Console.WriteLine( "SiteAndAppPath=>" + u.SiteAndAppPath ); Console.WriteLine( "ToString=>" + u.ToString() ); /* Scheme=>http UserName=>zhangsan Password=>123 Host=>www.wojilu.net Port=>80 Path=>/myapp/Photo/1984 PathAndQuery=>/myapp/Photo/1984?title=eee PathInfo=>myPathInfo AppPath=>/myapp/ PathAndQueryWithouApp=>/Photo/1984?title=eee Query=>?title=eee Fragment=>#top SiteUrl=>http://zhangsan:[email protected] SiteAndAppPath=>http://zhangsan:[email protected]/myapp/ ToString=>http://zhangsan:[email protected]/myapp/Photo/1984?title=eee#top */ }
/// <summary> /// 解析URL /// </summary> /// <param name="url"></param> /// <returns></returns> public static UrlInfo ParseURL(string url) { UrlInfo urlInfo = new UrlInfo(); string[] strTemp = null; urlInfo.Host = ""; urlInfo.Port = 80; urlInfo.File = "/"; urlInfo.Body = ""; int intIndex = url.ToLower().IndexOf("http://"); if (intIndex != -1) { url = url.Substring(7); intIndex = url.IndexOf("/"); if (intIndex == -1) { urlInfo.Host = url; } else { urlInfo.Host = url.Substring(0, intIndex); url = url.Substring(intIndex); intIndex = urlInfo.Host.IndexOf(":"); if (intIndex != -1) { strTemp = urlInfo.Host.Split(':'); urlInfo.Host = strTemp[0]; int.TryParse(strTemp[1], out urlInfo.Port); } intIndex = url.IndexOf("?"); if (intIndex == -1) { urlInfo.File = url; } else { strTemp = url.Split('?'); urlInfo.File = strTemp[0]; urlInfo.Body = strTemp[1]; } } } return urlInfo; }
private void bindShow( ContentPost post ) { ctx.SetItem( "ContentPost", post ); set( "post.Title", post.Title ); set( "post.CreateTime", post.Created ); set( "post.ReplyCount", post.Replies ); set( "post.Source", post.SourceLink ); set( "post.Hits", post.Hits ); if (post.Creator != null) { set( "post.Submitter", string.Format( "<a href=\"{0}\" target=\"_blank\">{1}</a>", Link.ToMember( post.Creator ), post.Creator.Name ) ); } else { set( "post.Submitter", "нч" ); } String siteUrl = new UrlInfo( post.SourceLink ).SiteUrl; set( "post.Source", siteUrl ); String val = WebHelper.GetFlash( post.SourceLink, 500, 400 ); set( "post.Content", val ); }
public OwinRequest(IOwinRequest request) { _request = request; _urlInfo = new UrlInfo(request.Uri); _cookies = new OwinRequestCookieCollection(request.Cookies); // setup the request params ImmutableDictionary<string, string>.Builder parms = ImmutableDictionary.CreateBuilder<string, string>(); ImmutableList<string>.Builder flags = ImmutableList.CreateBuilder<string>(); // import the querystring foreach (KeyValuePair<string, string[]> entry in request.Query) { if (entry.Value != null) { if (entry.Key == null) { flags.InsertRange(0, entry.Value); } else { parms.Add(entry.Key, entry.Value[0]); } } } // import the post values IFormCollection form = request.Get<IFormCollection>("Microsoft.Owin.Form#collection"); if (form != null) { foreach (KeyValuePair<string, string[]> entry in form) { parms.Add(entry.Key, entry.Value[0]); } } // import the payload _payload = request.Body.AsMemoryStream().AsText(); // import the headers ImmutableDictionary<string, string>.Builder headers = ImmutableDictionary.CreateBuilder<string, string>(); foreach (KeyValuePair<string, string[]> entry in request.Headers) { headers.Add(entry.Key, entry.Value[0]); } _flags = flags.ToImmutable(); _params = parms.ToImmutable(); _headers = headers.ToImmutable(); }
/// <summary> /// Initializes a new instance of the <see cref="StubResponse"/> class. /// </summary> /// <param name="currentUrl">The current URL.</param> /// <param name="urlBuilder">The URL builder.</param> /// <param name="serverUtility">The server utility.</param> /// <param name="routeMatch">The route match.</param> /// <param name="referrer">The referrer.</param> public StubResponse(UrlInfo currentUrl, IUrlBuilder urlBuilder, IServerUtility serverUtility, RouteMatch routeMatch, string referrer) : base(currentUrl, urlBuilder, serverUtility, routeMatch, referrer) { }
/// <summary> /// Creating default stub and mocks /// </summary> protected virtual void CreateDefaultStubsAndMocks() { writer = writer ?? new StringWriter(); engine = engine ?? new AspViewEngine(); engine.GetType().GetField("options", BindingFlags.Static | BindingFlags.NonPublic).SetValue(engine, new AspViewEngineOptions()); cookies = cookies ?? new Dictionary<string, HttpCookie>(); request = request ?? new StubRequest(cookies); response = response ?? new StubResponse(cookies); url = url ?? new UrlInfo("", "Stub", "Stub"); trace = trace ?? new StubTrace(); propertyBag = propertyBag ?? new Hashtable(); monoRailServices = monoRailServices ?? new StubMonoRailServices(); context = context ?? new StubEngineContext(request, response, monoRailServices, url); AspViewEngine.InitializeViewsStack(context); flash = flash ?? context.Flash; controller = controller ?? new ControllerStub(); controllerContext = controllerContext ?? new ControllerContextStub(); controllerContext.PropertyBag = propertyBag; context.Flash = flash; }
/// <summary> /// Creating default stub and mocks /// </summary> protected virtual void Clear() { expected = null; writer = null; engine = null; cookies = null; request = null; response = null; url = null; trace = null; propertyBag = null; flash = null; controller = null; context = null; }
public void SetUp() { var en = CultureInfo.CreateSpecificCulture("en"); Thread.CurrentThread.CurrentCulture = en; Thread.CurrentThread.CurrentUICulture = en; Layout = null; PropertyBag = new Hashtable(StringComparer.InvariantCultureIgnoreCase); Helpers = new HelperDictionary(); var services = new StubMonoRailServices { UrlBuilder = new DefaultUrlBuilder(new StubServerUtility(), new StubRoutingEngine()), UrlTokenizer = new DefaultUrlTokenizer(), CacheProvider = new StubCacheProvider() }; services.AddService(typeof(ICacheProvider), services.CacheProvider); var urlInfo = new UrlInfo( "example.org", "test", "", "http", 80, "http://test.example.org/test_area/test_controller/test_action.tdd", Area, ControllerName, Action, "tdd", "no.idea"); Response = new StubResponse(); EngineContext = new StubEngineContext(new StubRequest(), Response, services, urlInfo); services.AddService(typeof(IEngineContext), EngineContext); EngineContext.AddService<IEngineContext>(EngineContext); EngineContext.AddService<IUrlBuilder>(services.UrlBuilder); EngineContext.AddService<IUrlTokenizer>(services.UrlTokenizer); EngineContext.AddService<ICacheProvider>(services.CacheProvider); ViewComponentFactory = new DefaultViewComponentFactory(); ViewComponentFactory.Service(EngineContext); EngineContext.AddService<IViewComponentFactory>(ViewComponentFactory); services.AddService(typeof(IViewComponentFactory), ViewComponentFactory); EngineContext.AddService<IViewComponentDescriptorProvider>(new DefaultViewComponentDescriptorProvider()); services.AddService(typeof(IViewComponentDescriptorProvider), EngineContext.GetService<IViewComponentDescriptorProvider>()); ControllerContext = new ControllerContext { Helpers = Helpers, PropertyBag = PropertyBag }; EngineContext.CurrentControllerContext = ControllerContext; Helpers["formhelper"] = Helpers["form"] = new FormHelper(EngineContext); Helpers["urlhelper"] = Helpers["url"] = new UrlHelper(EngineContext); Helpers["dicthelper"] = Helpers["dict"] = new DictHelper(EngineContext); Helpers["DateFormatHelper"] = Helpers["DateFormat"] = new DateFormatHelper(EngineContext); var viewPath = Path.Combine(ViewSourcePath, "Views"); var loader = new FileAssemblyViewSourceLoader(viewPath); services.ViewSourceLoader = loader; services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader); EngineContext.AddService<IViewSourceLoader>(services.ViewSourceLoader); Controller = new BaseTestFixtureController(); Controller.Contextualize(EngineContext, ControllerContext); VelocityViewEngine = new NVelocityViewEngine(); services.AddService(typeof(IViewEngine), VelocityViewEngine); EngineContext.AddService<IViewEngine>(VelocityViewEngine); VelocityViewEngine.SetViewSourceLoader(loader); VelocityViewEngine.Service(services); var viewEngineManager = new DefaultViewEngineManager(); viewEngineManager.RegisterEngineForExtesionLookup(VelocityViewEngine); services.EmailTemplateService = new EmailTemplateService(viewEngineManager); BeforEachTest(); }
public void CanHandleEmptyAppPath() { var url = new UrlInfo("", "controller", "action", "", ".castle"); Assert.AreEqual("/controller/edit.castle", urlBuilder.BuildUrl(url, DictHelper.Create("action=edit"))); }
/// <summary> /// Builds an URL using the area name, controller name, action name, and a querystring name value collection. /// </summary> /// <param name="current">The current Url information.</param> /// <param name="area">The area.</param> /// <param name="controller">The controller.</param> /// <param name="action">The action.</param> /// <param name="queryStringParams">The query string params.</param> /// <returns></returns> public virtual string BuildUrl(UrlInfo current, string area, string controller, string action, NameValueCollection queryStringParams) { Hashtable parameters = new Hashtable(); parameters["area"] = area; parameters["controller"] = controller; parameters["action"] = action; parameters["querystring"] = queryStringParams; return BuildUrl(current, parameters); }
/// <summary> /// Builds an URL using the area name, controller name and action name. /// </summary> /// <param name="current">The current Url information.</param> /// <param name="area">The area.</param> /// <param name="controller">The controller.</param> /// <param name="action">The action.</param> /// <returns></returns> public virtual string BuildUrl(UrlInfo current, string area, string controller, string action) { Hashtable parameters = new Hashtable(); parameters["area"] = area; parameters["controller"] = controller; parameters["action"] = action; return BuildUrl(current, parameters); }
public void TurningOffUseExtensions() { urlBuilder.UseExtensions = false; var url = new UrlInfo("", "controller", "action", "", ".castle"); Assert.AreEqual("/controller/edit", urlBuilder.BuildUrl(url, DictHelper.Create("action=edit"))); }
/// <summary> /// Initializes a new instance of the <see cref="StubResponse"/> class. /// </summary> /// <param name="currentUrl">The current URL.</param> /// <param name="urlBuilder">The URL builder.</param> /// <param name="serverUtility">The server utility.</param> /// <param name="routeMatch">The route match.</param> public StubResponse(UrlInfo currentUrl, IUrlBuilder urlBuilder, IServerUtility serverUtility, RouteMatch routeMatch) : this(currentUrl, urlBuilder, serverUtility, routeMatch, null) { }
/// <summary> /// Initializes a new instance of the <see cref="StubResponse"/> class. /// </summary> /// <param name="cookies">The cookies.</param> /// <param name="info">Current url</param> public StubResponse(IDictionary<string, HttpCookie> cookies, UrlInfo info): this( info, new DefaultUrlBuilder(), new StubServerUtility(), new RouteMatch()) { this.cookies = cookies; output = new StringWriter(); }
/// <summary> /// Builds the URL using the current url as contextual information and a parameter dictionary. /// /// </summary> /// /// <remarks> /// <para> /// Common parameters includes <c>area</c>, <c>controller</c> and <c>action</c>, which outputs /// <c>/area/controller/name.extension</c> /// </para> /// /// <para> /// Please note that if you dont specify an area or controller name, they will be inferred from the /// context. If you want to use an empty area, you must specify <c>area=''</c>. /// This is commonly a source of confusion, so understand the following cases: /// </para> /// /// <example> /// <code> /// UrlInfo current = ... // Assume that the current is area Admin, controller Products and action List /// /// BuildUrl(current, {action: 'view'}) /// // returns /Admin/Products/view.castle /// /// BuildUrl(current, {controller: 'Home', action: 'index'}) /// // returns /Admin/Home/index.castle /// /// BuildUrl(current, {area:'', controller: 'Home', action: 'index'}) /// // returns /Home/index.castle /// </code> /// </example> /// /// <para> /// The <c>querystring</c> parameter can be a string or a dictionary. It appends a query string to the url: /// <c>/area/controller/name.extension?id=1</c> /// </para> /// /// <para> /// The <c>absolute</c> parameter forces the builder to output a full url like /// <c>http://hostname/virtualdir/area/controller/name.extension</c> /// </para> /// /// <para> /// The <c>encode</c> parameter forces the builder to encode the querystring /// <c>/controller/name.extension?id=1&name=John</c> which is required to output full xhtml compliant content. /// </para> /// /// </remarks> /// <param name="current">The current Url information.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public virtual string BuildUrl(UrlInfo current, IDictionary parameters) { bool applySubdomain = false; bool createAbsolutePath = CommonUtils.ObtainEntryAndRemove(parameters, "absolute", "false") == "true"; bool encode = CommonUtils.ObtainEntryAndRemove(parameters, "encode", "false") == "true"; string area; if (parameters.Contains("area")) { area = CommonUtils.ObtainEntryAndRemove(parameters, "area"); if (area == null) area = string.Empty; } else { area = current.Area; } string controller = CommonUtils.ObtainEntryAndRemove(parameters, "controller", current.Controller); string action = CommonUtils.ObtainEntryAndRemove(parameters, "action", current.Action); string domain = CommonUtils.ObtainEntryAndRemove(parameters, "domain", current.Domain); string subdomain = CommonUtils.ObtainEntryAndRemove(parameters, "subdomain", current.Subdomain); string protocol = CommonUtils.ObtainEntryAndRemove(parameters, "protocol", current.Protocol); string port = CommonUtils.ObtainEntryAndRemove(parameters, "port", current.Port.ToString()); string suffix = null; object queryString = CommonUtils.ObtainObjectEntryAndRemove(parameters, "querystring"); string basePath = null; if (parameters.Contains("basepath")) { basePath = CommonUtils.ObtainEntryAndRemove(parameters, "basepath"); } if (queryString != null) { if (queryString is IDictionary) { IDictionary qsDictionary = (IDictionary) queryString; suffix = CommonUtils.BuildQueryString(serverUtil, qsDictionary, encode); } else if (queryString is NameValueCollection) { suffix = CommonUtils.BuildQueryString(serverUtil, (NameValueCollection) queryString, encode); } else if (queryString is string) { suffix = queryString.ToString(); } } if (subdomain.ToLower() != current.Subdomain.ToLower()) { applySubdomain = true; } return InternalBuildUrl(area, controller, action, protocol, port, domain, subdomain, current.AppVirtualDir, current.Extension, createAbsolutePath, applySubdomain, suffix, basePath); }