Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

problem with app.config file
4rchie
#1 Posted : Wednesday, October 12, 2011 4:54:35 AM(UTC)
Rank: Member

Groups: Registered
Joined: 10/12/2011(UTC)
Posts: 27
Location: Poland

Thanks: 2 times
Was thanked: 6 time(s) in 6 post(s)
I have a code that relies on a specific app.config file. The test project contains some tests that check the code which read the appp.config. I do have the config file prepared but I have no clue how to tell NCrunch to use that specific app.config while testing that specific assembly. Any clues how can I do that??

Regards
4rchie
Remco
#2 Posted : Wednesday, October 12, 2011 11:34:51 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Hi 4rchie,

Thanks for posting. NCrunch should resolve your app.config file in the same way that other test runners do. Do you have any interesting build steps (i.e. a post build event?) that may be needed as part of preparing this config? Note that you can have a look at the workspace NCrunch used to run your tests by right clicking on a test and choosing 'Browse to workspace used for selected test'.

Cheers,

Remco
4rchie
#3 Posted : Thursday, October 13, 2011 5:55:00 AM(UTC)
Rank: Member

Groups: Registered
Joined: 10/12/2011(UTC)
Posts: 27
Location: Poland

Thanks: 2 times
Was thanked: 6 time(s) in 6 post(s)
I have nothing in the post build event.

The code I'm trying to test is:

public static MyServersCollection MyServers
{
get
{
var section = (MyConfigurationSection)ConfigurationManager.GetSection("myConfiguration");
return section != null ? section.MyServers : null;
}
}

In a brief, I have some classes that enhance my app.config.

The test that uses that is not executed - black dot - so I cannot do Browse to workspace used for selected test. In NCrunch Tests that particular test is having Running (First time run) status for ages. Im using the latest NCrunch. Any ideas for me?

Regards,
4rchie


update: I was missing a

<configSections>
<section name="myConfiguration" type=...../>
</configSections>

part in the app.config After adding that the tests are executed and.... fail due to some other error but I hope I'll find that soon.
Remco
#4 Posted : Thursday, October 13, 2011 6:19:28 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Ok - I don't think this is a problem related to your configuration ... something else is going on.

Is the test ignored in the Tests Window? Or does it show with a green tick?
4rchie
#5 Posted : Thursday, October 13, 2011 6:40:20 AM(UTC)
Rank: Member

Groups: Registered
Joined: 10/12/2011(UTC)
Posts: 27
Location: Poland

Thanks: 2 times
Was thanked: 6 time(s) in 6 post(s)
Test is not ignored. It runs now (after adding missing configSections in the app.config) but it fails. Funny thing is that it runs under the resharper runner but it fails under ncrunch (with an error like below):



SetUp : System.Configuration.ConfigurationErrorsException : An error occurred creating the configuration section handler for liderConfiguration: 'DefaultValue' property specified was not found. (k:\ncrunch\6040\43\Lider2.Configuration.Tests\bin\Debug\Lider2.Configuration.Tests.dll.config.NUnitTestFramework line 7)
----> System.Reflection.CustomAttributeFormatException : 'DefaultValue' property specified was not found.
----> System.Reflection.CustomAttributeFormatException : 'DefaultValue' property specified was not found.
at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at Lider2.Configuration.LiderConfiguration.get_LiderServers() in k:\ncrunch\6040\33\Lider2.Configuration\LiderConfiguration.cs:line 33
at Lider2.Configuration.Tests.LiderConfigurationTests.Setup() in k:\ncrunch\6040\43\Lider2.Configuration.Tests\LiderConfigurationTests.cs:line 18
--CustomAttributeFormatException
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.DeserializeElement(XmlReader reader, Boolean serializeCollectionKey)
at System.Configuration.ConfigurationElementCollection.OnDeserializeUnrecognizedElement(String elementName, XmlReader reader)
at System.Configuration.ConfigurationElement.DeserializeElement(XmlReader reader, Boolean serializeCollectionKey)
at System.Configuration.ConfigurationElement.DeserializeElement(XmlReader reader, Boolean serializeCollectionKey)
at System.Configuration.ConfigurationSection.DeserializeSection(XmlReader reader)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)
--CustomAttributeFormatException
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
Remco
#6 Posted : Thursday, October 13, 2011 8:09:52 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Ahh.. are you using named attribute parameters anywhere within your test?

There is a known problem in this area that I'm working on at the moment :)
4rchie
#7 Posted : Thursday, October 13, 2011 8:15:52 AM(UTC)
Rank: Member

Groups: Registered
Joined: 10/12/2011(UTC)
Posts: 27
Location: Poland

Thanks: 2 times
Was thanked: 6 time(s) in 6 post(s)
I do....... :(

so problem solved - in a way :)

I'll wait for the new version then.

Thanks for your help.

Regards,
4rchie
1 user thanked 4rchie for this useful post.
Remco on 10/13/2011(UTC)
larsw
#8 Posted : Tuesday, November 22, 2011 8:11:37 PM(UTC)
Rank: Member

Groups: Registered
Joined: 11/22/2011(UTC)
Posts: 15
Location: Oslo, Norway

Was thanked: 3 time(s) in 3 post(s)
Hi,

I'm experiencing the same problem - any progress on Named Parameters used in attributes?

--larsw
--larsw
Remco
#9 Posted : Tuesday, November 22, 2011 8:34:47 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Sorry, a fix is still in progress!
larsw
#10 Posted : Wednesday, November 23, 2011 8:30:23 AM(UTC)
Rank: Member

Groups: Registered
Joined: 11/22/2011(UTC)
Posts: 15
Location: Oslo, Norway

Was thanked: 3 time(s) in 3 post(s)
Hi again,

Ok, thanks for the feedback.

For other people struggling with ConfigurationElement-derived classes; It's possible to override the InitializeDefault() method and set the default values there instead of using the named property DefaultValue
on the ConfigurationProperty attribute.

--larsw
--larsw
1 user thanked larsw for this useful post.
Remco on 11/23/2011(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.070 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download