[bcl] Add NUnitHelper.cs with API not in nunit-lite
[mono.git] / mcs / class / System.Windows.Forms / Test / System.Resources / ResXDataNodeFileRefGetValueTests.cs
1 //
2 // ResXDataNodeFileRefGetValueTests.cs
3 // 
4 // Author:
5 //      Gary Barnett (gary.barnett.mono@gmail.com)
6 // 
7 // Copyright (C) Gary Barnett (2012)
8 //
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:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
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.
27
28 using System;
29 using System.IO;
30 using System.Reflection;
31 using System.Drawing;
32 using System.Resources;
33 using System.Collections;
34 using NUnit.Framework;
35 using System.ComponentModel.Design;
36 using System.Runtime.Serialization.Formatters.Binary;
37
38 namespace MonoTests.System.Resources {
39         [TestFixture]
40         public class ResXDataNodeFileRefGetValueTests : ResourcesTestHelper {
41                 [Test]
42                 public void ITRSNotUsedWhenNodeFromReader ()
43                 {
44                         ResXDataNode originalNode, returnedNode;
45                         originalNode = GetNodeFileRefToSerializable ("ser.bbb",true);
46                         returnedNode = GetNodeFromResXReader (originalNode);
47
48                         Assert.IsNotNull (returnedNode, "#A1");
49                         object val = returnedNode.GetValue (new ReturnSerializableSubClassITRS ());
50                         AssertHelper.IsNotInstanceOfType (typeof (serializableSubClass), val, "#A2");
51                         Assert.IsInstanceOfType (typeof (serializable), val, "#A3");
52                 }
53
54                 [Test, ExpectedException(typeof (TypeLoadException))]
55                 public void CantGetValueWithOnlyFullNameAsType ()
56                 {
57                         ResXDataNode originalNode, returnedNode;
58                         originalNode = GetNodeFileRefToSerializable ("ser.bbb", false);
59                         returnedNode = GetNodeFromResXReader (originalNode);
60
61                         Assert.IsNotNull (returnedNode, "#A1");
62                         object obj = returnedNode.GetValue ((AssemblyName []) null);
63                 }
64
65                 [Test, ExpectedException (typeof (TypeLoadException))]
66                 public void CantGetValueWithOnlyFullNameAsTypeByProvidingAssemblyName ()
67                 {
68                         ResXDataNode originalNode, returnedNode;
69
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) };
72
73                         originalNode = GetNodeFileRefToSerializable ("ser.bbb", false);
74                         returnedNode = GetNodeFromResXReader (originalNode);
75
76                         Assert.IsNotNull (returnedNode, "#A1");
77                         object obj = returnedNode.GetValue (assemblyNames);
78                 }
79
80                 [Test]
81                 public void ITRSNotUsedWhenNodeCreatedNew ()
82                 {
83                         ResXDataNode node;
84                         node = GetNodeFileRefToSerializable ("ser.bbb",true);
85
86                         object val = node.GetValue (new ReturnSerializableSubClassITRS ());
87                         AssertHelper.IsNotInstanceOfType (typeof (serializableSubClass), val, "#A1");
88                         Assert.IsInstanceOfType (typeof (serializable), val, "#A2");
89                 }
90
91                 [Test, ExpectedException (typeof (TargetInvocationException))]
92                 public void LoadingFileFails ()
93                 {
94                         string corruptFile = Path.GetTempFileName ();
95                         ResXFileRef fileRef = new ResXFileRef (corruptFile, typeof (serializable).AssemblyQualifiedName);
96
97                         File.AppendAllText (corruptFile, "corrupt");
98                         ResXDataNode node = new ResXDataNode ("aname", fileRef);
99                         node.GetValue ((AssemblyName []) null);
100                 }
101
102                 #region initial
103
104                 [Test]
105                 public void NullAssemblyNamesOK ()
106                 {
107                         ResXDataNode node = GetNodeFileRefToIcon ();
108
109                         Object ico = node.GetValue ((AssemblyName []) null);
110                         Assert.IsNotNull (ico, "#A1");
111                         Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
112                 }
113
114                 [Test]
115                 public void NullITRSOK ()
116                 {
117                         ResXDataNode node = GetNodeFileRefToIcon ();
118
119                         Object ico = node.GetValue ((ITypeResolutionService) null);
120                         Assert.IsNotNull (ico, "#A1");
121                         Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
122                 }
123
124                 [Test]
125                 public void WrongITRSOK ()
126                 {
127                         ResXDataNode node = GetNodeFileRefToIcon ();
128
129                         Object ico = node.GetValue (new DummyITRS ());
130                         Assert.IsNotNull (ico, "#A1");
131                         Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
132                 }
133                 
134                 [Test]
135                 public void WrongAssemblyNamesOK ()
136                 {
137                         ResXDataNode node = GetNodeFileRefToIcon ();
138                         AssemblyName [] ass = new AssemblyName [1];
139                         ass [0] = new AssemblyName ("System.Design");
140
141                         Object ico = node.GetValue (ass);
142                         Assert.IsNotNull (ico, "#A1");
143                         Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
144                 }
145
146                 #endregion
147                 
148         }
149
150 }