urasandesu / Prig

Prig is a lightweight framework for test indirections in .NET Framework.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with mocking System.Configuration

Ilane91 opened this issue · comments

Hello Akira,
I'm using Prig to mock Microsoft's System.Configuration library.

An exception is thrown when I attempt to use Configuration.GetSection on a custom section I created.

In addition, attempting to use the GetSection method on a different custom section, is working.

The Mocked methods are defined at the begining of the TestFixtureSetup method.

Snippet of the configuration file loading:
image

Snippet of the configuration file:
image
image

Snippet of the mocked GetSection method
image

image
The exception is thrown at the highlighted area.

If you need any extra info, I'll be more than happy to provide.

Thanks.

Thank you for the reporting!

I had a quick investigation for that, but I haven't found the cause yet. However, this is probably a problem of Prig, because Prig uses Configuration internally. I guess that the internal processing races your TestFixtureSetup.

I will let you know when information is updated.

I understand, thank you for your quick response.

I'm looking forward to hearing from you, regarding any updates.

Please let me confirm some points:

What is the method that you want to mock?
In your test code, ConfigurationManager.GetSection(string) is mocked by PConfigurationManager.GetSectionString().Body = ..., but it seems that it isn't used in your code anywhere. Perhaps, you want to mock Configuration.GetSection(string), don't you? If it is true, you have to use PConfiguration.GetSectionString().Body = ... instead of current TestFixtureSetup.

What is the stack trace of the exception about?
Could you give me more information about the following exception?

The exception is thrown at the highlighted area.

If method replacement succeeded(but exception is thrown by the internal problem of Prig after that), you should see the line that starting with TryPrig.... For example,

   at ClassLibrary1Test.Class1Test.<FooTest1>b__0(Configuration this, String sectionName) in c:\Users\urasa\Documents\Visual Studio 2013\Projects\ClassLibrary1\ClassLibrary1Test\Class1.cs:line 32
>> at System.Configuration.Configuration.TryPrigGetSection(ConfigurationSection& , Configuration , String )
   at System.Configuration.Configuration.GetSection(String sectionName)
   at ClassLibrary1.Class1.GetSection(String sectionName) in c:\Users\urasa\Documents\Visual Studio 2013\Projects\ClassLibrary1\ClassLibrary1\Class1.cs:line 28
   at ClassLibrary1.Class1.Foo() in c:\Users\urasa\Documents\Visual Studio 2013\Projects\ClassLibrary1\ClassLibrary1\Class1.cs:line 39
   at ClassLibrary1Test.Class1Test.FooTest1() in c:\Users\urasa\Documents\Visual Studio 2013\Projects\ClassLibrary1\ClassLibrary1Test\Class1.cs:line 35

If method replacement failed, you shouldn't see such line.

I closed this issue because there are no response for more than 1 year.