chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hello,

In .NET, I created a custom configuration section that I want to mock. In my configuration section, I return an instance of the configuration section through the Instance property (a static property), which calls ConfigurationManager.GetSection("mySection") to get a reference to the section. So I have code that checks to see if MySection.Instance != null, then if not null, access the child properties of the section, like:
if (MySection.Instance.SomeProp != null)
return MySection.Instance.SomeProp;
else
return null;

How much with custom configurations can I override with TypeMock, and how? Has anyone tried?
asked by bmains (13.2k points)

1 Answer

0 votes
Hi Brian,

It is possible to mock the GetSection, as well as all other methods of Configuration manager. I've assembled a few posts on the subject:

https://www.typemock.com/community/viewt ... nager#2548
https://www.typemock.com/community/viewt ... anager#831
https://www.typemock.com/community/viewt ... nager#3437
https://www.typemock.com/community/viewt ... nager#3356

If you want, you can post your code and test here so we can help with that.
Let me know if you need any assistance.
answered by gilz (14.5k points)
...