Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Romeo and Juliet

, 3 Dec 2011
Making relationships first class citizens.
XTreePropertyGrid.zip
XTreePropertyGrid
Clifton.Tools.Strings
bin
Debug
Clifton.Tools.Strings.dll
Release
Xml Documentation
obj
Debug
Refactor
TempPE
Xml Documentation
TempPE
UnitTests
Clifton.Windows.Forms
bin
Debug
Clifton.Tools.Strings.dll
Clifton.Windows.Forms.dll
Release
obj
Debug
Refactor
TempPE
Properties
Resources
tv_minus.bmp
tv_plus.bmp
XmlTree
.svn
all-wcprops
entries
prop-base
props
text-base
INode.cs.svn-base
IXtreeNode.cs.svn-base
Node.cs.svn-base
NodeDef.cs.svn-base
NodeInstance.cs.svn-base
NodeMenuItem.cs.svn-base
PlaceholderInstance.cs.svn-base
Popup.cs.svn-base
RootNode.cs.svn-base
XtreeNodeController.cs.svn-base
tmp
prop-base
props
text-base
Myxaml 2.0
MyXaml.Core
bin
Debug
Clifton.Tools.Strings.dll
MyXaml.Core.dll
UnitTest.dll
Release
Xml Documentation
doc
MyXamlCoreUnitTests
obj
Debug
Refactor
TempPE
Release
Xml Documentation
TempPE
MyXaml.WinForms
bin
Debug
Clifton.Tools.Strings.dll
MyXaml.Core.dll
MyXaml.WinForms.dll
UnitTest.dll
Release
Xml Documentation
obj
Debug
Refactor
TempPE
Xml Documentation
TempPE
ROPLib
bin
Debug
ROPLib.dll
XTreeInterfaces.dll
Release
obj
Debug
Refactor
TempPE
Properties
ROPLib.csproj.user
UnitTest
bin
Debug
UnitTest.dll
Release
Xml Documentation
obj
Debug
Refactor
TempPE
Xml Documentation
TempPE
UnitTest.csproj.user
XTreeIIDemo
bin
Debug
Clifton.Tools.Strings.dll
Clifton.Windows.Forms.dll
MyXaml.Core.dll
MyXaml.WinForms.dll
ROPLib.dll
schemaEditor.myxaml
UnitTest.dll
XTreeIIDemo.exe
XTreeIIDemo.vshost.exe
XTreeIIDemo.vshost.exe.manifest
XTreeInterfaces.dll
Properties
XTreeInterfaces
bin
Debug
XTreeInterfaces.dll
Release
obj
Debug
TempPE
Properties
using System;

using Vts.UnitTest;

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

namespace MyXamlCoreUnitTests
{
	public class FirstTestClass
	{
		private SecondTestClass secondTestClass;

		public SecondTestClass SecondTestClass
		{
			get {return secondTestClass;}
		}

		public FirstTestClass()
		{
			secondTestClass=new SecondTestClass();
		}
	}

	public class SecondTestClass
	{
		protected string val;

		public string Value
		{
			get {return val;}
		}

		public SecondTestClass()
		{
			val="Marc";
		}
	}

	[TestFixture]
	public class ReferenceTests
	{
		protected Parser parser;

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

		[Test]
		[ExpectedException(typeof(ArgumentException))]
		public void AddReferenceNullNameTest()
		{
			parser.AddReference(null, this);
		}

		[Test]
		[ExpectedException(typeof(ArgumentException))]
		public void RemoveReferenceNullNameTest()
		{
			parser.RemoveReference(null);
		}

		[Test]
		[ExpectedException(typeof(ArgumentException))]
		public void ContainsReferenceNullNameTest()
		{
			parser.ContainsReference(null);
		}

		[Test]
		[ExpectedException(typeof(ArgumentException))]
		public void GetReferenceNullNameTest()
		{
			parser.GetReference(null);
		}
		
		[Test]
		[ExpectedException(typeof(ArgumentException))]
		public void UpdateReferenceNullNameTest()
		{
			parser.UpdateReference(null, this);
		}
		
		[Test]
		[ExpectedException(typeof(ReferenceExistsException))]
		public void AddExistingReferenceTest()
		{
			parser.AddReference("Test", this);
			parser.AddReference("Test", this);
		}
		
		[Test]
		[ExpectedException(typeof(NoReferenceException))]
		public void RemoveMissingReferenceTest()
		{
			parser.RemoveReference("Test");
		}

		[Test]
		public void AddReferenceTest()
		{
			parser.AddReference("Test", this);
			Assertion.Assert(parser.GetReference("Test")==this, "Unexpected result.");
		}

		[Test]
		public void UpdateReferenceTest()
		{
			parser.AddReference("Test", this);
			parser.UpdateReference("Test", parser);
			Assertion.Assert(parser.GetReference("Test")==parser, "Unexpected result.");
		}

		[Test]
		public void RemoveReferenceTest()
		{
			parser.AddReference("Test", this);
			parser.RemoveReference("Test");
			Assertion.Assert(!parser.ContainsReference("Test"), "Unexpected result.");
		}

		[Test]
		[ExpectedException(typeof(ArgumentException))]
		public void BadSourceCopyTest()
		{
			parser.CopyReferencesFrom(null);
		}

		[Test]
		public void CopyReferencesTest()
		{
			parser.AddReference("Test", this);
			Parser p2=new Parser();
			p2.CopyReferencesFrom(parser);
			Assertion.Assert(p2.ContainsReference("Test"), "Unexpected result.");
		}

		[Test]
		[ExpectedException(typeof(NoReferenceException))]
		public void SimpleResolveFailureTest()
		{
			FirstTestClass ftc=new FirstTestClass();
			parser.AddReference("ftc", ftc);
			parser.ResolveValue("ftc2");
		}

		[Test]
		[ExpectedException(typeof(ImproperComplexReferenceException))]
		public void ComplexResolveFailureTest()
		{
			FirstTestClass ftc=new FirstTestClass();
			parser.AddReference("ftc", ftc);
			parser.ResolveValue("ftc.foobar");
		}

		[Test]
		public void ResolveSimpleValueTest()
		{
			FirstTestClass ftc=new FirstTestClass();
			parser.AddReference("ftc", ftc);
			object obj=parser.ResolveValue("ftc");
			Assertion.Assert(ftc==obj, "Unexpected result.");
		}

		[Test]
		public void ResolveComplexPropertyValueTest()
		{
			FirstTestClass ftc=new FirstTestClass();
			parser.AddReference("ftc", ftc);
			object obj=parser.ResolveValue("ftc.SecondTestClass.Value");
			Assertion.Assert(obj.ToString()=="Marc", "Unexpected result.");
		}

		[Test]
		public void ResolveComplexFieldValueTest()
		{
			FirstTestClass ftc=new FirstTestClass();
			parser.AddReference("ftc", ftc);
			object obj=parser.ResolveValue("ftc.secondTestClass.val");
			Assertion.Assert(obj.ToString()=="Marc", "Unexpected result.");
		}
	}
}

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)

Share

About the Author

Marc Clifton

United States United States
Marc is the creator of two open source projets, MyXaml, a declarative (XML) instantiation engine and the Advanced Unit Testing framework, and Interacx, a commercial n-tier RAD application suite.  Visit his website, www.marcclifton.com, where you will find many of his articles and his blog.
 
Marc lives in Philmont, NY.

| Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 3 Dec 2011
Article Copyright 2011 by Marc Clifton
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid