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