1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
22 // ResXFileRefTest.cs: Unit Tests for ResXFileRef.
25 // Andreia Gaita (avidigal@novell.com)
31 using System.Resources;
32 using System.Runtime.Serialization;
33 using System.Collections;
35 using NUnit.Framework;
36 namespace MonoTests.System.Resources
39 public class ResXDataNodeTest : MonoTests.System.Windows.Forms.TestHelper
42 [ExpectedException (typeof (ArgumentNullException))]
43 public void ConstructorEx1 ()
45 ResXDataNode d = new ResXDataNode (null, (object)null);
49 [ExpectedException (typeof (ArgumentNullException))]
50 public void ConstructorEx2 ()
52 ResXDataNode d = new ResXDataNode (null, (ResXFileRef) null);
56 [ExpectedException (typeof (ArgumentException))]
57 public void ConstructorEx3 ()
59 ResXDataNode d = new ResXDataNode ("", (object) null);
63 [ExpectedException (typeof (ArgumentNullException))]
64 public void ConstructorEx4 ()
66 ResXDataNode d = new ResXDataNode ("", (ResXFileRef) null);
70 [ExpectedException (typeof (ArgumentException))]
71 public void ConstructorEx5 ()
73 ResXDataNode d = new ResXDataNode ("", new ResXFileRef ("filename", "typename"));
77 [ExpectedException (typeof (InvalidOperationException))]
78 public void ConstructorEx6 ()
80 ResXDataNode d = new ResXDataNode ("name", new notserializable ());
84 public void WriteRead1 ()
86 ResXResourceWriter rw = new ResXResourceWriter ("resx.resx");
87 serializable ser = new serializable ("aaaaa", "bbbbb");
88 ResXDataNode dn = new ResXDataNode ("test", ser);
89 dn.Comment = "comment";
94 ResXResourceReader rr = new ResXResourceReader ("resx.resx");
95 IDictionaryEnumerator en = rr.GetEnumerator ();
96 while (en.MoveNext ()) {
97 serializable o = ((DictionaryEntry) en.Current).Value as serializable;
100 Assert.AreEqual (ser, o, "#A1");
106 Assert.IsTrue (found, "#A2 - Serialized object not found on resx");
110 class notserializable
113 public notserializable ()
119 [SerializableAttribute]
120 public class serializable : ISerializable
125 public serializable (string name, string value)
131 public serializable (SerializationInfo info, StreamingContext ctxt)
133 name = (string) info.GetValue ("sername", typeof (string));
134 value = (String) info.GetValue ("servalue", typeof (string));
137 public void GetObjectData (SerializationInfo info, StreamingContext ctxt)
139 info.AddValue ("sername", name);
140 info.AddValue ("servalue", value);
143 public override string ToString ()
145 return String.Format ("name={0};value={1}", this.name, this.value);
148 public override bool Equals (object obj)
150 serializable o = obj as serializable;
153 return this.name.Equals(o.name) && this.value.Equals(o.value);