﻿// The following code was generated by Microsoft Visual Studio 2005.
// The test owner should check each test for validity.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Text;
using System.Collections.Generic;
using Aga.Controls.Tree;
namespace TestProject1
{
	[TestClass]
	public class NodeTest
	{
		[TestMethod]
		public void ParentTest()
		{
			Node r1 = new Node("");
			Node node = new Node("");

			r1.Nodes.Add(node);
			Assert.AreEqual(1, r1.Nodes.Count);
			Assert.AreEqual(r1, node.Parent);

			r1.Nodes.Remove(node);
			Assert.AreEqual(0, r1.Nodes.Count);
			Assert.AreEqual(null, node.Parent);

			node.Parent = r1;
			Assert.AreEqual(1, r1.Nodes.Count);
			Assert.AreEqual(r1, node.Parent);

			node.Parent = null;
			Assert.AreEqual(0, r1.Nodes.Count);
			Assert.AreEqual(null, node.Parent);


			Node r2 = new Node("");
			node.Parent = r1;

			node.Parent = r2;
			Assert.AreEqual(1, r2.Nodes.Count);
			Assert.AreEqual(0, r1.Nodes.Count);
			Assert.AreEqual(r2, node.Parent);

			r1.Nodes.Add(node);
			Assert.AreEqual(1, r1.Nodes.Count);
			Assert.AreEqual(0, r2.Nodes.Count);
			Assert.AreEqual(r1, node.Parent);



			Node node2 = new Node("");
			r1.Nodes[0] = node2;
			Assert.AreEqual(null, node.Parent);
			Assert.AreEqual(r1, node2.Parent);
		}

		private int remove, insert;
		[TestMethod]
		public void ModelTest()
		{
			TreeModel model = new TreeModel();
			model.NodesInserted += new EventHandler<TreeModelEventArgs>(model_NodesInserted);
			model.NodesRemoved += new EventHandler<TreeModelEventArgs>(model_NodesRemoved);

			remove = 0;
			insert = 0;
			Node node = new Node("");
			model.Root.Nodes.Add(node);
			model.Root.Nodes.Remove(node);
			Assert.AreEqual(1, remove);
			Assert.AreEqual(1, insert);
		}

		void model_NodesRemoved(object sender, TreeModelEventArgs e)
		{
			remove++;
		}

		void model_NodesInserted(object sender, TreeModelEventArgs e)
		{
			insert++;
		}

	}
}
