Menu

[r98]: / UnitTests / SerializationTest.cs  Maximize  Restore  History

Download this file

42 lines (36 with data), 1.3 kB

 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
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using Aga.Controls.Tree;
using System.Reflection;
using System.Globalization;
namespace Aga.Controls.UnitTests
{
[TestClass]
public class SerializationTest
{
[TestMethod]
public void TestTreeNodeAdv()
{
PropertyInfo prop = typeof(TreeNodeAdv).GetProperty("Nodes", BindingFlags.NonPublic | BindingFlags.Instance);
TreeNodeAdv node = new TreeNodeAdv("root");
node.IsExpanded = true;
ICollection<TreeNodeAdv> nodes = (ICollection<TreeNodeAdv>)prop.GetValue(node, null);
nodes.Add(new TreeNodeAdv("ch0"));
nodes.Add(new TreeNodeAdv("ch2"));
MemoryStream ms = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(ms, node);
ms.Position = 0;
TreeNodeAdv node2 = formatter.Deserialize(ms) as TreeNodeAdv;
Assert.AreEqual(node.Tag, node2.Tag);
Assert.AreEqual(node.IsExpanded, node2.IsExpanded);
Assert.AreEqual(node.Children.Count, node2.Children.Count);
for (int i = 0; i < node.Children.Count; i++)
Assert.AreEqual(node.Children[i].Tag, node2.Children[i].Tag);
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.