[Adapdev-commits] Adapdev/src/Adapdev.Windows.Forms.Tests Adapdev.Windows.Forms.Tests.csproj,1.5,1.6
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-11-16 07:02:12
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Windows.Forms.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv909/src/Adapdev.Windows.Forms.Tests Added Files: Adapdev.Windows.Forms.Tests.csproj SmartTreeViewTest.cs Log Message: --- NEW FILE: Adapdev.Windows.Forms.Tests.csproj --- <VisualStudioProject> <CSHARP ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{D51D807A-D70C-445A-B1D9-062D61463AB7}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "Adapdev.Windows.Forms.Tests" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" PreBuildEvent = "" PostBuildEvent = "" RootNamespace = "Adapdev.Windows.Forms.Tests" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "" > <Config Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "DEBUG;TRACE" DocumentationFile = "" DebugSymbols = "true" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "false" OutputPath = "bin\Debug\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> <Config Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "TRACE" DocumentationFile = "" DebugSymbols = "false" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "true" OutputPath = "bin\Release\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll" /> <Reference Name = "System.Data" AssemblyName = "System.Data" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" /> <Reference Name = "log4net" AssemblyName = "log4net" HintPath = "..\..\lib\log4net.dll" /> <Reference Name = "nunit.framework" AssemblyName = "nunit.framework" HintPath = "..\..\lib\nunit.framework.dll" /> <Reference Name = "Adapdev.Windows.Forms" Project = "{0BE602B6-D67E-414E-B852-A2AC61305E8E}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> <Reference Name = "System.Windows.Forms" AssemblyName = "System.Windows.Forms" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Windows.Forms.dll" /> <Reference Name = "System.Drawing" AssemblyName = "System.Drawing" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll" /> </References> </Build> <Files> <Include> <File RelPath = "AdapdevAssemblyInfo.cs" Link = "..\AdapdevAssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "SmartTreeViewTest.cs" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </CSHARP> </VisualStudioProject> --- NEW FILE: SmartTreeViewTest.cs --- using System; using System.Windows.Forms; using NUnit.Framework; using Adapdev.Windows.Forms; namespace Adapdev.Windows.Forms.Tests { using System.Drawing; /// <summary> /// Summary description for SmartTreeViewTest. /// </summary> /// [TestFixture] public class SmartTreeViewTest { SmartTreeView tree = null; [SetUp] public void BuildTree() { tree = new SmartTreeView(); TreeNode root = new TreeNode("Root"); tree.Nodes.Add(root); TreeNode node1 = new TreeNode("Node1"); TreeNode child1 = new TreeNode("Child1"); TreeNode child2 = new TreeNode("Child2"); node1.Nodes.Add(child1); node1.Nodes.Add(child2); TreeNode node2 = new TreeNode("Node2"); TreeNode child3 = new TreeNode("Child3"); TreeNode child4 = new TreeNode("Child4"); node2.Nodes.Add(child3); node2.Nodes.Add(child4); root.Nodes.Add(node1); root.Nodes.Add(node2); /* * Structure: * Root * Node1 * Child1 * Child2 * Node2 * Child3 * Child4 **/ } [Test] public void CheckParents() { // Make sure all nodes are at the proper state Assert.IsTrue(this.GetChild1().Checked == false, "Child1 should not be checked."); Assert.IsTrue(this.GetNode1().Checked == false, "Node1 should not be checked."); Assert.IsTrue(this.GetRoot().Checked == false, "Root should not be checked."); // Check the child, which should check all parents this.GetChild1().Checked = true; Assert.IsTrue(this.GetNode1().Checked, "Node1 should be checked."); Assert.IsTrue(this.GetRoot().Checked, "Root should be checked."); // Uncheck the child...parents should remain checked this.GetChild1().Checked = false; Assert.IsTrue(this.GetNode1().Checked, "Node1 should be checked."); Assert.IsTrue(this.GetRoot().Checked, "Root should be checked."); } [Test] public void CheckChildren() { // Make sure all nodes are at the proper state Assert.IsTrue(this.GetChild1().Checked == false, "Child1 should not be checked."); Assert.IsTrue(this.GetNode1().Checked == false, "Node1 should not be checked."); Assert.IsTrue(this.GetRoot().Checked == false, "Root should not be checked."); // Check the root node this.GetRoot().Checked = true; // All child nodes should be checked Assert.IsTrue(this.GetRoot().Checked, "Root should be checked."); Assert.IsTrue(this.GetNode1().Checked, "Node1 should be checked."); Assert.IsTrue(this.GetNode2().Checked, "Node2 should be checked."); Assert.IsTrue(this.GetChild1().Checked, "Child1 should be checked."); Assert.IsTrue(this.GetChild2().Checked, "Child2 should be checked."); Assert.IsTrue(this.GetChild3().Checked, "Child3 should be checked."); Assert.IsTrue(this.GetChild4().Checked, "Child4 should be checked."); // Uncheck the root node this.GetRoot().Checked = false; // All child nodes should be unchecked Assert.IsFalse(this.GetRoot().Checked, "Root should not be checked."); Assert.IsFalse(this.GetNode1().Checked, "Node1 should not be checked."); Assert.IsFalse(this.GetNode2().Checked, "Node2 should not be checked."); Assert.IsFalse(this.GetChild1().Checked, "Child1 should not be checked."); Assert.IsFalse(this.GetChild2().Checked, "Child2 should not be checked."); Assert.IsFalse(this.GetChild3().Checked, "Child3 should not be checked."); Assert.IsFalse(this.GetChild4().Checked, "Child4 should not be checked."); } [Test] public void CheckColor() { // IMPORTANT - need to set the root node checked value // Test fails otherwise, since the Color comes up // as Color.Empty this.GetRoot().Checked = false; // Node1 should be unchecked and light gray Assert.AreEqual(Color.LightGray, this.GetNode1().ForeColor, "Node1 unchecked color is incorrect."); // Root should be unchecked and light gray Assert.AreEqual(Color.LightGray, this.GetRoot().ForeColor, "Root unchecked color is incorrect."); this.GetNode1().Checked = true; // Node1 should be checked and black Assert.AreEqual(Color.Black, this.GetNode1().ForeColor); // Root should be checked and black Assert.AreEqual(Color.Black, this.GetRoot().ForeColor); } [Test] public void ValidateStructure() { Assert.AreEqual("Root", this.GetRoot().Text); Assert.AreEqual("Node1", this.GetNode1().Text); Assert.AreEqual("Node2", this.GetNode2().Text); Assert.AreEqual("Child1", this.GetChild1().Text); Assert.AreEqual("Child2", this.GetChild2().Text); Assert.AreEqual("Child3", this.GetChild3().Text); Assert.AreEqual("Child4", this.GetChild4().Text); } [Test] public void GetUniqueNodeName() { Assert.AreEqual("Root", tree.GetUniqueNodeName(this.GetRoot())); Assert.AreEqual("Node1Root", tree.GetUniqueNodeName(this.GetNode1())); Assert.AreEqual("Child1Node1Root", tree.GetUniqueNodeName(this.GetChild1())); } [Test] public void GetState() { this.tree.StateChanged += new StateChangedEventHandler(tree_StateChanged); ; this.GetRoot().Checked = false; this.GetNode1().Checked = false; Assert.IsTrue(this.GetNode1().Checked == false, "Node1 should not be checked initially"); // Check it - checked state should be saved this.GetNode1().Checked = true; Assert.IsTrue(tree.GetState(this.GetNode1()), "State wasn't saved for Node1"); string node1a = tree.GetUniqueNodeName(this.GetNode1()); // Remove it this.GetNode2().Remove(); this.GetNode1().Remove(); // Readd it this.GetRoot().Nodes.Add("Node1"); this.GetRoot().Nodes.Add("Node2"); string node2a = tree.GetUniqueNodeName(this.GetNode1()); Assert.AreEqual(node1a, node2a, "Nodes should be the same for state monitoring."); Assert.IsFalse(this.GetNode1().Checked, "Node1 should not be checked after being added"); Assert.IsFalse(this.GetNode2().Checked, "Node2 should not be checked before LoadState."); Assert.IsTrue(tree.HasState(this.GetNode1()), "State no longer exists for Node1"); Assert.IsTrue(tree.GetState(this.GetNode1()), "State should still be true."); // Load the state this.tree.LoadState(); Assert.IsTrue(this.GetNode1().Checked == true, "Node1 should be checked."); Assert.IsTrue(this.GetNode2().Checked == false, "Node1 should not be checked after LoadState."); // Clear the state and reload this.tree.ClearState(); this.GetNode1().Checked = false; this.tree.LoadState(); Assert.IsFalse(this.GetNode1().Checked == true, "Node1 should not be checked since state was cleared."); } #region Utility Methods private TreeNode GetRoot() { return tree.Nodes[0]; } private TreeNode GetNode1() { return this.GetRoot().Nodes[0]; } private TreeNode GetNode2() { return this.GetRoot().Nodes[1]; } private TreeNode GetChild1() { return this.GetNode1().Nodes[0]; } private TreeNode GetChild2() { return this.GetNode1().Nodes[1]; } private TreeNode GetChild3() { return this.GetNode2().Nodes[0]; } private TreeNode GetChild4() { return this.GetNode2().Nodes[1]; } #endregion private void tree_StateChanged(TreeNode node, bool state) { //Console.WriteLine("{0} changed to {1}", node.Text, state); } } } |