1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
//
// ResXDataNodeTypeConverterGetValueTypeNameTests.cs
//
// Author:
// Gary Barnett (gary.barnett.mono@gmail.com)
//
// Copyright (C) Gary Barnett (2012)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using System.Resources;
using System.Collections;
using NUnit.Framework;
using System.ComponentModel.Design;
using System.Drawing;
using System.Reflection;
namespace MonoTests.System.Resources
{
[TestFixture]
public class ResXDataNodeTypeConverterGetValueTypeNameTests : ResourcesTestHelper {
[Test]
public void ITRSUsedWithNodeFromReader ()
{
ResXDataNode returnedNode, originalNode;
originalNode = new ResXDataNode ("aNumber", 23L);
returnedNode = GetNodeFromResXReader (originalNode);
Assert.IsNotNull (returnedNode, "#A1");
string returnedType = returnedNode.GetValueTypeName (new ReturnIntITRS ());
Assert.AreEqual ((typeof (Int32)).AssemblyQualifiedName, returnedType, "#A2");
}
[Test]
public void ITRSUsedEachTimeWhenNodeFromReader ()
{
ResXDataNode returnedNode, originalNode;
originalNode = new ResXDataNode ("aNumber", 23L);
returnedNode = GetNodeFromResXReader (originalNode);
Assert.IsNotNull (returnedNode, "#A1");
string newType = returnedNode.GetValueTypeName (new ReturnIntITRS ());
Assert.AreEqual (typeof (int).AssemblyQualifiedName, newType, "#A2");
string origType = returnedNode.GetValueTypeName ((ITypeResolutionService) null);
Assert.AreEqual (typeof (long).AssemblyQualifiedName, origType, "#A3");
}
[Test]
public void ITRSNotUsedWhenNodeCreatedNew ()
{
ResXDataNode node;
node = new ResXDataNode ("along", 34L);
string returnedType = node.GetValueTypeName (new ReturnIntITRS ());
Assert.AreEqual ((typeof (long)).AssemblyQualifiedName, returnedType, "#A1");
}
[Test]
public void InvalidMimeTypeReturnedFromReader_ReturnsStringIfCantResolveType ()
{
ResXDataNode node = GetNodeFromResXReader (typeconResXInvalidMimeTypeAndType);
Assert.IsNotNull (node, "#A1");
string type = node.GetValueTypeName ((AssemblyName []) null);
Assert.AreEqual ("A.type", type, "#A2");
}
[Test]
public void InvalidMimeTypeReturnedFromReader_TriesToResolve ()
{
ResXDataNode node = GetNodeFromResXReader (typeconResXInvalidMimeType);
Assert.IsNotNull (node, "#A1");
string type = node.GetValueTypeName ((AssemblyName []) null);
Assert.AreEqual (typeof (string).AssemblyQualifiedName, type, "#A2");
}
[Test]
public void ReturnsFullNameWereOnlyFullNameInResX ()
{
ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName);
Assert.IsNotNull (node, "#A1");
string returnedType = node.GetValueTypeName ((AssemblyName []) null);
Assert.AreEqual ("DummyAssembly.Convertable", returnedType, "#A2");
}
[Test]
public void AssemblyNameUsedWhereOnlyFullNameInResX ()
{
// DummyAssembly must be in the same directory as current assembly to work correctly
string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName);
Assert.IsNotNull (node, "#A1");
string returnedType = node.GetValueTypeName (assemblyNames);
Assert.AreEqual ("DummyAssembly.Convertable, " + aName, returnedType, "#A2");
}
[Test]
public void AssemblyNameUsedEachTimeWhereOnlyFullNameInResX ()
{
// DummyAssembly must be in the same directory as current assembly to work correctly
string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName);
Assert.IsNotNull (node, "#A1");
string returnedName = node.GetValueTypeName (assemblyNames);
Assert.AreEqual ("DummyAssembly.Convertable, " + aName, returnedName, "#A2");
string nameWithNullParam = node.GetValueTypeName ((AssemblyName []) null);
Assert.AreEqual ("DummyAssembly.Convertable", nameWithNullParam, "#A3");
}
#region initial
[Test]
public void NullITRSServiceOK ()
{
ResXDataNode node = GetNodeEmdeddedIcon ();
string name = node.GetValueTypeName ((ITypeResolutionService) null);
Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
}
[Test]
public void WrongITRSOK ()
{
ResXDataNode node = GetNodeEmdeddedIcon ();
string name = node.GetValueTypeName (new DummyITRS ());
Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
}
[Test]
public void WrongAssemblyNamesOK ()
{
ResXDataNode node = GetNodeEmdeddedIcon ();
AssemblyName [] ass = new AssemblyName [1];
ass [0] = new AssemblyName ("System.Design");
string name = node.GetValueTypeName (ass);
Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
}
[Test]
public void NullAssemblyNamesOK ()
{
ResXDataNode node = GetNodeEmdeddedIcon ();
string name = node.GetValueTypeName ((AssemblyName []) null);
Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
}
#endregion
static string typeconResXInvalidMimeTypeAndType =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<root>
<resheader name=""resmimetype"">
<value>text/microsoft-resx</value>
</resheader>
<resheader name=""version"">
<value>2.0</value>
</resheader>
<resheader name=""reader"">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name=""writer"">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name=""test"" type=""A.type"" mimetype=""application/xxxx"">
<value>42</value>
</data>
</root>";
static string typeconResXInvalidMimeType =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<root>
<resheader name=""resmimetype"">
<value>text/microsoft-resx</value>
</resheader>
<resheader name=""version"">
<value>2.0</value>
</resheader>
<resheader name=""reader"">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name=""writer"">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name=""test"" type=""System.String"" mimetype=""application/xxxx"">
<value>42</value>
</data>
</root>";
static string missingSerializableFromMissingAssembly =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<root>
<resheader name=""resmimetype"">
<value>text/microsoft-resx</value>
</resheader>
<resheader name=""version"">
<value>2.0</value>
</resheader>
<resheader name=""reader"">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name=""writer"">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64"">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAEZNaXNzaW5nQXNzZW1ibHksIFZlcnNpb249MS4wLjAuMCwgQ3Vs
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBQEAAAAhRHVtbXlBc3NlbWJseS5NaXNzaW5n
U2VyaWFsaXphYmxlAgAAAAdzZXJuYW1lCHNlcnZhbHVlAQECAAAABgMAAAAFYW5hbWUGBAAAAAZhdmFs
dWUL
</value>
</data>
</root>";
static string anotherSerializableFromDummyAssembly =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<root>
<resheader name=""resmimetype"">
<value>text/microsoft-resx</value>
</resheader>
<resheader name=""version"">
<value>2.0</value>
</resheader>
<resheader name=""reader"">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name=""writer"">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64"">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAEREdW1teUFzc2VtYmx5LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAIUR1bW15QXNzZW1ibHkuQW5vdGhlclNl
cmlhbGl6YWJsZQIAAAAHc2VybmFtZQhzZXJ2YWx1ZQEBAgAAAAYDAAAABWFuYW1lBgQAAAAGYXZhbHVl
Cw==
</value>
</data>
</root>";
static string convertableResXWithoutAssemblyName =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<root>
<resheader name=""resmimetype"">
<value>text/microsoft-resx</value>
</resheader>
<resheader name=""version"">
<value>2.0</value>
</resheader>
<resheader name=""reader"">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name=""writer"">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name=""test"" type=""DummyAssembly.Convertable"">
<value>im a name im a value</value>
</data>
</root>";
static string thisAssemblyConvertableResXWithoutAssemblyName =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<root>
<resheader name=""resmimetype"">
<value>text/microsoft-resx</value>
</resheader>
<resheader name=""version"">
<value>2.0</value>
</resheader>
<resheader name=""reader"">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name=""writer"">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name=""test"" type=""MonoTests.System.Resources.ThisAssemblyConvertable"">
<value>im a name im a value</value>
</data>
</root>";
}
}
|