1
// Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
.Tests
.Services
.StaticResourceRegistry
17 using Castle
.Core
.Resource
;
18 using Castle
.MonoRail
.Framework
.Services
;
19 using NUnit
.Framework
;
22 public class DefaultStaticResourceRegistryTestCase
24 private DefaultStaticResourceRegistry registry
;
29 registry
= new DefaultStaticResourceRegistry();
33 public void Exists_CorrectlyMatchesLocationAndVersion()
35 registry
.RegisterCustomResource("key", null, null, new StaticContentResource("content"), "text/javascript");
37 Assert
.IsTrue(registry
.Exists("key", null, null));
38 Assert
.IsTrue(registry
.Exists("Key", null, null));
39 Assert
.IsTrue(registry
.Exists("KEY", null, null));
41 Assert
.IsFalse(registry
.Exists("key2", null, null));
42 Assert
.IsFalse(registry
.Exists("key", "neutral", null));
43 Assert
.IsFalse(registry
.Exists("key", "pt-br", null));
44 Assert
.IsFalse(registry
.Exists("key", null, "1"));
45 Assert
.IsFalse(registry
.Exists("key", null, "1.0"));
49 public void GetResource_FetchesCorrectResource()
51 registry
.RegisterCustomResource("key 1", null, null, new StaticContentResource("content 1"), "text/javascript");
52 registry
.RegisterCustomResource("key 2", null, null, new StaticContentResource("content 2"), "text/javascript");
55 Assert
.AreEqual("content 1", registry
.GetResource("key 1", null, null, out mime
));
56 Assert
.AreEqual("text/javascript", mime
);
57 Assert
.AreEqual("content 2", registry
.GetResource("key 2", null, null, out mime
));
58 Assert
.AreEqual("text/javascript", mime
);
62 public void RegisterAssemblyResource_FetchesCorrectResource()
64 registry
.RegisterAssemblyResource("key 1", null, null, "Castle.MonoRail.Framework.Tests", "Castle.MonoRail.Framework.Tests.Services.StaticResourceRegistry.DummyRes", "jsfunctions", "text/javascript");
65 registry
.RegisterAssemblyResource("key 2", null, null, "Castle.MonoRail.Framework.Tests", "Castle.MonoRail.Framework.Tests.Services.StaticResourceRegistry.DummyRes", "jsValidator", "text/javascript");
68 Assert
.AreEqual("Something 1", registry
.GetResource("key 1", null, null, out mime
));
69 Assert
.AreEqual("text/javascript", mime
);
70 Assert
.AreEqual("validators", registry
.GetResource("key 2", null, null, out mime
));
71 Assert
.AreEqual("text/javascript", mime
);
75 public void DefaultResource_CanResolveBehaviourScripts()
78 Assert
.AreEqual("\r\n/*\r\n Behaviour v1.1 by Ben Nolan, June 2005.",
79 registry
.GetResource("BehaviourScripts", null, null, out mime
).Substring(0, 48));
80 Assert
.AreEqual("text/javascript", mime
);
84 public void DefaultResource_CanResolveAjaxScripts()
87 Assert
.AreEqual("\r\n/* Prototype JavaScript framework, version 1.5.1\r\n * (c)",
88 registry
.GetResource("AjaxScripts", null, null, out mime
).Substring(0, 60));
89 Assert
.AreEqual("text/javascript", mime
);
93 public void DefaultResource_CanResolveFormHelperScript()
96 Assert
.AreEqual("\r\n\r\n\r\nfunction monorail_formhelper_numberonly(e, exceptions, forbidalso)\r\n{\r\n\tex",
97 registry
.GetResource("FormHelperScript", null, null, out mime
).Substring(0, 80));
98 Assert
.AreEqual("text/javascript", mime
);
102 public void DefaultResource_CanResolveZebdaScripts()
105 Assert
.AreEqual(" \r\n\r\n/*\r\n\r\nZebda javascript library, version 0.3.1\r\n http://labs.cavorite.com/ze",
106 registry
.GetResource("ZebdaScripts", null, null, out mime
).Substring(0, 80));
107 Assert
.AreEqual("text/javascript", mime
);
111 public void DefaultResource_CanResolveValidateScripts()
114 Assert
.AreEqual(" \r\n\t\t\t \r\n\t\t\t/*************************************",
115 registry
.GetResource("ValidateCore", null, null, out mime
).Substring(0, 50));
116 Assert
.AreEqual("text/javascript", mime
);
118 Assert
.AreEqual(" \r\n\t\t\t/*--\tfValidate US-English language file.\r\n\t\t",
119 registry
.GetResource("ValidateLang", null, null, out mime
).Substring(0, 50));
120 Assert
.AreEqual("text/javascript", mime
);
122 Assert
.AreEqual(" \r\n\t\t\t/*< blank basic ****************************",
123 registry
.GetResource("ValidateValidators", null, null, out mime
).Substring(0, 50));
124 Assert
.AreEqual("text/javascript", mime
);
126 Assert
.AreEqual(" \r\n\t\t\t\tfunction fValConfig()\r\n\t\t\t\t{\r\n\t\t\t\t\t/*\tGloba",
127 registry
.GetResource("ValidateConfig", null, null, out mime
).Substring(0, 50));
128 Assert
.AreEqual("text/javascript", mime
);
132 public void DefaultResource_CanResolveEffects2()
135 Assert
.AreEqual("\r\n\r\n// script.aculo.us scriptaculous.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 ",
136 registry
.GetResource("Effects2", null, null, out mime
).Substring(0, 80));
137 Assert
.AreEqual("text/javascript", mime
);
141 public void DefaultResource_CanResolveEffectsFatScripts()
144 Assert
.AreEqual("\r\n// @name The Fade Anything Technique\r\n// @namespace http://www.axentric.c",
145 registry
.GetResource("EffectsFatScripts", null, null, out mime
).Substring(0, 80));
146 Assert
.AreEqual("text/javascript", mime
);