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

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 TestClass
	{
		[MyXamlAutoInitialize] private string name;
		[MyXamlAutoInitialize("fullName")] private string name2;

		public string Name
		{
			get {return name;}
		}

		public string FullName
		{
			get {return name2;}
		}

		public TestClass()
		{
			name=null;
			name2=null;
		}
	}

	[TestFixture]
	public class FieldInitializationTests
	{
		protected Parser parser;

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

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

		[Test]
		[ExpectedException(typeof(NoReferenceException))]
		public void NoReferenceTest()
		{
			TestClass tc=new TestClass();
			parser.InitializeFields(tc);
		}

		[Test]
		[ExpectedException(typeof(AutoInitializeException))]
		public void AutoInitializeTypeConversionTest()
		{
			TestClass tc=new TestClass();
			parser.AddReference("name", 1);
			parser.InitializeFields(tc);
		}

		[Test]
		public void AutoInitializeTest()
		{
			TestClass tc=new TestClass();
			parser.AddReference("name", "Marc");
			parser.AddReference("fullName", "Marc Clifton");
			parser.InitializeFields(tc);
			Assertion.Assert(tc.Name=="Marc", "Unexpected result.");
		}
		
		[Test]
		public void AliasTest()
		{
			TestClass tc=new TestClass();
			parser.AddReference("name", "Marc");
			parser.AddReference("fullName", "Marc Clifton");
			parser.InitializeFields(tc);
			Assertion.Assert(tc.FullName=="Marc Clifton", "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
Web01 | 2.8.140827.1 | Last Updated 3 Dec 2011
Article Copyright 2011 by Marc Clifton
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid