2 // ResXDataNodeFileRefGetValueTests.cs
5 // Gary Barnett (gary.barnett.mono@gmail.com)
7 // Copyright (C) Gary Barnett (2012)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Reflection;
32 using System.Resources;
33 using System.Collections;
34 using NUnit.Framework;
35 using System.ComponentModel.Design;
36 using System.Runtime.Serialization.Formatters.Binary;
38 namespace MonoTests.System.Resources {
40 public class ResXDataNodeFileRefGetValueTests : ResourcesTestHelper {
42 public void ITRSNotUsedWhenNodeFromReader ()
44 ResXDataNode originalNode, returnedNode;
45 originalNode = GetNodeFileRefToSerializable ("ser.bbb",true);
46 returnedNode = GetNodeFromResXReader (originalNode);
48 Assert.IsNotNull (returnedNode, "#A1");
49 object val = returnedNode.GetValue (new ReturnSerializableSubClassITRS ());
50 Assert.IsNotInstanceOfType (typeof (serializableSubClass), val, "#A2");
51 Assert.IsInstanceOfType (typeof (serializable), val, "#A3");
54 [Test, ExpectedException(typeof (TypeLoadException))]
55 public void CantGetValueWithOnlyFullNameAsType ()
57 ResXDataNode originalNode, returnedNode;
58 originalNode = GetNodeFileRefToSerializable ("ser.bbb", false);
59 returnedNode = GetNodeFromResXReader (originalNode);
61 Assert.IsNotNull (returnedNode, "#A1");
62 object obj = returnedNode.GetValue ((AssemblyName []) null);
65 [Test, ExpectedException (typeof (TypeLoadException))]
66 public void CantGetValueWithOnlyFullNameAsTypeByProvidingAssemblyName ()
68 ResXDataNode originalNode, returnedNode;
70 string aName = "System.Windows.Forms_test_net_2_0, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
71 AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
73 originalNode = GetNodeFileRefToSerializable ("ser.bbb", false);
74 returnedNode = GetNodeFromResXReader (originalNode);
76 Assert.IsNotNull (returnedNode, "#A1");
77 object obj = returnedNode.GetValue (assemblyNames);
81 public void ITRSNotUsedWhenNodeCreatedNew ()
84 node = GetNodeFileRefToSerializable ("ser.bbb",true);
86 object val = node.GetValue (new ReturnSerializableSubClassITRS ());
87 Assert.IsNotInstanceOfType (typeof (serializableSubClass), val, "#A1");
88 Assert.IsInstanceOfType (typeof (serializable), val, "#A2");
91 [Test, ExpectedException (typeof (TargetInvocationException))]
92 public void LoadingFileFails ()
94 string corruptFile = Path.GetTempFileName ();
95 ResXFileRef fileRef = new ResXFileRef (corruptFile, typeof (serializable).AssemblyQualifiedName);
97 File.AppendAllText (corruptFile, "corrupt");
98 ResXDataNode node = new ResXDataNode ("aname", fileRef);
99 node.GetValue ((AssemblyName []) null);
105 public void NullAssemblyNamesOK ()
107 ResXDataNode node = GetNodeFileRefToIcon ();
109 Object ico = node.GetValue ((AssemblyName []) null);
110 Assert.IsNotNull (ico, "#A1");
111 Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
115 public void NullITRSOK ()
117 ResXDataNode node = GetNodeFileRefToIcon ();
119 Object ico = node.GetValue ((ITypeResolutionService) null);
120 Assert.IsNotNull (ico, "#A1");
121 Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
125 public void WrongITRSOK ()
127 ResXDataNode node = GetNodeFileRefToIcon ();
129 Object ico = node.GetValue (new DummyITRS ());
130 Assert.IsNotNull (ico, "#A1");
131 Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
135 public void WrongAssemblyNamesOK ()
137 ResXDataNode node = GetNodeFileRefToIcon ();
138 AssemblyName [] ass = new AssemblyName [1];
139 ass [0] = new AssemblyName ("System.Design");
141 Object ico = node.GetValue (ass);
142 Assert.IsNotNull (ico, "#A1");
143 Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");