Click here to Skip to main content
11,701,590 members (72,680 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# .NET UnitTesting , +
In order to remove external dependency for testing purpose i was trying to implement the mole framework

everything was working fine until i have moled the class with static readonly property.

Creating mole of that class is not the root cause of issue but that readonly property is creating the issue

in my actual method that readonly property is used and value of that property is coming null after creating mole instance
since there is not setter, getter for this property so mole class is not giving override for this property

However without mole testcase is not giving error and fetching the data from external sources

Please suggest how to proceed in this case

Thanks in advance
Posted 1-Jan-13 20:21pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You could try using the MolesEraseStaticConstructor.
More about it here -[^].
Vijay_Gurunanee at 30-Mar-13 8:35am
Sorry Friend for delay in reply!!!
but it is not helping me!!!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Sorry for late reply...

but not working for me....
I just re factored the code and changed my code such that it can be moled.

But still i didn't find proper solution for this problem...

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

I have gone for many articles and discussions but did not found any perfect solutions.
So for now considering that it is not possible to override the private read only static properties of a sealed class. (Yes in my case, class sealed...)

So i have decided to change the design of class and then pain was gone.

Thanks for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 324
1 Maciej Los 275
2 Sergey Alexandrovich Kryukov 250
3 Mika Wendelius 189
4 CHill60 110
0 OriginalGriff 8,274
1 Sergey Alexandrovich Kryukov 7,317
2 CPallini 4,912
3 Maciej Los 4,146
4 Mika Wendelius 3,556

Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 19 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100