public void build_descriptor_extra_params_set_to_null_should_acts_as_empty() { var param1 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, null); var param2 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, new Dictionary<string, object>()); Assert.That(param1, Is.EqualTo(param2)); }
public void build_descriptor_params_should_act_as_a_unique_key() { var param1 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, null); var param2 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, null); var param3 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", true, null); var param4 = new BuildDescriptorParams("foo", "baz", "fizz", "buzz", false, null); param1.ShouldEqual(param2); param1.ShouldNotEqual(param3); param1.ShouldNotEqual(param4); }
public void Build_descriptor_params_should_act_as_a_unique_key() { //Given, When var param1 = new BuildDescriptorParams("foo", "fizz", "buzz", false, null); var param2 = new BuildDescriptorParams("foo", "bar", "buzz", false, null); var param3 = new BuildDescriptorParams("foo", "fizz", "buzz", true, null); //Then param1.ShouldNotEqual(param2); param1.ShouldNotEqual(param3); }
public void BuildDescriptorParamsActsAsKey() { var param1 = new BuildDescriptorParams("a", "c", "d", "e", false, null); var param2 = new BuildDescriptorParams("a", "c", "d", "e", false, null); var param3 = new BuildDescriptorParams("a", "c", "d", "e", true, null); var param4 = new BuildDescriptorParams("a", "c2", "d", "e", false, null); Assert.That(param1, Is.EqualTo(param2)); Assert.That(param1, Is.Not.EqualTo(param3)); Assert.That(param1, Is.Not.EqualTo(param4)); }
public void build_descriptor_params_should_act_as_a_unique_key() { var param1 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, null); var param2 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, null); var param3 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", true, null); var param4 = new BuildDescriptorParams("foo", "baz", "fizz", "buzz", false, null); param1.ShouldEqual(param2); param1.ShouldNotEqual(param3); param1.ShouldNotEqual(param4); }
public SparkViewDescriptor BuildDescriptor(BuildDescriptorParams buildDescriptorParams, ICollection<string> searchedLocations) { var descriptor = new SparkViewDescriptor { TargetNamespace = buildDescriptorParams.ActionNamespace }; if (!LocatePotentialTemplate( PotentialViewLocations(buildDescriptorParams.AcionName, buildDescriptorParams.ViewName, buildDescriptorParams.Extra), descriptor.Templates, searchedLocations)) { return null; } if (!string.IsNullOrEmpty(buildDescriptorParams.MasterName)) { if (!LocatePotentialTemplate( PotentialMasterLocations(buildDescriptorParams.MasterName, buildDescriptorParams.Extra), descriptor.Templates, searchedLocations)) { return null; } } else if (buildDescriptorParams.FindDefaultMaster && TrailingUseMasterName(descriptor) == null) { LocatePotentialTemplate( PotentialDefaultMasterLocations(buildDescriptorParams.AcionName, buildDescriptorParams.Extra), descriptor.Templates, null); } string trailingUseMaster = TrailingUseMasterName(descriptor); while (buildDescriptorParams.FindDefaultMaster && !string.IsNullOrEmpty(trailingUseMaster)) { if (!LocatePotentialTemplate( PotentialMasterLocations(trailingUseMaster, buildDescriptorParams.Extra), descriptor.Templates, searchedLocations)) { return null; } trailingUseMaster = TrailingUseMasterName(descriptor); } return descriptor; }
private SparkViewDescriptor GetViewDescriptor(string controllerName, string viewName, string masterName) { var searchLocations = new List <string>(); var buildDescriptorParams = new BuildDescriptorParams(String.Empty, controllerName, viewName, masterName, false, new Dictionary <string, object>()); var viewDescriptor = _descriptorBuilder.BuildDescriptor(buildDescriptorParams, searchLocations); viewDescriptor.Language = LanguageType.Javascript; return(viewDescriptor); }
public void build_descriptor_extra_params_should_have_identical_equality() { var param1 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, Dict(new[] {"hippo", "lion"})); var param2 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, Dict(new[] {"hippo"})); var param3 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, Dict(new[] {"lion"})); var param4 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, Dict(new[] {"lion", "hippo"})); var param5 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, Dict(null)); var param6 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, Dict(new string[0])); var param7 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, Dict(new[] {"hippo", "lion"})); Assert.That(param1, Is.Not.EqualTo(param2)); Assert.That(param1, Is.Not.EqualTo(param3)); Assert.That(param1, Is.Not.EqualTo(param4)); Assert.That(param1, Is.Not.EqualTo(param5)); Assert.That(param1, Is.Not.EqualTo(param6)); Assert.That(param1, Is.EqualTo(param7)); }
public SparkViewToken GetViewToken(ActionCall call, string actionName, string viewName, LanguageType languageType) { var searchedLocations = new List <string>(); var descriptorParams = new BuildDescriptorParams("", actionName, viewName, String.Empty, false, null); var descriptor = DescriptorBuilder.BuildDescriptor(descriptorParams, searchedLocations); if (descriptor == null) { var errMsg = string.Format("View '{0}' could not be found in any of the following locations: {1}", viewName, string.Join(", ", searchedLocations)); throw new CompilerException(errMsg); } descriptor.Language = languageType; return(new SparkViewToken(call, descriptor, call.Method.Name, viewName)); }
public void build_descriptor_extra_params_should_have_identical_equality() { var param1 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, Dict(new[] { "hippo", "lion" })); var param2 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, Dict(new[] { "hippo" })); var param3 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, Dict(new[] { "lion" })); var param4 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, Dict(new[] { "lion", "hippo" })); var param5 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, Dict(null)); var param6 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, Dict(new string[0])); var param7 = new BuildDescriptorParams("foo", "bar", "fizz", "buzz", false, Dict(new[] { "hippo", "lion" })); Assert.That(param1, Is.Not.EqualTo(param2)); Assert.That(param1, Is.Not.EqualTo(param3)); Assert.That(param1, Is.Not.EqualTo(param4)); Assert.That(param1, Is.Not.EqualTo(param5)); Assert.That(param1, Is.Not.EqualTo(param6)); Assert.That(param1, Is.EqualTo(param7)); }
public void ParamsExtraEqualityMustBeIdentical() { var param1 = new BuildDescriptorParams("a", "c", "d", "e", false, Dict(new[] { "alpha", "beta" })); var param2 = new BuildDescriptorParams("a", "c", "d", "e", false, Dict(new[] { "alpha" })); var param3 = new BuildDescriptorParams("a", "c", "d", "e", false, Dict(new[] { "beta" })); var param4 = new BuildDescriptorParams("a", "c", "d", "e", false, Dict(new[] { "beta", "alpha" })); var param5 = new BuildDescriptorParams("a", "c", "d", "e", false, Dict(null)); var param6 = new BuildDescriptorParams("a", "c", "d", "e", false, Dict(new string[0])); var param7 = new BuildDescriptorParams("a", "c", "d", "e", false, Dict(new[] { "alpha", "beta" })); Assert.That(param1, Is.Not.EqualTo(param2)); Assert.That(param1, Is.Not.EqualTo(param3)); Assert.That(param1, Is.Not.EqualTo(param4)); Assert.That(param1, Is.Not.EqualTo(param5)); Assert.That(param1, Is.Not.EqualTo(param6)); Assert.That(param1, Is.EqualTo(param7)); }
public void Build_descriptor_extra_params_should_have_identical_equality() { //Given, When var param1 = new BuildDescriptorParams("foo", "fizz", "buzz", false, Dict(new[] { "hippo", "lion" })); var param2 = new BuildDescriptorParams("foo", "fizz", "buzz", false, Dict(new[] { "hippo" })); var param3 = new BuildDescriptorParams("foo", "fizz", "buzz", false, Dict(new[] { "lion" })); var param4 = new BuildDescriptorParams("foo", "fizz", "buzz", false, Dict(new[] { "lion", "hippo" })); var param5 = new BuildDescriptorParams("foo", "fizz", "buzz", false, Dict(null)); var param6 = new BuildDescriptorParams("foo", "fizz", "buzz", false, Dict(new string[0])); var param7 = new BuildDescriptorParams("foo", "fizz", "buzz", false, Dict(new[] { "hippo", "lion" })); //Then param1.ShouldNotEqual(param2); param1.ShouldNotEqual(param3); param1.ShouldNotEqual(param4); param1.ShouldNotEqual(param5); param1.ShouldNotEqual(param6); param1.ShouldEqual(param7); }
private ViewEngineResult findViewInternal(ActionContext actionContext, string viewName, string masterName, bool findDefaultMaster, bool useCache) { var searchedLocations = new List <string>(); var targetNamespace = actionContext.ActionNamespace; var descriptorParams = new BuildDescriptorParams( targetNamespace, actionContext.ActionName, viewName, masterName, findDefaultMaster, DescriptorBuilder.GetExtraParameters(actionContext)); ISparkViewEntry entry; if (useCache) { if (tryGetCacheValue(descriptorParams, out entry) && entry.IsCurrent()) { return(buildResult(entry)); } return(new ViewEngineResult(new List <string> { "Cache" })); } var descriptor = DescriptorBuilder.BuildDescriptor(descriptorParams, searchedLocations); if (descriptor == null) { return(new ViewEngineResult(searchedLocations)); } entry = Engine.CreateEntry(descriptor); setCacheValue(descriptorParams, entry); return(buildResult(entry)); }
private SparkViewEngineResult LocateView(string viewPath, string viewName, ViewLocationResult viewLocationResult, IRenderContext renderContext) { var searchedLocations = new List <string>(); var descriptorParams = new BuildDescriptorParams(viewPath, viewName, null, true, null); var descriptor = this.descriptorBuilder.BuildDescriptor( descriptorParams, searchedLocations); if (descriptor == null) { return(new SparkViewEngineResult(searchedLocations)); } var entry = renderContext.ViewCache.GetOrAdd( viewLocationResult, x => this.engine.CreateEntry(descriptor)); return(new SparkViewEngineResult( entry.CreateInstance() as NancySparkView)); }
private ViewEngineResult FindViewInternal(ActionContext actionContext, string viewName, string masterName, bool findDefaultMaster, bool useCache) { var searchedLocations = new List <string>(); var viewPath = actionContext.ViewPath; var descriptorParams = new BuildDescriptorParams( viewPath, viewName, masterName, findDefaultMaster, DescriptorBuilder.GetExtraParameters(actionContext)); ISparkViewEntry entry; if (useCache) { if (TryGetCacheValue(descriptorParams, out entry) && entry.IsCurrent()) { return(BuildResult(actionContext.HttpContext, entry)); } return(cacheMissResult); } var descriptor = DescriptorBuilder.BuildDescriptor( descriptorParams, searchedLocations); if (descriptor == null) { return(new ViewEngineResult(searchedLocations)); } entry = Engine.CreateEntry(descriptor); this.SetCacheValue(descriptorParams, entry); return(BuildResult(actionContext.HttpContext, entry)); }
private bool tryGetCacheValue(BuildDescriptorParams descriptorParams, out ISparkViewEntry entry) { lock (_cache) { return _cache.TryGetValue(descriptorParams, out entry); } }
public void BuildDescriptorParamsActsAsKey() { var param1 = new BuildDescriptorParams("a", "c", "d", "e", false, null); var param2 = new BuildDescriptorParams("a", "c", "d", "e", false, null); var param3 = new BuildDescriptorParams("a", "c", "d", "e", true, null); var param4 = new BuildDescriptorParams("a", "c2", "d", "e", false, null); Assert.That(param1, Is.EqualTo(param2)); Assert.That(param1, Is.Not.EqualTo(param3)); Assert.That(param1, Is.Not.EqualTo(param4)); }
private ViewEngineResult findViewInternal(ActionContext actionContext, string viewName, string masterName, bool findDefaultMaster, bool useCache) { var searchedLocations = new List<string>(); var targetNamespace = actionContext.ActionNamespace; var descriptorParams = new BuildDescriptorParams( targetNamespace, actionContext.ActionName, viewName, masterName, findDefaultMaster, DescriptorBuilder.GetExtraParameters(actionContext)); ISparkViewEntry entry; if (useCache) { if (tryGetCacheValue(descriptorParams, out entry) && entry.IsCurrent()) { return buildResult(entry); } return new ViewEngineResult(new List<string> { "Cache" }); } var descriptor = DescriptorBuilder.BuildDescriptor(descriptorParams, searchedLocations); if (descriptor == null) { return new ViewEngineResult(searchedLocations); } entry = Engine.CreateEntry(descriptor); setCacheValue(descriptorParams, entry); return buildResult(entry); }
public SparkViewToken GetViewToken(ActionCall call, string actionName, string viewName, LanguageType languageType) { var searchedLocations = new List<string>(); var descriptorParams = new BuildDescriptorParams("", actionName, viewName, String.Empty, false, null); var descriptor = DescriptorBuilder.BuildDescriptor(descriptorParams, searchedLocations); if (descriptor == null) { var errMsg = string.Format("View '{0}' could not be found in any of the following locations: {1}", viewName, string.Join(", ", searchedLocations)); throw new CompilerException(errMsg); } descriptor.Language = languageType; return new SparkViewToken(call, descriptor, call.Method.Name, viewName); }
/// <summary> /// Given a set of MVC-specific parameters, a descriptor for the target view is created. This can /// be a bit more expensive because the existence of files is tested at various candidate locations. /// </summary> /// <param name="buildDescriptorParams">Contains all of the standard and extra parameters which contribute to a descriptor</param> /// <param name="searchedLocations">Candidate locations are added to this collection so an information-rich error may be returned</param> /// <returns>The descriptor with all of the detected view locations in order</returns> public SparkViewDescriptor BuildDescriptor(BuildDescriptorParams buildDescriptorParams, ICollection <string> searchedLocations) { return(null); }
public void ParamsExtraNullActsAsEmpty() { var param1 = new BuildDescriptorParams("a", "c", "d", "e", false, null); var param2 = new BuildDescriptorParams("a", "c", "d", "e", false, new Dictionary<string, object>()); Assert.That(param1, Is.EqualTo(param2)); }
public void ParamsExtraEqualityMustBeIdentical() { var param1 = new BuildDescriptorParams("a", "c", "d", "e", false, Dict(new[] { "alpha", "beta" })); var param2 = new BuildDescriptorParams("a", "c", "d", "e", false, Dict(new[] { "alpha" })); var param3 = new BuildDescriptorParams("a", "c", "d", "e", false, Dict(new[] { "beta" })); var param4 = new BuildDescriptorParams("a", "c", "d", "e", false, Dict(new[] { "beta", "alpha" })); var param5 = new BuildDescriptorParams("a", "c", "d", "e", false, Dict(null)); var param6 = new BuildDescriptorParams("a", "c", "d", "e", false, Dict(new string[0])); var param7 = new BuildDescriptorParams("a", "c", "d", "e", false, Dict(new[] { "alpha", "beta" })); Assert.That(param1, Is.Not.EqualTo(param2)); Assert.That(param1, Is.Not.EqualTo(param3)); Assert.That(param1, Is.Not.EqualTo(param4)); Assert.That(param1, Is.Not.EqualTo(param5)); Assert.That(param1, Is.Not.EqualTo(param6)); Assert.That(param1, Is.EqualTo(param7)); }
private ViewEngineResult FindViewInternal(ActionContext actionContext, string viewName, string masterName, bool findDefaultMaster, bool useCache) { var searchedLocations = new List<string>(); string targetNamespace = actionContext.ActionNamespace; string controllerName = actionContext.RouteData.GetRequiredString("controller"); var descriptorParams = new BuildDescriptorParams( targetNamespace, controllerName, viewName, masterName, findDefaultMaster, DescriptorBuilder.GetExtraParameters(actionContext)); ISparkViewEntry entry; if (useCache) { if (TryGetCacheValue(descriptorParams, out entry) && entry.IsCurrent()) { return BuildResult(actionContext.HttpContext, entry); } return new ViewEngineResult(new List<string> { "Cache" }); } SparkViewDescriptor descriptor = DescriptorBuilder.BuildDescriptor( descriptorParams, searchedLocations); if (descriptor == null) return new ViewEngineResult(searchedLocations); entry = Engine.CreateEntry(descriptor); SetCacheValue(descriptorParams, entry); return BuildResult(actionContext.HttpContext, entry); }
private void setCacheValue(BuildDescriptorParams descriptorParams, ISparkViewEntry entry) { lock (_cache) { _cache[descriptorParams] = entry; } }