From: Owen R. <exo...@us...> - 2005-09-08 02:03:30
|
Update of /cvsroot/netreflector/NetReflector/src/NetReflector.Test/Attributes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20404/src/NetReflector.Test/Attributes Modified Files: ReflectorPropertyTest.cs Log Message: NETREF-5: adding support for customisable serialisation. attributes use DefaultSerialiserFactory by default -- however clients can override for more control over serialisation process. changing implementation to support limitation in that attributes can't take custom types into their properties. passing types instead. Index: ReflectorPropertyTest.cs =================================================================== RCS file: /cvsroot/netreflector/NetReflector/src/NetReflector.Test/Attributes/ReflectorPropertyTest.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ReflectorPropertyTest.cs 8 Sep 2005 01:07:47 -0000 1.1 --- ReflectorPropertyTest.cs 8 Sep 2005 02:03:18 -0000 1.2 *************** *** 1,5 **** using Exortech.NetReflector.Util; - using NMock; - using NMock.Constraints; using NUnit.Framework; --- 1,5 ---- + using System; + using System.Xml; using Exortech.NetReflector.Util; using NUnit.Framework; *************** *** 9,13 **** public class ReflectorPropertyTest { - private ReflectorPropertyAttribute attribute; private ReflectorMember member; --- 9,12 ---- *************** *** 15,19 **** protected void SetUp() { - attribute = new ReflectorPropertyAttribute("foo"); member = ReflectorMember.Create(typeof (TestClass).GetProperty("Name")); } --- 14,17 ---- *************** *** 22,34 **** public void ShouldUseCustomSerialiserFactory() { ! IMock mockSerialiser = new DynamicMock(typeof (IXmlMemberSerialiser)); ! IMock mockFactory = new DynamicMock(typeof (ISerialiserFactory)); ! ! mockFactory.ExpectAndReturn("Create", mockSerialiser.MockInstance, new IsTypeOf(typeof (ReflectorMember)), attribute); ! ! attribute.SerialiserFactory = (ISerialiserFactory) mockFactory.MockInstance; ! attribute.CreateSerialiser(member); ! ! mockFactory.Verify(); } --- 20,27 ---- public void ShouldUseCustomSerialiserFactory() { ! TestCustomSerialiser test = new TestCustomSerialiser(); ! ReflectorPropertyAttribute attribute = (ReflectorPropertyAttribute) test.GetType().GetField("Foo").GetCustomAttributes(typeof(ReflectorPropertyAttribute), true)[0]; ! IXmlSerialiser serialiser = attribute.CreateSerialiser(member); ! Assert.AreEqual(CustomSerialiserFactory.Serialiser, serialiser); } *************** *** 37,44 **** { ReflectorPropertyAttribute attribute = new ReflectorPropertyAttribute("foo"); - IXmlSerialiser serialiser = attribute.CreateSerialiser(member); Assert.IsNotNull(serialiser); } } } \ No newline at end of file --- 30,65 ---- { ReflectorPropertyAttribute attribute = new ReflectorPropertyAttribute("foo"); IXmlSerialiser serialiser = attribute.CreateSerialiser(member); Assert.IsNotNull(serialiser); } } + + internal class CustomSerialiserFactory : ISerialiserFactory + { + public static readonly IXmlSerialiser Serialiser = new CustomSerialiser(); + + public IXmlSerialiser Create(ReflectorMember memberInfo, ReflectorPropertyAttribute attribute) + { + return Serialiser; + } + } + + internal class CustomSerialiser : IXmlSerialiser + { + public void Write(XmlWriter writer, object target) + { + throw new NotImplementedException(); + } + + public object Read(XmlNode node, NetReflectorTypeTable table) + { + throw new NotImplementedException(); + } + } + + internal class TestCustomSerialiser + { + [ReflectorProperty("foo", typeof (CustomSerialiserFactory))] + public int Foo; + } } \ No newline at end of file |