Re: Trouble with Custom PropertyAttribute-SerializationException with enum parameter
"Walker Jay W" <[email protected]>
| Newsgroups | gmane.comp.windows.dotnet.nunit.user |
|---|---|
| Message-ID | <EB576B995DA9DF4894A78EE7450C0E0C01F5C29F@AUS0010CP3MB02.ds.irsnet.gov> |
Thanks Charlie,
Your suggestion to modify the constructor worked. I modified the derived
constructor to pass a string to the attribute base constructor on line 5
below. Can the sample docs be updated to reflect this change? I think
others would benefit.
1 [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
2 public class TraceabilityAttribute : PropertyAttribute
3 {
4 public TraceabilityAttribute(Requirement level)
5 : base(level.ToString())
6 {
7 }
8 }
I noticed that a CustomProperty or a Property for a given propertyName
will only show up once in the results. Is this by design? It would be
very helpful for my needs to be able to specify a property multiple
times. Here are some examples:
[Test]
[Property("Traceability", "Requirement1")]
[Property("Traceability", "Requirement2")]
public void SimplePropertyMultipleTest()
{ /* ... */ }
[Test]
[Property("Traceability", "Requirement1")]
[Property("Traceability", "Requirement2")]
[Property("SomethingElse", "Value1")]
[Property("SomethingElse", "Value2")]
public void SimplePropertyMultipleDifferentTest()
{ /* ... */ }
[Test]
[Traceability(Requirement.Requirement2)]
[Traceability(Requirement.Requirement3)]
public void CustomPropertyMultipleTest()
{ /*...*/ }
And the resulting xml that includes only 1 <property> entry for a
CustomProperty or Property/PropertyName combination:
<test-case name="... SimplePropertyMultipleTest" ... >
<properties>
<property name="Traceability" value="Requirement1" />
</properties>
</test-case>
<test-case name="... SimplePropertyMultipleDifferentTest" ... >
<properties>
<property name="Traceability" value="Requirement1" />
<property name="SomethingElse" value="Value2" />
</properties>
</test-case>
<test-case name="... CustomPropertyMultipleTest" ... >
<properties>
<property name="Traceability" value="Requirement3" />
</properties>
</test-case>
-----Original Message-----
From: Charlie Poole [mailto:[email protected]]
Sent: Wednesday, November 28, 2007 11:46 PM
To: [email protected]
Subject: Re: [Nunit-users] Trouble with Custom
PropertyAttribute-SerializationException with enum parameter
Hi Jay,
For this to work, you have to make sure that the data in the attribute
itself is of a type that NUnit knows without loading your assembly.
(Yes, NUnit has loaded your assembly in the test domain, but it is not
loaded in the primary domain where the gui or console is running. You
can think of the test domain as a sandbox.)
I think the easiest way to do this is to have your own constructor,
which sets the value of the property to the string name of the enum
value.
Charlie
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4