Rank: Newbie
Groups: Registered
Joined: 9/13/2011(UTC) Posts: 3
|
It seems that something in the way NCrunch executes tests causes problems with reflection. Consequently I'm unable to set or access configuration properties with declared default value on configuration elements. All tests in example below fail with following exception when executing in NCrunch. All tests execute successfully in NUnit runner. If property DefaultValue is removed from configuration element property, all tests with exception of 'AccessPropertyWithDefaultValue' execute successfully in NCrunch and NUnit. Can this problem be fixed with appropriate configuration? Code:
System.Reflection.CustomAttributeFormatException : 'DefaultValue' property specified was not found.
----> System.Reflection.CustomAttributeFormatException : 'DefaultValue' property specified was not found.
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)
at System.Reflection.RuntimePropertyInfo.GetCustomAttributes(Type attributeType, Boolean inherit)
at System.Attribute.InternalGetCustomAttributes(PropertyInfo element, Type type, Boolean inherit)
at System.Attribute.GetCustomAttributes(MemberInfo element, Type type, Boolean inherit)
at System.Attribute.GetCustomAttribute(MemberInfo element, Type attributeType, Boolean inherit)
at System.Configuration.ConfigurationElement.CreateConfigurationPropertyFromAttributes(PropertyInfo propertyInformation)
at System.Configuration.ConfigurationElement.CreatePropertyBagFromType(Type type)
at System.Configuration.ConfigurationElement.PropertiesFromType(Type type, ConfigurationPropertyCollection& result)
at System.Configuration.ConfigurationElement.get_Properties()
at System.Configuration.ConfigurationElement.get_Item(String propertyName)
at NCrunchBugs.SampleConfigurationElement.get_First() in c:\Users\blorger\AppData\Local\NCrunch\4828\16\NCrunchBugs\DefaultConfigurationValuesBug.cs:line 47
at NCrunchBugs.DefaultConfigurationValuesBug.AccessPropertyWithDefaultValue() in c:\Users\blorger\AppData\Local\NCrunch\4828\16\NCrunchBugs\DefaultConfigurationValuesBug.cs:line 28
--CustomAttributeFormatException
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
Code:
using System.Configuration;
using NUnit.Framework;
namespace NCrunchBugs
{
[TestFixture]
public class DefaultConfigurationValuesBug
{
[Test]
public static void SetPropertyWithDefaultValue()
{
var s = new SampleConfigurationElement();
s.First = "dd";
}
[Test]
public static void SetPropertyWithoutDefaultValue()
{
var s = new SampleConfigurationElement();
s.Second = "dd";
}
[Test]
public static void AccessPropertyWithDefaultValue()
{
var s = new SampleConfigurationElement();
Assert.That(s.First, Is.Not.Empty);
}
[Test]
public static void AccessPropertyWithoutDefaultValue()
{
var s = new SampleConfigurationElement();
Assert.That(s.Second, Is.Empty);
}
}
public class SampleConfigurationElement : ConfigurationElement
{
private const string FirstProperty = "first";
private const string SecondProperty = "second";
[ConfigurationProperty(FirstProperty, DefaultValue = "something")]
public string First
{
get { return (string)this[FirstProperty]; }
set { this[FirstProperty] = value; }
}
[ConfigurationProperty(SecondProperty)]
public string Second
{
get { return (string)this[SecondProperty]; }
set { this[SecondProperty] = value; }
}
}
}
|