2 // StronglyTypedResourceBuilderBaseNameTests.cs - tests the baseName
3 // parameter passed to main Create overload
6 // Gary Barnett (gary.barnett.mono@gmail.com)
8 // Copyright (C) Gary Barnett (2012)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit.Framework;
33 using System.Resources.Tools;
35 using Microsoft.CSharp;
36 using System.Collections.Generic;
38 namespace MonoTests.System.Resources.Tools {
40 public class StronglyTypedResourceBuilderBaseNameTests {
41 static string [] keywords = {"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char",
42 "checked", "class", "const", "continue", "decimal", "default", "delegate",
43 "do", "double", "else", "enum", "event", "explicit", "extern", "FALSE",
44 "false", "finally", "fixed", "float", "for", "foreach", "goto", "if",
45 "implicit", "in", "int", "interface", "internal", "is", "lock", "long",
46 "namespace", "new", "null", "object", "operator", "out", "override", "params",
47 "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed",
48 "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this",
49 "throw", "TRUE", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe",
50 "ushort", "using", "virtual", "volatile", "void", "while" };
51 static char [] specialChars = { ' ', '\u00A0', '.', ',', ';', '|', '~', '@', '#', '%', '^', '&',
52 '*', '+', '-', '/', '\\', '<', '>', '?', '[', ']', '(', ')', '{',
53 '}', '\"', '\'', ':', '!'};
54 CSharpCodeProvider provider = new CSharpCodeProvider ();
55 Dictionary<string, object> testResources;
60 testResources = new Dictionary<string, object> ();
61 testResources.Add ("akey", String.Empty);
65 public void BaseNameEmpty ()
67 // empty class name should change to _
68 string [] unmatchables;
70 string input, expected;
74 ccu = StronglyTypedResourceBuilder.Create (testResources,
77 "TestResourcesNameSpace",
84 Assert.AreEqual (expected,ccu.Namespaces [0].Types [0].Name);
87 [Test, ExpectedException (typeof (ArgumentException))]
88 public void BaseNameInvalidIdentifier ()
90 // identifier invalid after Going through provider.CreateValidIdentifier throw exception in .NET framework
91 string [] unmatchables;
96 StronglyTypedResourceBuilder.Create (testResources,
99 "TestResourcesNameSpace",
106 public void BaseNameKeywords ()
108 // provider.CreateValidIdentifier used to return valid identifier
110 string [] unmatchables;
113 foreach (string input in keywords) {
114 ccu = StronglyTypedResourceBuilder.Create (testResources,
117 "TestResourcesNameSpace",
122 expected = provider.CreateValidIdentifier (input);
124 Assert.AreEqual (expected,ccu.Namespaces [0].Types [0].Name);
128 [Test, ExpectedException (typeof (ArgumentNullException))]
129 public void BaseNameNull ()
131 // should throw exception
132 string [] unmatchables;
137 StronglyTypedResourceBuilder.Create (testResources,
140 "TestResourcesNameSpace",
147 public void BaseNameSpecialChars ()
149 // StronglyTypedResourceBuilder.VerifyResourceName seems to be used
150 string [] unmatchables;
152 string input, expected;
154 foreach (char c in specialChars) {
155 input = c.ToString ();
157 ccu = StronglyTypedResourceBuilder.Create (testResources,
160 "TestResourcesNameSpace",
165 expected = StronglyTypedResourceBuilder.VerifyResourceName (input, provider);
167 Assert.AreEqual (expected,ccu.Namespaces [0].Types [0].Name);