Click here to Skip to main content
15,898,134 members
Articles / Programming Languages / C#

Article Two: Building a UI Platform in C# - Testing via UI Animation

,
Rate me:
Please Sign up or sign in to vote.
4.20/5 (7 votes)
3 Mar 20055 min read 51.4K   927   33  
Describes an implementation of UI animation for the support of Test-Driven Development.
// (c) 2003-2005 Datron, Inc.  All rights reserved. http://www.blix.net

using System;
using System.Runtime.Serialization;
using UITestingFramework;

namespace freeBlix
{
	[Serializable]
	public class PaintState: CaseState, ISerializable, IColorCollection, ILeft, ITop, IRight, IBottom, IWidth, IHeight, IPaintStateCollection					 														 										 									 
	{		
		#region Fields
		private System.Drawing.Bitmap _Offscreen;
		private RectangleColorSample _ColorSample;
		private int _Left;
		private int _Top;
		private int _Right;
		private int _Bottom;
		private int _Width;
		private int _Height;
		private PaintStateCollection _States;
		private string _ControlType;
		#endregion

		#region PaintState()
		public PaintState()
		{
			_States = new PaintStateCollection();
		}
		#endregion
	
		#region ExtractTestValues
		public override void ExtractTestValues()
		{
			Control control = (Control) TestObject;
		
			_ControlType = control.GetType().Name;

			_ColorSample = new RectangleColorSample(control, _Offscreen);

			if (((IBounds) control).Bounds is Rectangle)
			{
				Rectangle rectangle = (Rectangle) ((IBounds)control).Bounds;

				_Left = rectangle.Left;
				_Top = rectangle.Top;
				_Right = rectangle.Right;
				_Bottom = rectangle.Bottom;
				_Width = rectangle.Width;
				_Height = rectangle.Height;
			}		

			_States.Clear();

			if (control is ControlOverlay)
			{
				ControlOverlay controlOverlay = (ControlOverlay) control;

				foreach (Control childControl in ((IChildren)controlOverlay).Children.Controls)
				{
					PaintState childState = new PaintState();

					childState.Offscreen = _Offscreen;

					childState.TestObject = childControl;

					childState.ExtractTestValues();

					_States.Add(childState);
				}
			}
		}
		#endregion			
		
		#region ControlType
		public string ControlType
		{
			get
			{
				return _ControlType;
			}
		}
		#endregion
		#region Offscreen
		public System.Drawing.Bitmap Offscreen
		{
			get
			{
				return _Offscreen;
			}
			set
			{
				_Offscreen = value;
			}
		}
		#endregion		

		#region IColorCollection
		ColorCollection IColorCollection.Colors
		{
			get
			{
				if (_ColorSample != null)
					return _ColorSample.Colors;
				else
					return new ColorCollection();
			}
		}
		#endregion				
		#region ILeft
		int ILeft.Left
		{
			get
			{
				return _Left;
			}
		}
		#endregion
		#region ITop
		int ITop.Top
		{
			get
			{
				return _Top;
			}			
		}
		#endregion
		#region IWidth
		int IWidth.Width
		{
			get
			{
				return _Width;
			}			
		}
		#endregion
		#region IHeight
		int IHeight.Height
		{
			get
			{
				return _Height;
			}			
		}
		#endregion
		#region IRight
		int IRight.Right
		{
			get
			{
				return _Right;
			}			
		}
		#endregion
		#region IBottom
		int IBottom.Bottom
		{
			get
			{
				return _Bottom;
			}
		}
		#endregion		
		#region IPaintStateCollection
		PaintStateCollection IPaintStateCollection.States
		{
			get
			{
				return _States;
			}
		}
		#endregion		

		#region ISerializable
		protected PaintState(SerializationInfo aInfo, StreamingContext aContext)
		{
			_ColorSample = (RectangleColorSample) aInfo.GetValue("_ColorSample", typeof(RectangleColorSample));
			_States = (PaintStateCollection) aInfo.GetValue("_States", typeof(PaintStateCollection));
			_ControlType = (string) aInfo.GetValue("_ControlType", typeof(string));
			_Left = (int) aInfo.GetValue("_Left", typeof(int));
			_Top = (int) aInfo.GetValue("_Top", typeof(int));
			_Right = (int) aInfo.GetValue("_Right", typeof(int));
			_Bottom = (int) aInfo.GetValue("_Bottom", typeof(int));
			_Width = (int) aInfo.GetValue("_Width", typeof(int));
			_Height = (int) aInfo.GetValue("_Height", typeof(int));
		}
		public override void GetObjectData(SerializationInfo aInfo, StreamingContext aContext)
		{		
			aInfo.AddValue("_ColorSample", _ColorSample);
			aInfo.AddValue("_States", _States);
			aInfo.AddValue("_ControlType", _ControlType);
			aInfo.AddValue("_Left", _Left);
			aInfo.AddValue("_Top", _Top);
			aInfo.AddValue("_Right", _Right);
			aInfo.AddValue("_Bottom", _Bottom);
			aInfo.AddValue("_Width", _Width);
			aInfo.AddValue("_Height", _Height);
		}
		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
CEO Sagerion, LLC
United States United States
I read About Face by Alan Cooper in 1995 and immediately recognized it as a founding document for the future of software. I also recognized we had a long, long way to go - and yes, even with the advent of iOS, we are still not there yet.

At my company, Sagerion (say-jair-ee-on), we can take a look at your planned or existing software and suggest ways of making it better - lots better. We can develop down-to-the-pixel blueprints showing exactly what our suggestions mean. We can help manage on-going development to make sure the top-notch user-experience we've suggested really does get built. Now, honestly, how often have you ever seen all those things happen?

You may or may not already have great development going on - but what does that matter if you don't have great design driving it?

Feel free to contact me at tom@sagerion.com, I would love to hear about your next ground-breaking project.

Written By
Founder Sagerion LLC
United States United States
www.filoshare.com
-It is a fresh and free distributed source control system.

Comments and Discussions