Click here to Skip to main content
15,886,362 members
Articles / Programming Languages / C# 4.0

Relationship Oriented Programming - The IDE plus More on Agile Project Management

Rate me:
Please Sign up or sign in to vote.
4.98/5 (25 votes)
12 Mar 2012CPOL81 min read 77.5K   1.2K   49  
An Integrated Development Environment (IDE) for the Relationship Oriented Programming Tool.
using System;
using System.Xml;

using Vts.UnitTest;

using MyXaml.Core;
using MyXaml.Core.Exceptions;

namespace MyXamlCoreUnitTests
{
	public class AnotherHandler
	{
		protected bool clicked;

		public bool Clicked
		{
			get {return clicked;}
		}

		public void OnClick(object sender, EventArgs e)
		{
			clicked=true;
		}
	}

	public class AnEventTestClass
	{
		public event EventHandler Click;

		protected string val;
		protected bool clicked;

		public string ReadOnlyValue
		{
			get {return val;}
		}

		public string ReadWriteValue
		{
			get {return val;}
			set {val=value;}
		}

		public bool Clicked
		{
			get {return clicked;}
		}

		public void DoClick()
		{
			Click(null, EventArgs.Empty);
		}

		public void OnClick(object sender, EventArgs e)
		{
			clicked=true;
		}
	}

	[TestFixture]
	public class EventWireupTests
	{
		protected Parser parser;

		[SetUp]
		public void SetUp()
		{
			parser=new Parser();
		}

		[Test]
		[ExpectedException(typeof(ReferencedEventMissingHandlerException))]
		public void MissingHandlerInReferenceTest()
		{
			string xml="<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
			xml+="<!-- (c) 2005 MyXaml  All Rights Reserved  -->\r\n";
			xml+="<MyXaml\r\n";
			xml+="  xmlns:def=\"Definition\"\r\n";
			xml+="  xmlns:ref=\"Reference\"\r\n";
			xml+="  xmlns=\"MyXamlCoreUnitTests\">\r\n";
			xml+="  <AnEventTestClass Click='{AnotherHandler}'/>\r\n";
			xml+="</MyXaml>\r\n";
			parser.InstantiateFromString(xml, "*");
		}

		[Test]
		public void LocalEventTest()
		{
			string xml="<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
			xml+="<!-- (c) 2005 MyXaml  All Rights Reserved  -->\r\n";
			xml+="<MyXaml\r\n";
			xml+="  xmlns:def=\"Definition\"\r\n";
			xml+="  xmlns:ref=\"Reference\"\r\n";
			xml+="  xmlns=\"MyXamlCoreUnitTests\">\r\n";
			xml+="  <AnEventTestClass Click='OnClick'/>\r\n";
			xml+="</MyXaml>\r\n";

			AnEventTestClass tc=(AnEventTestClass)parser.InstantiateFromString(xml, "*");
			tc.DoClick();
			Assertion.Assert(tc.Clicked, "Event not wired up.");
		}

		[Test]
		public void ReferencedEventTest()
		{
			string xml="<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
			xml+="<!-- (c) 2005 MyXaml  All Rights Reserved  -->\r\n";
			xml+="<MyXaml\r\n";
			xml+="  xmlns:def=\"Definition\"\r\n";
			xml+="  xmlns:ref=\"Reference\"\r\n";
			xml+="  xmlns=\"MyXamlCoreUnitTests\">\r\n";
			xml+="  <AnEventTestClass Click='{AnotherHandler.OnClick}'/>\r\n";
			xml+="</MyXaml>\r\n";

			AnotherHandler h=new AnotherHandler();
			parser.AddReference("AnotherHandler", h);

			AnEventTestClass tc=(AnEventTestClass)parser.InstantiateFromString(xml, "*");
			tc.DoClick();
			Assertion.Assert(h.Clicked, "Event not wired up.");
		}

		// Foo Click='A, B, C'
		// late binding events (use markup pre/post to test early/late binding)
		// handler method doesn't match event signature test.
	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Interacx
United States United States
Blog: https://marcclifton.wordpress.com/
Home Page: http://www.marcclifton.com
Research: http://www.higherorderprogramming.com/
GitHub: https://github.com/cliftonm

All my life I have been passionate about architecture / software design, as this is the cornerstone to a maintainable and extensible application. As such, I have enjoyed exploring some crazy ideas and discovering that they are not so crazy after all. I also love writing about my ideas and seeing the community response. As a consultant, I've enjoyed working in a wide range of industries such as aerospace, boatyard management, remote sensing, emergency services / data management, and casino operations. I've done a variety of pro-bono work non-profit organizations related to nature conservancy, drug recovery and women's health.

Comments and Discussions