Wiki Link: [discussion:5357]
How to unit test with generated profile 

Aug 15 2012 at 7:29 PM
I have tried unit testing code that uses the generated profile. For this, I use a mock profile provider I created and I register this through App.config. My generated profile does have groups because I grouped my profile properties in App.config.

When I try to access any property under a group in the unit test, I get a "Pre-Start Initialization" error. This occurs when the generated profile calls "GetProfileGroup". It is due to some internal code in "BuildManager" that does a check for "Pre-Start". If I add the following in my unit test, this error goes away:

typeof(BuildManager).GetProperty("PreStartInitStage", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, 2, null);
typeof(BuildManager).GetField("topLevelFilesCompiledStarted", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(typeof(BuildManager).GetField("theBuildManager", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null), true);

However, if I try to access any data under a group, I get an error saying the group has not been defined. I am wondering if anybody has been able to unit test a generated profile where the profile has groups in it?

Page view tracker