public void Serialized_WriteBack() { ResXDataNode node, returnedNode, finalNode; node = GetNodeEmdeddedSerializable(); node.Comment = "acomment"; returnedNode = GetNodeFromResXReader(node); Assert.IsNotNull(returnedNode, "#A1"); Assert.AreEqual("acomment", returnedNode.Comment, "#A2"); object returnedObj = returnedNode.GetValue((ITypeResolutionService)null); Assert.IsInstanceOfType(typeof(serializable), returnedObj, "#A3"); serializable returnedSer = (serializable)returnedObj; Assert.AreEqual("testName", returnedSer.name, "A4"); finalNode = GetNodeFromResXReader(returnedNode); Assert.IsNotNull(finalNode, "#A5"); Assert.AreEqual("acomment", finalNode.Comment, "#A6"); object finalObj = finalNode.GetValue((ITypeResolutionService)null); Assert.IsInstanceOfType(typeof(serializable), finalObj, "#A7"); serializable finalSer = (serializable)finalObj; Assert.AreEqual("testName", finalSer.name, "A7"); }
public void WriteRead1() { ResXResourceWriter rw = new ResXResourceWriter("resx.resx"); serializable ser = new serializable("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode("test", ser); dn.Comment = "comment"; rw.AddResource(dn); rw.Close(); bool found = false; ResXResourceReader rr = new ResXResourceReader("resx.resx"); IDictionaryEnumerator en = rr.GetEnumerator(); while (en.MoveNext()) { serializable o = ((DictionaryEntry)en.Current).Value as serializable; if (o != null) { found = true; Assert.AreEqual(ser, o, "#A1"); } } rr.Close(); Assert.IsTrue(found, "#A2 - Serialized object not found on resx"); }
public ResXDataNode GetNodeEmdeddedSerializable() { serializable ser = new serializable("testName", "testValue"); ResXDataNode node = new ResXDataNode("test", ser); return(node); }
public void WriteRead1() { serializable ser = new serializable("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode("test", ser); dn.Comment = "comment"; string resXFile = GetResXFileWithNode(dn, "resx.resx"); bool found = false; ResXResourceReader rr = new ResXResourceReader(resXFile); rr.UseResXDataNodes = true; IDictionaryEnumerator en = rr.GetEnumerator(); while (en.MoveNext()) { ResXDataNode node = ((DictionaryEntry)en.Current).Value as ResXDataNode; if (node == null) { break; } serializable o = node.GetValue((AssemblyName [])null) as serializable; if (o != null) { found = true; Assert.AreEqual(ser, o, "#A1"); Assert.AreEqual("comment", node.Comment, "#A3"); } } rr.Close(); Assert.IsTrue(found, "#A2 - Serialized object not found on resx"); }
public void DoesNotRequireResXFileToBeOpen_Serializable() { serializable ser = new serializable("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode("test", ser); string resXFile = GetResXFileWithNode(dn, "resx.resx"); ResXResourceReader rr = new ResXResourceReader(resXFile); rr.UseResXDataNodes = true; IDictionaryEnumerator en = rr.GetEnumerator(); en.MoveNext(); ResXDataNode node = ((DictionaryEntry)en.Current).Value as ResXDataNode; rr.Close(); File.Delete("resx.resx"); Assert.IsNotNull(node, "#A1"); serializable o = node.GetValue((AssemblyName [])null) as serializable; Assert.IsNotNull(o, "#A2"); }
static void SerializeToFile(string filepath, serializable ser) { Stream stream = File.Open(filepath, FileMode.Create); BinaryFormatter bFormatter = new BinaryFormatter(); bFormatter.Serialize(stream, ser); stream.Close(); }
public serializable(Stream stream) { BinaryFormatter bFormatter = new BinaryFormatter(); serializable deser = (serializable)bFormatter.Deserialize(stream); stream.Close(); name = deser.name; value = deser.value; }
public override bool Equals(object obj) { serializable o = obj as serializable; if (o == null) { return(false); } return(this.name.Equals(o.name) && this.value.Equals(o.value)); }
public void RefToSameObjectNotHeld() { ResXDataNode node = GetNodeEmdeddedSerializable(); ResXDataNode returnedNode = GetNodeFromResXReader(node); Assert.IsNotNull(returnedNode, "#A1"); serializable ser1 = (serializable)returnedNode.GetValue((AssemblyName [])null); ser1.name = "beenchanged"; serializable ser2 = (serializable)returnedNode.GetValue((AssemblyName [])null); Assert.AreNotSame(ser1, ser2, "#A2"); }
public ResXDataNode GetNodeFileRefToSerializable(string filename, bool assemblyQualifiedName) { tempFileWithSerializable = Path.GetTempFileName(); // remember to delete file in teardown serializable ser = new serializable("name", "value"); SerializeToFile(tempFileWithSerializable, ser); string typeName; if (assemblyQualifiedName) { typeName = typeof(serializable).AssemblyQualifiedName; } else { typeName = typeof(serializable).FullName; } ResXFileRef fileRef = new ResXFileRef(tempFileWithSerializable, typeName); ResXDataNode node = new ResXDataNode("test", fileRef); return(node); }
public void ITRSPassedToResourceReaderDoesNotAffectResXDataNode_Serializable() { serializable ser = new serializable("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode("test", ser); string resXFile = GetResXFileWithNode(dn, "resx.resx"); ResXResourceReader rr = new ResXResourceReader(resXFile, new ReturnSerializableSubClassITRS()); rr.UseResXDataNodes = true; IDictionaryEnumerator en = rr.GetEnumerator(); en.MoveNext(); ResXDataNode node = ((DictionaryEntry)en.Current).Value as ResXDataNode; Assert.IsNotNull(node, "#A1"); object o = node.GetValue((AssemblyName [])null); AssertHelper.IsNotInstanceOfType(typeof(serializableSubClass), o, "#A2"); Assert.IsInstanceOfType(typeof(serializable), o, "#A3"); rr.Close(); }
public void ITRSPassedToResourceReaderDoesNotAffectResXDataNode_Serializable () { serializable ser = new serializable ("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode ("test", ser); string resXFile = GetResXFileWithNode (dn,"resx.resx"); ResXResourceReader rr = new ResXResourceReader (resXFile, new ReturnSerializableSubClassITRS ()); rr.UseResXDataNodes = true; IDictionaryEnumerator en = rr.GetEnumerator (); en.MoveNext (); ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode; Assert.IsNotNull (node, "#A1"); object o = node.GetValue ((AssemblyName []) null); Assert.IsNotInstanceOfType (typeof (serializableSubClass), o, "#A2"); Assert.IsInstanceOfType (typeof (serializable), o, "#A3"); rr.Close (); }
public void DoesNotRequireResXFileToBeOpen_Serializable () { serializable ser = new serializable ("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode ("test", ser); string resXFile = GetResXFileWithNode (dn,"resx.resx"); ResXResourceReader rr = new ResXResourceReader (resXFile); rr.UseResXDataNodes = true; IDictionaryEnumerator en = rr.GetEnumerator (); en.MoveNext (); ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode; rr.Close (); File.Delete ("resx.resx"); Assert.IsNotNull (node,"#A1"); serializable o = node.GetValue ((AssemblyName []) null) as serializable; Assert.IsNotNull (o, "#A2"); }
public void WriteRead1 () { ResXResourceWriter rw = new ResXResourceWriter ("resx.resx"); serializable ser = new serializable ("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode ("test", ser); dn.Comment = "comment"; rw.AddResource (dn); rw.Close (); bool found = false; ResXResourceReader rr = new ResXResourceReader ("resx.resx"); rr.UseResXDataNodes = true; IDictionaryEnumerator en = rr.GetEnumerator (); while (en.MoveNext ()) { ResXDataNode node = ((DictionaryEntry)en.Current).Value as ResXDataNode; if (node == null) break; serializable o = node.GetValue ((AssemblyName []) null) as serializable; if (o != null) { found = true; Assert.AreEqual (ser, o, "#A1"); Assert.AreEqual ("comment", node.Comment, "#A3"); } } rr.Close (); Assert.IsTrue (found, "#A2 - Serialized object not found on resx"); }
public void Serializable_ITRSUsed () { serializable ser = new serializable ("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode ("test", ser); StringBuilder sb = new StringBuilder (); using (StringWriter sw = new StringWriter (sb)) { using (ResXResourceWriter writer = new ResXResourceWriter (sw)) { writer.AddResource (dn); } } using (StringReader sr = new StringReader (sb.ToString ())) { ResXResourceReader rr = new ResXResourceReader (sr, new ReturnSerializableSubClassITRS ()); IDictionaryEnumerator en = rr.GetEnumerator (); en.MoveNext (); object o = ((DictionaryEntry) en.Current).Value; Assert.IsNotNull (o, "#A1"); Assert.IsInstanceOfType (typeof (serializableSubClass), o,"#A2"); rr.Close (); } }
static void SerializeToFile (string filepath, serializable ser) { Stream stream = File.Open (filepath, FileMode.Create); BinaryFormatter bFormatter = new BinaryFormatter (); bFormatter.Serialize (stream, ser); stream.Close (); }
public ResXDataNode GetNodeFileRefToSerializable (string filename, bool assemblyQualifiedName) { tempFileWithSerializable = Path.GetTempFileName (); // remember to delete file in teardown serializable ser = new serializable ("name", "value"); SerializeToFile (tempFileWithSerializable, ser); string typeName; if (assemblyQualifiedName) typeName = typeof (serializable).AssemblyQualifiedName; else typeName = typeof (serializable).FullName; ResXFileRef fileRef = new ResXFileRef (tempFileWithSerializable, typeName); ResXDataNode node = new ResXDataNode ("test", fileRef); return node; }
public ResXDataNode GetNodeEmdeddedSerializable () { serializable ser = new serializable ("testName", "testValue"); ResXDataNode node = new ResXDataNode ("test", ser); return node; }