2 // StronglyTypedResourceBuilderOtherTests.cs - tests the internalClass,
3 // codeProvider and resourceList params of the 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.
32 using NUnit.Framework;
34 using System.Resources.Tools;
36 using Microsoft.CSharp;
37 using System.Collections.Generic;
39 using System.Reflection;
42 namespace MonoTests.System.Resources.Tools {
44 public class StronglyTypedResourceBuilderOtherTests {
45 CSharpCodeProvider provider = new CSharpCodeProvider ();
47 Dictionary<string,object> GetAllResourceTypes ()
49 Dictionary<string, object> tempDict = new Dictionary<string, object> ();
50 Bitmap bmp = new Bitmap (100,100);
51 MemoryStream wav = new MemoryStream (1000);
53 tempDict.Add ("astring", "myvalue");
54 tempDict.Add ("bmp", bmp);
55 tempDict.Add ("wav", wav);
61 Dictionary<string,object> GetTestResources ()
63 Dictionary<string, object> tempDict = new Dictionary<string, object> ();
64 tempDict.Add ("akey", string.Empty);
70 public void InternalClassFalse ()
72 // check access modifiers for class, Culture, ResourceManager, string, stream and standard resource properties
73 Dictionary<string, object> testResources = GetAllResourceTypes ();
74 string [] unmatchables;
76 CodeMemberProperty cmp;
78 bool isInternal = false;
80 ccu = StronglyTypedResourceBuilder.Create (testResources,
83 "TestResourcesNameSpace",
88 CodeTypeDeclaration resType = ccu.Namespaces [0].Types [0];
89 Assert.IsTrue (resType.TypeAttributes == TypeAttributes.Public);
91 cmp = StronglyTypedResourceBuilderCodeDomTest.Get<CodeMemberProperty> (
92 "ResourceManager", ccu);
93 Assert.IsTrue (cmp.Attributes == (MemberAttributes.Abstract
94 | MemberAttributes.Final
95 | MemberAttributes.FamilyAndAssembly
96 | MemberAttributes.FamilyOrAssembly));
98 cmp = StronglyTypedResourceBuilderCodeDomTest.Get<CodeMemberProperty> ("Culture", ccu);
99 Assert.IsTrue (cmp.Attributes == (MemberAttributes.Abstract
100 | MemberAttributes.Final
101 | MemberAttributes.FamilyAndAssembly
102 | MemberAttributes.FamilyOrAssembly));
104 cmp = StronglyTypedResourceBuilderCodeDomTest.Get<CodeMemberProperty> ("astring", ccu);
105 Assert.IsTrue (cmp.Attributes == (MemberAttributes.Abstract
106 | MemberAttributes.Final
107 | MemberAttributes.FamilyAndAssembly
108 | MemberAttributes.FamilyOrAssembly));
110 cmp = StronglyTypedResourceBuilderCodeDomTest.Get<CodeMemberProperty> ("bmp", ccu);
111 Assert.IsTrue (cmp.Attributes == (MemberAttributes.Abstract
112 | MemberAttributes.Final
113 | MemberAttributes.FamilyAndAssembly
114 | MemberAttributes.FamilyOrAssembly));
116 cmp = StronglyTypedResourceBuilderCodeDomTest.Get<CodeMemberProperty> ("wav", ccu);
117 Assert.IsTrue (cmp.Attributes == (MemberAttributes.Abstract
118 | MemberAttributes.Final
119 | MemberAttributes.FamilyAndAssembly
120 | MemberAttributes.FamilyOrAssembly));
124 public void InternalClassTrue ()
126 // check access modifiers for class, Culture, ResourceManager, string, stream and standard resource properties
127 Dictionary<string, object> testResources = GetAllResourceTypes ();
128 string [] unmatchables;
130 CodeMemberProperty cmp;
132 bool isInternal = true;
134 ccu = StronglyTypedResourceBuilder.Create (testResources,
137 "TestResourcesNameSpace",
143 CodeTypeDeclaration resType = ccu.Namespaces [0].Types [0];
144 Assert.IsTrue (resType.TypeAttributes == TypeAttributes.NotPublic);
146 cmp = StronglyTypedResourceBuilderCodeDomTest.Get<CodeMemberProperty> (
147 "ResourceManager", ccu);
148 Assert.IsTrue (cmp.Attributes == (MemberAttributes.Abstract
149 | MemberAttributes.Final
150 | MemberAttributes.Assembly));
152 cmp = StronglyTypedResourceBuilderCodeDomTest.Get<CodeMemberProperty> ("Culture", ccu);
153 Assert.IsTrue (cmp.Attributes == (MemberAttributes.Abstract
154 | MemberAttributes.Final
155 | MemberAttributes.Assembly));
157 cmp = StronglyTypedResourceBuilderCodeDomTest.Get<CodeMemberProperty> ("astring", ccu);
158 Assert.IsTrue (cmp.Attributes == (MemberAttributes.Abstract
159 | MemberAttributes.Final
160 | MemberAttributes.Assembly));
161 cmp = StronglyTypedResourceBuilderCodeDomTest.Get<CodeMemberProperty> ("bmp", ccu);
162 Assert.IsTrue (cmp.Attributes == (MemberAttributes.Abstract
163 | MemberAttributes.Final
164 | MemberAttributes.Assembly));
165 cmp = StronglyTypedResourceBuilderCodeDomTest.Get<CodeMemberProperty> ("wav", ccu);
166 Assert.IsTrue (cmp.Attributes == (MemberAttributes.Abstract
167 | MemberAttributes.Final
168 | MemberAttributes.Assembly));
171 [Test, ExpectedException (typeof (ArgumentNullException))]
172 public void ProviderNull ()
174 // should throw exception
175 Dictionary<string, object> testResources = GetTestResources ();
176 string [] unmatchables;
178 StronglyTypedResourceBuilder.Create (testResources,
181 "TestResourcesNameSpace",
182 null, //setting provider to null
188 public void ResourceListEmpty ()
190 //should still create class with default members
191 Dictionary<string, object> testResources;
192 string [] unmatchables;
195 testResources = new Dictionary<string, object> ();
197 ccu = StronglyTypedResourceBuilder.Create (testResources,
200 "TestResourcesNameSpace",
205 Assert.AreEqual(5,ccu.Namespaces [0].Types [0].Members.Count);
208 [Test, ExpectedException (typeof (ArgumentNullException))]
209 public void ResourceListNull ()
211 // should through exception
212 Dictionary<string, object> testResources;
213 string [] unmatchables;
214 CSharpCodeProvider provider = new CSharpCodeProvider ();
216 testResources = null;
218 StronglyTypedResourceBuilder.Create (testResources,
221 "TestResourcesNameSpace",